3These scripts are all related to [Terraform], the infrastructure-as-code tool we use at work.
5[
Terraform]:
https://www.terraform.io/
7## The individual scripts
11# This adds the root of the repo to the PATH, which has cog_helpers.py
12from os.path import abspath, dirname
15sys.path.append(abspath(dirname(dirname("."))))
19folder_name = "terraform"
24 "description": "alias for
`terraform`",
29 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/init"><code>terraform init</code></a>
35 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/plan"><code>terraform plan -out=tfplan</code></a>.
36 I run this before making any changes, so I can review what Terraform is about to do.
42 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/apply"><code>terraform apply terraform.plan</code></a>.
43 I only run this after I’ve reviewed the proposed changes from <code>tfp</code>.
49 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/state/mv"><code>terraform state mv</code></a>
55 alias for the <a href="https://github.com/terraform-linters/tflint">tflint linter</a>, but running inside a Docker container
60cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
65 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tf">
74 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tfi">
79 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/init"><code>terraform init</code></a>
83 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tfp">
88 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/plan"><code>terraform plan -out=tfplan</code></a>.
89 I run this before making any changes, so I can review what Terraform is about to do.
93 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tfa">
98 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/apply"><code>terraform apply terraform.plan</code></a>.
99 I only run this after I’ve reviewed the proposed changes from <code>tfp</code>.
103 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tfmv">
108 alias for <a href="https://developer.hashicorp.com/terraform/cli/commands/state/mv"><code>terraform state mv</code></a>
112 <a href="https://github.com/alexwlchan/scripts/blob/main/terraform/tflint">
117 alias for the <a href="https://github.com/terraform-linters/tflint">tflint linter</a>, but running inside a Docker container
120<!-- [[[end]]] (sum: udcN6wOhi/) -->
122## Choosing between `terraform` and `run_terraform.sh`
124In some of the Terraform configurations at work, we use wrapper scripts
`run_terraform.sh` instead of invoking
`terraform` directly.
125This wrapper script fetches API keys for the [Elastic Cloud] and [Auth0] providers, so we don't have to hard-code them or store them locally.
129EC_API_KEY=$(aws secretsmanager get-secret-value
\
130 --secret-id
"elastic_cloud/api_key" \
132 --query
"SecretString")
134EC_API_KEY="$EC_API_KEY" terraform
"$@"
137My
`tf` scripts will choose whether to run a wrapper script or vanilla
`terraform`, so I don't have to think about it.
139[
Elastic Cloud]:
https://registry.terraform.io/providers/elastic/ec/latest/docs#using-your-api-key-on-the-elastic-cloud-terraform-provider
140[
Auth0]:
https://registry.terraform.io/providers/auth0/auth0/latest/docs#environment-variables