Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Update Terraform to 0.13.4 (#67)
Browse files Browse the repository at this point in the history
* Update Terraform to 0.13.4

Terraform 0.13.1 have kubernetes backend support.

Signed-off-by: Dinar Valeev <dinar.valeev@absa.africa>

* Drop key var from varFile

Signed-off-by: Dinar Valeev <dinar.valeev@absa.africa>
  • Loading branch information
k0da authored Oct 21, 2020
1 parent bd7e925 commit 1a908db
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}

Expand Down
8 changes: 3 additions & 5 deletions package/Dockerfile.executor
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmds/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type controllers struct {
}

const (
terraState = "terrastate"
terraKey = "terraKey"
terraState = "tfstate"
terraKey = "tfstateSecretSuffix"
)

var controllerCache *controllers
Expand Down
6 changes: 3 additions & 3 deletions pkg/executor/runner/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
8 changes: 4 additions & 4 deletions pkg/executor/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand All @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion pkg/terraform/state/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 1a908db

Please sign in to comment.