From a34048ad079fb3ed46f1464fb2a73b3e028d771d Mon Sep 17 00:00:00 2001 From: Andriy Knysh Date: Thu, 15 Aug 2024 15:59:50 -0400 Subject: [PATCH] Improve logging for the template function `atmos.Component` (#672) * updates * updates * updates * updates --- examples/quick-start-advanced/Dockerfile | 4 +- .../test/template-functions-test/outputs.tf | 18 ++++++++ go.mod | 4 +- go.sum | 4 +- internal/exec/template_funcs_component.go | 45 ++++++++++++++++--- website/docs/integrations/atlantis.mdx | 2 +- .../github-actions/setup-atmos.mdx | 2 +- 7 files changed, 66 insertions(+), 13 deletions(-) diff --git a/examples/quick-start-advanced/Dockerfile b/examples/quick-start-advanced/Dockerfile index fc71854b4..f43c8e7f8 100644 --- a/examples/quick-start-advanced/Dockerfile +++ b/examples/quick-start-advanced/Dockerfile @@ -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 diff --git a/examples/tests/components/terraform/test/template-functions-test/outputs.tf b/examples/tests/components/terraform/test/template-functions-test/outputs.tf index 72cf38561..2af5e9cef 100644 --- a/examples/tests/components/terraform/test/template-functions-test/outputs.tf +++ b/examples/tests/components/terraform/test/template-functions-test/outputs.tf @@ -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" +} diff --git a/go.mod b/go.mod index 3153fffb3..49aeebb41 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cloudposse/atmos -go 1.21 +go 1.23 require ( dario.cat/mergo v1.0.0 @@ -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 diff --git a/go.sum b/go.sum index ae48a6fb4..502263143 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/exec/template_funcs_component.go b/internal/exec/template_funcs_component.go index 3938fc5bb..0648e1f4d 100644 --- a/internal/exec/template_funcs_component.go +++ b/internal/exec/template_funcs_component.go @@ -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 } @@ -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 }) @@ -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) } } diff --git a/website/docs/integrations/atlantis.mdx b/website/docs/integrations/atlantis.mdx index 91d4fac44..229413a11 100644 --- a/website/docs/integrations/atlantis.mdx +++ b/website/docs/integrations/atlantis.mdx @@ -673,7 +673,7 @@ on: branches: [ main ] env: - ATMOS_VERSION: 1.86.0 + ATMOS_VERSION: 1.86.1 ATMOS_CLI_CONFIG_PATH: ./ jobs: diff --git a/website/docs/integrations/github-actions/setup-atmos.mdx b/website/docs/integrations/github-actions/setup-atmos.mdx index 861beba01..75054e106 100644 --- a/website/docs/integrations/github-actions/setup-atmos.mdx +++ b/website/docs/integrations/github-actions/setup-atmos.mdx @@ -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 ```