Skip to content

Commit

Permalink
push the bootstrap module thing to plan
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanking authored and czimergebot committed Jul 11, 2018
1 parent f1d1fe2 commit 5aa9aea
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
13 changes: 7 additions & 6 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[email protected]: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
Expand Down
34 changes: 34 additions & 0 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Component struct {
SharedInfraVersion string
TerraformVersion string
SiccMode bool

BootstrapModule string
}

type Env struct {
Expand Down Expand Up @@ -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 = "[email protected]:chanzuckerberg/shared-infra//terraform/modules/aws-env"

envPlan.Components["cloud-env"] = componentPlan
}

envPlans[envName] = envPlan
}
return envPlans
Expand Down
2 changes: 1 addition & 1 deletion plan/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5aa9aea

Please sign in to comment.