From 2dfe7158f067f4a8af16dc87379f85554627afe3 Mon Sep 17 00:00:00 2001 From: Jake Heath Date: Thu, 25 Apr 2024 10:11:59 -0700 Subject: [PATCH] filter out nonexistent variables --- apply/apply.go | 13 +++++++++++++ testdata/tfe_config/fogg.yml | 1 + 2 files changed, 14 insertions(+) diff --git a/apply/apply.go b/apply/apply.go index 6acd27ca0..59559dd14 100644 --- a/apply/apply.go +++ b/apply/apply.go @@ -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" @@ -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 } diff --git a/testdata/tfe_config/fogg.yml b/testdata/tfe_config/fogg.yml index 91ed90d1f..652bb6d7e 100644 --- a/testdata/tfe_config/fogg.yml +++ b/testdata/tfe_config/fogg.yml @@ -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: ""