diff --git a/apply/apply.go b/apply/apply.go index 436b3aed4..1cdd75570 100644 --- a/apply/apply.go +++ b/apply/apply.go @@ -122,13 +122,14 @@ func applyEnvs(fs afero.Fs, p *plan.Plan, envBox *packr.Box, componentBox *packr if e != nil { return errors.Wrap(e, "unable to apply templates for component") } - } - path = filepath.Join(rootPath, "envs", env, "cloud-env") - if envPlan.Type == "aws" { - e := applyModule(fs, path, "git@github.com:chanzuckerberg/shared-infra//terraform/modules/aws-env", templates.Templates.ModuleInvocation) - if e != nil { - return errors.Wrap(e, "unable to apply module") + + if componentPlan.BootstrapModule != "" { + e := applyModule(fs, path, componentPlan.BootstrapModule, templates.Templates.ModuleInvocation) + if e != nil { + return errors.Wrap(e, "unable to apply module") + } } + } } return nil diff --git a/plan/plan.go b/plan/plan.go index 138937544..13fa1e31d 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -48,6 +48,8 @@ type Component struct { SharedInfraVersion string TerraformVersion string SiccMode bool + + BootstrapModule string } type Env struct { @@ -314,11 +316,43 @@ func buildEnvs(conf *config.Config, siccMode bool) map[string]Env { componentPlan.Env = envName componentPlan.Component = componentName componentPlan.OtherComponents = otherComponentNames(conf.Envs[envName].Components, componentName) + // This is a bit awkward but should go away when we make the modules thing first-class. + if envPlan.Type == "aws" { + componentPlan.OtherComponents = append(componentPlan.OtherComponents, "cloud-env") + } componentPlan.SiccMode = siccMode envPlan.Components[componentName] = componentPlan } + if envPlan.Type == "aws" { + componentPlan := Component{} + + componentPlan.AWSRegionBackend = envPlan.AWSRegionBackend + componentPlan.AWSRegionProvider = envPlan.AWSRegionProvider + componentPlan.AWSRegions = envPlan.AWSRegions + + componentPlan.AWSProfileBackend = envPlan.AWSProfileBackend + componentPlan.AWSProfileProvider = envPlan.AWSProfileProvider + componentPlan.AWSProviderVersion = envPlan.AWSProviderVersion + componentPlan.AccountID = envPlan.AccountID + + componentPlan.TerraformVersion = envPlan.TerraformVersion + componentPlan.InfraBucket = envPlan.InfraBucket + componentPlan.Owner = envPlan.Owner + componentPlan.Project = envPlan.Project + componentPlan.SharedInfraVersion = conf.Defaults.SharedInfraVersion + + componentPlan.Env = envName + componentPlan.Component = "cloud-env" + componentPlan.OtherComponents = []string{} + componentPlan.SiccMode = siccMode + + componentPlan.BootstrapModule = "git@github.com:chanzuckerberg/shared-infra//terraform/modules/aws-env" + + envPlan.Components["cloud-env"] = componentPlan + } + envPlans[envName] = envPlan } return envPlans diff --git a/plan/plan_test.go b/plan/plan_test.go index 8c9e2bdd1..2aa8f8c67 100644 --- a/plan/plan_test.go +++ b/plan/plan_test.go @@ -103,7 +103,7 @@ func TestPlanBasic(t *testing.T) { assert.Equal(t, plan.Envs["staging"].TerraformVersion, "0.100.0") assert.NotNil(t, plan.Envs["staging"].Components) - assert.Len(t, plan.Envs["staging"].Components, 2) + assert.Len(t, plan.Envs["staging"].Components, 3) // includes implicit cloud-env assert.NotNil(t, plan.Envs["staging"].Components["comp1"]) assert.Equal(t, plan.Envs["staging"].Components["comp1"].TerraformVersion, "0.100.0")