Skip to content

Commit

Permalink
Version the chanzuckerberg/terraform docker image (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Aug 15, 2018
1 parent 28dbeb7 commit f33a796
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 36 additions & 20 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions templates/account/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ 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 \
-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-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:

Expand Down
5 changes: 3 additions & 2 deletions templates/component/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ 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 \
-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-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:

Expand Down
5 changes: 3 additions & 2 deletions templates/global/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ 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 \
-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-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:

Expand Down
5 changes: 3 additions & 2 deletions templates/module/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ 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 \
-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-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

Expand Down

0 comments on commit f33a796

Please sign in to comment.