From 3e0bac4b846446877e06058d526d0d7412c9b2ed Mon Sep 17 00:00:00 2001 From: Jake Heath Date: Tue, 7 Mar 2023 14:27:59 -0800 Subject: [PATCH 1/2] fix: omit empty leaving behind variables --- config/v2/config.go | 2 +- plan/plan.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/config/v2/config.go b/config/v2/config.go index 073304b37..87b4fdd29 100644 --- a/config/v2/config.go +++ b/config/v2/config.go @@ -124,7 +124,7 @@ type Component struct { Kind *ComponentKind `yaml:"kind,omitempty"` ModuleSource *string `yaml:"module_source,omitempty"` ModuleName *string `yaml:"module_name,omitempty"` - Variables []string `yaml:"variables,omitempty"` + Variables *[]string `yaml:"variables,omitempty"` } type Providers struct { diff --git a/plan/plan.go b/plan/plan.go index 3855fc3c6..77973f433 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -436,7 +436,9 @@ func (p *Plan) buildTFE(c *v2.Config) (*TFEConfig, error) { tfeConfig.ComponentCommon = resolveComponentCommon(c.Defaults.Common, c.Global.Common, c.TFE.Common) tfeConfig.ModuleSource = c.TFE.ModuleSource tfeConfig.ModuleName = c.TFE.ModuleName - tfeConfig.Variables = c.TFE.Variables + if c.TFE.Variables != nil { + tfeConfig.Variables = *c.TFE.Variables + } if tfeConfig.ComponentCommon.Backend.Kind == BackendKindS3 { tfeConfig.ComponentCommon.Backend.S3.KeyPath = fmt.Sprintf("terraform/%s/%s.tfstate", "tfe", "tfe") @@ -614,7 +616,9 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) { componentPlan.Name = componentName componentPlan.ModuleSource = componentConf.ModuleSource componentPlan.ModuleName = componentConf.ModuleName - componentPlan.Variables = componentConf.Variables + if componentConf.Variables != nil { + componentPlan.Variables = *componentConf.Variables + } componentPlan.PathToRepoRoot = "../../../../" componentPlan.Global = &p.Global From 0de29c893d1bb577eb25dec29046c8cdbafa9fa9 Mon Sep 17 00:00:00 2001 From: Jake Heath Date: Tue, 7 Mar 2023 14:35:54 -0800 Subject: [PATCH 2/2] omitempty --- config/v2/config.go | 2 +- plan/plan.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/config/v2/config.go b/config/v2/config.go index 87b4fdd29..c6986b7cb 100644 --- a/config/v2/config.go +++ b/config/v2/config.go @@ -124,7 +124,7 @@ type Component struct { Kind *ComponentKind `yaml:"kind,omitempty"` ModuleSource *string `yaml:"module_source,omitempty"` ModuleName *string `yaml:"module_name,omitempty"` - Variables *[]string `yaml:"variables,omitempty"` + Variables []string `yaml:"variables"` } type Providers struct { diff --git a/plan/plan.go b/plan/plan.go index 77973f433..3855fc3c6 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -436,9 +436,7 @@ func (p *Plan) buildTFE(c *v2.Config) (*TFEConfig, error) { tfeConfig.ComponentCommon = resolveComponentCommon(c.Defaults.Common, c.Global.Common, c.TFE.Common) tfeConfig.ModuleSource = c.TFE.ModuleSource tfeConfig.ModuleName = c.TFE.ModuleName - if c.TFE.Variables != nil { - tfeConfig.Variables = *c.TFE.Variables - } + tfeConfig.Variables = c.TFE.Variables if tfeConfig.ComponentCommon.Backend.Kind == BackendKindS3 { tfeConfig.ComponentCommon.Backend.S3.KeyPath = fmt.Sprintf("terraform/%s/%s.tfstate", "tfe", "tfe") @@ -616,9 +614,7 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) { componentPlan.Name = componentName componentPlan.ModuleSource = componentConf.ModuleSource componentPlan.ModuleName = componentConf.ModuleName - if componentConf.Variables != nil { - componentPlan.Variables = *componentConf.Variables - } + componentPlan.Variables = componentConf.Variables componentPlan.PathToRepoRoot = "../../../../" componentPlan.Global = &p.Global