From f33a7961c9af5986e3a7bc8cd56d1925f54dfe33 Mon Sep 17 00:00:00 2001 From: Eduardo Lopez Date: Wed, 15 Aug 2018 11:13:04 -0700 Subject: [PATCH] Version the chanzuckerberg/terraform docker image (#117) --- Makefile | 2 +- plan/plan.go | 56 ++++++++++++++++++++----------- templates/account/Makefile.tmpl | 5 +-- templates/component/Makefile.tmpl | 5 +-- templates/global/Makefile.tmpl | 5 +-- templates/module/Makefile.tmpl | 5 +-- 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index ae3fdef18..5a045cf2e 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ coverage: ## run the go coverage tool, reading file coverage.out test: ## run the tests go test -cover ./... -install: # install the fogg binary in $GOPATH/bin +install: ## install the fogg binary in $GOPATH/bin go install ${LDFLAGS} . help: ## display help for this makefile diff --git a/plan/plan.go b/plan/plan.go index fa674882e..d07667be8 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -8,6 +8,11 @@ import ( "github.com/pkg/errors" ) +const ( + // The version of the chanzuckerberg/terraform docker image to use + dockerImageVersion = "0.1.1" +) + type AWSConfiguration struct { AccountID *int64 AccountName string @@ -21,38 +26,43 @@ type AWSConfiguration struct { } type account struct { + AllAccounts map[string]int64 AWSConfiguration - AllAccounts map[string]int64 - ExtraVars map[string]string - Owner string - Project string - TerraformVersion string + DockerImageVersion string + ExtraVars map[string]string + Owner string + Project string + TerraformVersion string } type Module struct { - TerraformVersion string + DockerImageVersion string + TerraformVersion string } type Component struct { AWSConfiguration - Component string - Env string - ExtraVars map[string]string - ModuleSource *string - OtherComponents []string - Owner string - Project string - TerraformVersion string + + Component string + DockerImageVersion string + Env string + ExtraVars map[string]string + ModuleSource *string + OtherComponents []string + Owner string + Project string + TerraformVersion string } type Env struct { AWSConfiguration - Components map[string]Component - Env string - ExtraVars map[string]string - Owner string - Project string - TerraformVersion string + Components map[string]Component + DockerImageVersion string + Env string + ExtraVars map[string]string + Owner string + Project string + TerraformVersion string } type Plan struct { @@ -70,6 +80,7 @@ func Eval(config *config.Config, verbose bool) (*Plan, error) { return nil, errors.Wrap(e, "unable to parse fogg version") } p.Version = v + accounts, err := buildAccounts(config) if err != nil { return nil, err @@ -196,6 +207,7 @@ func buildAccounts(c *config.Config) (map[string]account, error) { accountPlans := make(map[string]account, len(c.Accounts)) for name, config := range c.Accounts { accountPlan := account{} + accountPlan.DockerImageVersion = dockerImageVersion accountPlan.AccountName = name accountPlan.AccountID = resolveOptionalInt(c.Defaults.AccountID, config.AccountID) @@ -225,6 +237,7 @@ func buildModules(c *config.Config) (map[string]Module, error) { for name, conf := range c.Modules { modulePlan := Module{} + modulePlan.DockerImageVersion = dockerImageVersion modulePlan.TerraformVersion = resolveRequired(c.Defaults.TerraformVersion, conf.TerraformVersion) modulePlans[name] = modulePlan } @@ -241,6 +254,7 @@ func buildGlobal(conf *config.Config) (Component, error) { // Global just uses defaults because that's the way sicc worked. We should make it directly configurable. componentPlan := Component{} + componentPlan.DockerImageVersion = dockerImageVersion componentPlan.AccountID = conf.Defaults.AccountID componentPlan.AWSRegionBackend = conf.Defaults.AWSRegionBackend @@ -274,6 +288,7 @@ func buildEnvs(conf *config.Config) (map[string]Env, error) { envPlan.AccountID = resolveOptionalInt(conf.Defaults.AccountID, envConf.AccountID) envPlan.Env = envName + envPlan.DockerImageVersion = dockerImageVersion envPlan.AWSRegionBackend = resolveRequired(defaults.AWSRegionBackend, envConf.AWSRegionBackend) envPlan.AWSRegionProvider = resolveRequired(defaults.AWSRegionProvider, envConf.AWSRegionProvider) @@ -309,6 +324,7 @@ func buildEnvs(conf *config.Config) (map[string]Env, error) { componentPlan.Env = envName componentPlan.Component = componentName + componentPlan.DockerImageVersion = dockerImageVersion componentPlan.OtherComponents = otherComponentNames(conf.Envs[envName].Components, componentName) componentPlan.ModuleSource = componentConf.ModuleSource componentPlan.ExtraVars = resolveExtraVars(envPlan.ExtraVars, componentConf.ExtraVars) diff --git a/templates/account/Makefile.tmpl b/templates/account/Makefile.tmpl index 15e0b22a5..ba926e4fe 100644 --- a/templates/account/Makefile.tmpl +++ b/templates/account/Makefile.tmpl @@ -7,6 +7,7 @@ REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) # We need to do this because `terraform fmt` recurses into .terraform/modules # and wont' accept more than one file at a time. TF=$(wildcard *.tf) +IMAGE_VERSION={{ .DockerImageVersion }}_TF{{ .TerraformVersion }} docker_base = \ docker run -it --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ @@ -14,8 +15,8 @@ docker_base = \ -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) -docker_terraform = $(docker_base) chanzuckerberg/terraform:{{ .TerraformVersion }} -docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:{{ .TerraformVersion }} +docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) +docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) all: diff --git a/templates/component/Makefile.tmpl b/templates/component/Makefile.tmpl index 15e0b22a5..ba926e4fe 100644 --- a/templates/component/Makefile.tmpl +++ b/templates/component/Makefile.tmpl @@ -7,6 +7,7 @@ REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) # We need to do this because `terraform fmt` recurses into .terraform/modules # and wont' accept more than one file at a time. TF=$(wildcard *.tf) +IMAGE_VERSION={{ .DockerImageVersion }}_TF{{ .TerraformVersion }} docker_base = \ docker run -it --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ @@ -14,8 +15,8 @@ docker_base = \ -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) -docker_terraform = $(docker_base) chanzuckerberg/terraform:{{ .TerraformVersion }} -docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:{{ .TerraformVersion }} +docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) +docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) all: diff --git a/templates/global/Makefile.tmpl b/templates/global/Makefile.tmpl index 15e0b22a5..ba926e4fe 100644 --- a/templates/global/Makefile.tmpl +++ b/templates/global/Makefile.tmpl @@ -7,6 +7,7 @@ REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) # We need to do this because `terraform fmt` recurses into .terraform/modules # and wont' accept more than one file at a time. TF=$(wildcard *.tf) +IMAGE_VERSION={{ .DockerImageVersion }}_TF{{ .TerraformVersion }} docker_base = \ docker run -it --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ @@ -14,8 +15,8 @@ docker_base = \ -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) -docker_terraform = $(docker_base) chanzuckerberg/terraform:{{ .TerraformVersion }} -docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:{{ .TerraformVersion }} +docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) +docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) all: diff --git a/templates/module/Makefile.tmpl b/templates/module/Makefile.tmpl index 2f8af05bb..56edf7d07 100644 --- a/templates/module/Makefile.tmpl +++ b/templates/module/Makefile.tmpl @@ -7,6 +7,7 @@ REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) # We need to do this because `terraform fmt` recurses into .terraform/modules # and wont' accept more than one file at a time. TF=$(wildcard *.tf) +IMAGE_VERSION={{ .DockerImageVersion }}_TF{{ .TerraformVersion }} docker_base = \ docker run -it --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ @@ -14,8 +15,8 @@ docker_base = \ -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) -docker_terraform = $(docker_base) chanzuckerberg/terraform:{{ .TerraformVersion }} -docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:{{ .TerraformVersion }} +docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) +docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) all: fmt lint doc