Skip to content

Commit

Permalink
Remove parseLocals cache (#73)
Browse files Browse the repository at this point in the history
* Remove parseLocals cache

* Remove unused files

Co-authored-by: dmattia <david@transcend.io>
  • Loading branch information
dmattia and dmattia authored Oct 2, 2020
1 parent ab8a0f9 commit dad7b6a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=0.9.6
VERSION=0.9.7
PATH_BUILD=build/
FILE_COMMAND=terragrunt-atlantis-config
FILE_ARCH=darwin_amd64
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
11 changes: 11 additions & 0 deletions cmd/golden/mergeParentDependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 0 additions & 17 deletions cmd/parse_locals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,28 +45,21 @@ 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
}

// Parse the HCL string into an AST body
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
}

Expand All @@ -98,7 +82,6 @@ func parseLocals(path string, terragruntOptions *options.TerragruntOptions, incl
)
}

parseLocalsCache[path] = ParseLocalResult{resolvedLocals: parentLocals}
return parentLocals, nil
}

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some_tag_key: some_tag_value
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"noice": "no ice"
}
3 changes: 3 additions & 0 deletions test_examples/parent_with_extra_deps/parent/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit dad7b6a

Please sign in to comment.