How to use the official Terraform Docker image

/IaC
├── README.md
├── env-vars
│ ├── prod.tfvars
│ └── test.tfvars
├── infrastructure
│ ├── test
│ │ ├── README.md
│ │ ├── config.tf
│ │ ├── data.tf
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── versions.tf
│ ├── prod
│ │ ├── README.md
│ │ ├── config.tf
│ │ ├── data.tf
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── versions.tf
#!/bin/bash
export AZURE_CLIENT_ID=<hidden-value>
export AZURE_TENANT_ID=<hidden-value>
export AZURE_CLIENT_SECRET='<hidden-value>'
export AZURE_SUBSCRIPTION_ID=<hidden-value>
hideme=$(az login --service-principal --username $AZURE_CLIENT_ID --password $AZURE_CLIENT_SECRET --tenant $AZURE_TENANT_ID)
az account set -s $AZURE_SUBSCRIPTION_ID
docker pull docker.io/hashicorp/terraform
docker run -i -t docker.io/hashicorp/terraform version
docker run … hashicorp/terraform:0.13.3 …
cd /IaC
export TF_ENV=test
docker run -i -t -v $PWD:$PWD -w $PWD/infrastructure/${TF_ENV} \
— env ARM_CLIENT_ID=$AZURE_CLIENT_ID \
— env ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET \
— env ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID \
— env ARM_TENANT_ID=$AZURE_TENANT_ID \
hashicorp/terraform:0.13.3 \
init -reconfigure \
-backend-config=”resource_group_name=${TF_ENV}-tf-state-rg” \
-backend-config=”storage_account_name=${TF_ENV}-tf-storage” \
-backend-config=”container_name=tfstate” \
-backend-config=”key=${TF_ENV}.terraform.tfstate”
cd /IaC
export TF_ENV=test
docker run -i -t -v $PWD:$PWD -w $PWD/infrastructure/${TF_ENV} \
— env ARM_CLIENT_ID=$AZURE_CLIENT_ID \
— env ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET \
— env ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID \
— env ARM_TENANT_ID=$AZURE_TENANT_ID \
hashicorp/terraform:0.13.3 \
plan -var-file=../../env-vars/${TF_ENV}.tfvars -out=${TF_ENV}.tfplan
cd /IaC
export TF_ENV=test
docker run -i -t -v $PWD:$PWD -w $PWD/infrastructure/${TF_ENV} \
— env ARM_CLIENT_ID=$AZURE_CLIENT_ID \
— env ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET \
— env ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID \
— env ARM_TENANT_ID=$AZURE_TENANT_ID \
hashicorp/terraform:0.13.3 \
apply ${TF_ENV}.tfplan
cd /IaC
export TF_ENV=test
docker run -i -t -v $PWD:$PWD -w $PWD/infrastructure/${TF_ENV} \
— env ARM_CLIENT_ID=$AZURE_CLIENT_ID \
— env ARM_CLIENT_SECRET=$AZURE_CLIENT_SECRET \
— env ARM_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID \
— env ARM_TENANT_ID=$AZURE_TENANT_ID \
hashicorp/terraform:0.13.3 \
destroy -var-file=../../env-vars/${TF_ENV}.tfvars

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Audun Nes

Audun Nes

Site Reliability Engineer from Copenhagen, Denmark. GitHub: https://github.com/avnes