diff --git a/README.md b/README.md index f03276b2..c19a4167 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ **NOTE:** We are actively experimenting with this in the open. Consider this ALPHA software and subject to change. -Terraform-controller - This is a low level tool to run Git controlled Terraform modules in Kubernetes. The controller manages the TF state file using Kubernetes as a remote statefile backend! [Backend upstream PR](https://github.com/hashicorp/terraform/pull/19525) You can have changes auto-applied or wait for an explicit "OK" before running. +Terraform-controller - This is a low level tool to run Git controlled Terraform modules in Kubernetes. The controller manages the TF state file using Kubernetes as a remote statefile backend (requires Terraform 0.13.4)! You can have changes auto-applied or wait for an explicit "OK" before running. There are two parts to the stack, the controller and the executor. diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 3fcff05d..0c81e4db 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -173,12 +173,12 @@ func TestTerraState(t *testing.T) { assert := assert.New(t) ts, err := e.cs.CoreV1().Secrets(e.namespace).List(v13.ListOptions{ - LabelSelector: "terraKey=" + e.generateStateName(), + LabelSelector: "tfstateSecretSuffix=" + e.generateStateName(), }) assert.Nil(err) assert.Equal(len(ts.Items), 1) - assert.NotEmpty(ts.Items[0].Data["terrastate"]) + assert.NotEmpty(ts.Items[0].Data["tfstate"]) assert.Empty(ts.Items[0].Data["lockInfo"]) } diff --git a/package/Dockerfile.executor b/package/Dockerfile.executor index 8421d347..b56120a2 100644 --- a/package/Dockerfile.executor +++ b/package/Dockerfile.executor @@ -3,12 +3,10 @@ FROM alpine # Need to grab terraform binary RUN apk add --no-cache curl git openssh unzip -# This is the real url we will eventually need to pull the zip from -# https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip -RUN curl -sLf https://github.com/dramich/terraform/releases/download/testing/linux_amd64.zip -o terraform_0.11.11_linux_amd64.zip && \ - unzip terraform_0.11.11_linux_amd64.zip -d /usr/bin && \ +RUN curl -sLf https://releases.hashicorp.com/terraform/0.13.4/terraform_0.13.4_linux_amd64.zip -o terraform_0.13.4_linux_amd64.zip && \ + unzip terraform_0.13.4_linux_amd64.zip -d /usr/bin && \ chmod +x /usr/bin/terraform && \ - rm terraform_0.11.11_linux_amd64.zip + rm terraform_0.13.4_linux_amd64.zip COPY terraform-executor /usr/bin/ diff --git a/pkg/cli/cmds/common.go b/pkg/cli/cmds/common.go index d4187184..12cc3026 100644 --- a/pkg/cli/cmds/common.go +++ b/pkg/cli/cmds/common.go @@ -26,8 +26,8 @@ type controllers struct { } const ( - terraState = "terrastate" - terraKey = "terraKey" + terraState = "tfstate" + terraKey = "tfstateSecretSuffix" ) var controllerCache *controllers diff --git a/pkg/executor/runner/backend.go b/pkg/executor/runner/backend.go index bda210fd..9b0ced62 100644 --- a/pkg/executor/runner/backend.go +++ b/pkg/executor/runner/backend.go @@ -9,7 +9,7 @@ type Terraform struct { } type Backend struct { - Namespace string `json:"namespace,omitempty"` - Key string `json:"key,omitempty"` - ServiceAccount string `json:"service_account,omitempty"` + Namespace string `json:"namespace,omitempty"` + SecretSuffix string `json:"secret_suffix,omitempty"` + InClusterConfig string `json:"in_cluster_config,omitempty"` } diff --git a/pkg/executor/runner/runner.go b/pkg/executor/runner/runner.go index 2c0f5ce8..63ceaa39 100644 --- a/pkg/executor/runner/runner.go +++ b/pkg/executor/runner/runner.go @@ -290,9 +290,9 @@ func (r *Runner) WriteConfigFile() error { Terraform: Terraform{ Backend: map[string]*Backend{ "kubernetes": { - Key: r.Execution.Spec.ExecutionName, - Namespace: r.Execution.Namespace, - ServiceAccount: "true", + SecretSuffix: r.Execution.Spec.ExecutionName, + Namespace: r.Execution.Namespace, + InClusterConfig: "true", }, }, }, @@ -316,7 +316,7 @@ func (r *Runner) WriteVarFile() error { if !ok { return fmt.Errorf("no varFile data found in secret %v", r.VarSecret.Name) } - err := writer.Write(vars, fmt.Sprintf("/root/module/%v.auto.tfvars", r.Execution.Name)) + err := writer.Write(vars, fmt.Sprintf("/root/module/%v.auto.tfvars.json", r.Execution.Name)) if err != nil { return err } diff --git a/pkg/terraform/state/deploy.go b/pkg/terraform/state/deploy.go index ed21c71f..99d21a63 100644 --- a/pkg/terraform/state/deploy.go +++ b/pkg/terraform/state/deploy.go @@ -448,7 +448,6 @@ func createEnvForJob(input *Input, action, runName, namespace string) { func getCombinedVars(state *v1.State, input *Input) map[string]string { combinedVars := combineVars(input) - combinedVars["key"] = state.Name return combinedVars }