From dad7b6aa4b8aac67f10bf2d3eb71f1a770e778d4 Mon Sep 17 00:00:00 2001 From: David Mattia <8922077+dmattia@users.noreply.github.com> Date: Fri, 2 Oct 2020 10:28:08 -0500 Subject: [PATCH] Remove parseLocals cache (#73) * Remove parseLocals cache * Remove unused files Co-authored-by: dmattia --- Makefile | 2 +- README.md | 2 +- cmd/golden/mergeParentDependencies.yaml | 11 +++++++++++ cmd/parse_locals.go | 17 ----------------- main.go | 2 +- .../child/local_tags.yaml | 1 + .../child/terragrunt.hcl | 17 +++++++++++++++++ .../file_in_parent_of_child.json | 3 +++ .../parent/terragrunt.hcl | 3 +++ 9 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/local_tags.yaml create mode 100644 test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/terragrunt.hcl create mode 100644 test_examples/parent_with_extra_deps/deep_with_local_tags_file/file_in_parent_of_child.json diff --git a/Makefile b/Makefile index b7623ad8..85a441c8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=0.9.6 +VERSION=0.9.7 PATH_BUILD=build/ FILE_COMMAND=terragrunt-atlantis-config FILE_ARCH=darwin_amd64 diff --git a/README.md b/README.md index 6546e903..1141e361 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ jobs: id: atlantis_validator uses: transcend-io/terragrunt-atlantis-config-github-action@v0.0.3 with: - version: v0.9.6 + version: v0.9.7 extra_args: '--autoplan --parallel=false ``` diff --git a/cmd/golden/mergeParentDependencies.yaml b/cmd/golden/mergeParentDependencies.yaml index db43298a..e7e7bada 100644 --- a/cmd/golden/mergeParentDependencies.yaml +++ b/cmd/golden/mergeParentDependencies.yaml @@ -12,4 +12,15 @@ projects: - ../../parent/folder_under_parent/common_tags.hcl - some_child_dep dir: deep/child +- autoplan: + enabled: false + when_modified: + - '*.hcl' + - '*.tf*' + - some_parent_dep + - local_tags.yaml + - ../file_in_parent_of_child.json + - ../../parent/folder_under_parent/common_tags.hcl + - some_child_dep + dir: deep_with_local_tags_file/child version: 3 diff --git a/cmd/parse_locals.go b/cmd/parse_locals.go index a0816f9a..d5c8492d 100644 --- a/cmd/parse_locals.go +++ b/cmd/parse_locals.go @@ -15,15 +15,6 @@ import ( "path/filepath" ) -var ( - parseLocalsCache map[string]ParseLocalResult = make(map[string]ParseLocalResult) -) - -type ParseLocalResult struct { - resolvedLocals ResolvedLocals - err error -} - // ResolvedLocals are the parsed result of local values this module cares about type ResolvedLocals struct { // The Atlantis workflow to use for some project @@ -54,13 +45,8 @@ func parseHcl(parser *hclparse.Parser, hcl string, filename string) (file *hcl.F // Parses a given file, returning a map of all it's `local` values func parseLocals(path string, terragruntOptions *options.TerragruntOptions, includeFromChild *config.IncludeConfig) (ResolvedLocals, error) { - if cachedResult, ok := parseLocalsCache[path]; ok { - return cachedResult.resolvedLocals, cachedResult.err - } - configString, err := util.ReadFileAsString(path) if err != nil { - parseLocalsCache[path] = ParseLocalResult{err: err} return ResolvedLocals{}, err } @@ -68,14 +54,12 @@ func parseLocals(path string, terragruntOptions *options.TerragruntOptions, incl parser := hclparse.NewParser() file, err := parseHcl(parser, configString, path) if err != nil { - parseLocalsCache[path] = ParseLocalResult{err: err} return ResolvedLocals{}, err } // Decode just the Base blocks. See the function docs for DecodeBaseBlocks for more info on what base blocks are. localsAsCty, _, includeConfig, err := config.DecodeBaseBlocks(terragruntOptions, parser, file, path, includeFromChild) if err != nil { - parseLocalsCache[path] = ParseLocalResult{err: err} return ResolvedLocals{}, err } @@ -98,7 +82,6 @@ func parseLocals(path string, terragruntOptions *options.TerragruntOptions, incl ) } - parseLocalsCache[path] = ParseLocalResult{resolvedLocals: parentLocals} return parentLocals, nil } diff --git a/main.go b/main.go index f19a96c7..7377c944 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import "github.com/transcend-io/terragrunt-atlantis-config/cmd" // This variable is set at build time using -ldflags parameters. // But we still set a default here for those using plain `go get` downloads // For more info, see: http://stackoverflow.com/a/11355611/483528 -var VERSION string = "0.9.6" +var VERSION string = "0.9.7" func main() { cmd.Execute(VERSION) diff --git a/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/local_tags.yaml b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/local_tags.yaml new file mode 100644 index 00000000..0e47e12a --- /dev/null +++ b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/local_tags.yaml @@ -0,0 +1 @@ +some_tag_key: some_tag_value \ No newline at end of file diff --git a/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/terragrunt.hcl b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/terragrunt.hcl new file mode 100644 index 00000000..d447e1ae --- /dev/null +++ b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/child/terragrunt.hcl @@ -0,0 +1,17 @@ +include { + path = "${find_in_parent_folders("parent")}/terragrunt.hcl" +} + +terraform { + source = "git::git@github.com:transcend-io/terraform-aws-fargate-container?ref=v0.0.4" +} + +locals { + extra_atlantis_dependencies = [ + "some_child_dep", + ] +} + +inputs = { + foo = "bar" +} \ No newline at end of file diff --git a/test_examples/parent_with_extra_deps/deep_with_local_tags_file/file_in_parent_of_child.json b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/file_in_parent_of_child.json new file mode 100644 index 00000000..18d81366 --- /dev/null +++ b/test_examples/parent_with_extra_deps/deep_with_local_tags_file/file_in_parent_of_child.json @@ -0,0 +1,3 @@ +{ + "noice": "no ice" +} \ No newline at end of file diff --git a/test_examples/parent_with_extra_deps/parent/terragrunt.hcl b/test_examples/parent_with_extra_deps/parent/terragrunt.hcl index 554bf24d..fe4e10b5 100644 --- a/test_examples/parent_with_extra_deps/parent/terragrunt.hcl +++ b/test_examples/parent_with_extra_deps/parent/terragrunt.hcl @@ -3,6 +3,9 @@ locals { # A relative file to the child should work "some_parent_dep", + # Relative files to the child should be conditionally includable + fileexists("${path_relative_to_include()}/local_tags.yaml") ? "local_tags.yaml" : "", + # Functions should run from the child dir, not the parent dir find_in_parent_folders("file_in_parent_of_child.json"), "${get_parent_terragrunt_dir()}/folder_under_parent/common_tags.hcl",