Skip to content

Commit

Permalink
filter out nonexistent variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeyheath committed Apr 25, 2024
1 parent 079487b commit 2dfe715
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/chanzuckerberg/fogg/plan"
"github.com/chanzuckerberg/fogg/templates"
"github.com/chanzuckerberg/fogg/util"
"github.com/chanzuckerberg/go-misc/sets"
getter "github.com/hashicorp/go-getter"
"github.com/hashicorp/hcl2/hclwrite"
"github.com/hashicorp/terraform-config-inspect/tfconfig"
Expand Down Expand Up @@ -585,6 +586,18 @@ func gatherTFModuleVariablesAndValues(component plan.Component, moduleConfig *tf
}
}

// filter out non-existent variables on the module
for k := range variables {
ss := sets.NewStringSet()
for _, v := range moduleConfig.Variables {
ss.Add(v.Name)
}

if !ss.ContainsElement(k) {
delete(variables, k)
}
}

return variables, nil
}

Expand Down
1 change: 1 addition & 0 deletions testdata/tfe_config/fogg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tfe:
- env=var.tags.env
- owner=var.tags.owner
- project
- blah # should be filtered out
extra_vars:
TFE_AWS_ACCESS_KEY_ID: ""
TFE_AWS_SECRET_ACCESS_KEY: ""
Expand Down

0 comments on commit 2dfe715

Please sign in to comment.