Skip to content

Commit

Permalink
Improve logging for the template function atmos.Component (#672)
Browse files Browse the repository at this point in the history
* updates

* updates

* updates

* updates
  • Loading branch information
aknysh authored Aug 15, 2024
1 parent 9fef230 commit a34048a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/quick-start-advanced/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Geodesic: https://github.com/cloudposse/geodesic/
ARG GEODESIC_VERSION=3.0.0
ARG GEODESIC_VERSION=3.1.0
ARG GEODESIC_OS=debian

# Atmos
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.86.0
ARG ATMOS_VERSION=1.86.1

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.9.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ output "test_label_id" {
value = module.test_label.id
description = "Test label ID"
}

output "test_list" {
value = [
"list_item_1",
"list_item_2",
"list_item_3"
]
description = "Test list"
}

output "test_map" {
value = {
a = 1,
b = 2,
c = 3
}
description = "Test map"
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cloudposse/atmos

go 1.21
go 1.23

require (
dario.cat/mergo v1.0.0
Expand All @@ -18,7 +18,7 @@ require (
github.com/google/go-github/v59 v59.0.0
github.com/google/uuid v1.6.0
github.com/hairyhenderson/gomplate/v3 v3.11.8
github.com/hashicorp/go-getter v1.7.5
github.com/hashicorp/go-getter v1.7.6
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.21.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20240801114854-6714b46f5fe4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-getter v1.7.5 h1:dT58k9hQ/vbxNMwoI5+xFYAJuv6152UNvdHokfI5wE4=
github.com/hashicorp/go-getter v1.7.5/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-getter v1.7.6 h1:5jHuM+aH373XNtXl9TNTUH5Qd69Trve11tHIrB+6yj4=
github.com/hashicorp/go-getter v1.7.6/go.mod h1:W7TalhMmbPmsSMdNjD0ZskARur/9GJ17cfHTRtXV744=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand Down
45 changes: 40 additions & 5 deletions internal/exec/template_funcs_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ var (
)

func componentFunc(cliConfig schema.CliConfiguration, component string, stack string) (any, error) {
u.LogTrace(cliConfig, fmt.Sprintf("Executing template function atmos.Component(%s, %s)", component, stack))
u.LogTrace(cliConfig, fmt.Sprintf("Executing template function 'atmos.Component(%s, %s)'", component, stack))

stackSlug := fmt.Sprintf("%s-%s", stack, component)

// If the result for the component in the stack already exists in the cache, return it
existingSections, found := componentFuncSyncMap.Load(stackSlug)
if found && existingSections != nil {

if cliConfig.Logs.Level == u.LogLevelTrace {
u.LogTrace(cliConfig, fmt.Sprintf("Found the result of the template function 'atmos.Component(%s, %s)' in the cache", component, stack))

if outputsSection, ok := existingSections.(map[string]any)["outputs"]; ok {
u.LogTrace(cliConfig, "'outputs' section:")
y, err2 := u.ConvertToYAML(outputsSection)
if err2 != nil {
u.LogError(err2)
} else {
u.LogTrace(cliConfig, y)
}
}
}

return existingSections, nil
}

Expand Down Expand Up @@ -82,9 +97,27 @@ func componentFunc(cliConfig schema.CliConfiguration, component string, stack st
return nil, err
}

if cliConfig.Logs.Level == u.LogLevelTrace {
y, err2 := u.ConvertToYAML(outputMeta)
if err2 != nil {
u.LogError(err2)
} else {
u.LogTrace(cliConfig, fmt.Sprintf("\nResult of 'atmos terraform output %s -s %s' before processing it:\n%s\n", component, stack, y))
}
}

outputMetaProcessed := lo.MapEntries(outputMeta, func(k string, v tfexec.OutputMeta) (string, any) {
d, err2 := u.ConvertFromJSON(string(v.Value))
u.LogError(err2)
s := string(v.Value)
u.LogTrace(cliConfig, fmt.Sprintf("Converting the variable '%s' with the value\n%s\nfrom JSON to 'Go' data type\n", k, s))

d, err2 := u.ConvertFromJSON(s)

if err2 != nil {
u.LogError(err2)
} else {
u.LogTrace(cliConfig, fmt.Sprintf("Converted the variable '%s' with the value\n%s\nfrom JSON to 'Go' data type\nResult: %v\n", k, s, d))
}

return k, d
})

Expand All @@ -98,10 +131,12 @@ func componentFunc(cliConfig schema.CliConfiguration, component string, stack st
componentFuncSyncMap.Store(stackSlug, sections)

if cliConfig.Logs.Level == u.LogLevelTrace {
u.LogTrace(cliConfig, fmt.Sprintf("Executed template function atmos.Component(%s, %s)\n'outputs' section:\n", component, stack))
err2 := u.PrintAsYAML(outputMetaProcessed)
u.LogTrace(cliConfig, fmt.Sprintf("Executed template function 'atmos.Component(%s, %s)'\n\n'outputs' section:", component, stack))
y, err2 := u.ConvertToYAML(outputMetaProcessed)
if err2 != nil {
u.LogError(err2)
} else {
u.LogTrace(cliConfig, y)
}
}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/atlantis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ on:
branches: [ main ]
env:
ATMOS_VERSION: 1.86.0
ATMOS_VERSION: 1.86.1
ATMOS_CLI_CONFIG_PATH: ./
jobs:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/integrations/github-actions/setup-atmos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
uses: cloudposse/github-action-setup-atmos
with:
# Make sure to pin to the latest version of atmos
atmos_version: 1.86.0
atmos_version: 1.86.1
```
</File>

0 comments on commit a34048a

Please sign in to comment.