Last active
August 12, 2022 21:29
-
-
Save JoshuaSchlichting/d944d52d8ee6b93dbab81c2dc40610a4 to your computer and use it in GitHub Desktop.
A bash script for executing terraform within Docker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# This script is used to execute terraform commands in the current working directory, using Docker. | |
# USAGE: ./terraform_docker.sh <init, plan, apply, or any other valid terraform argument> | |
# NOTE: You will need to ensure this file is executable. You can do this by executing `chmod +x ./terraform_docker.sh`. | |
# !!!!!!!!!!!!!!!!! TERRAFORM CLOUD !!!!!!!!!!!!!!!!! | |
# NOTE: As written, this script assumes you have a credentials.tfrc.json file, which is | |
# generated via `terraform login`. This may seem like a "chicken & the egg" problem, | |
# given that this script is for executing terraform within docker. However, I wrote | |
# this script to assist developers using Apple Silicon for when they run into roadblocks | |
# with their current Terraform install targeting arm64 builds of Terraform. | |
# Location of your Terraform Cloud token | |
TF_CLOUD_TOKEN_FILE=$HOME/.terraform.d/credentials.tfrc.json | |
PLATFORM=linux/amd64 | |
docker run \ | |
-it \ | |
--rm \ | |
--name terraform \ | |
-v $PWD:/data/terraform \ | |
-v $TF_CLOUD_TOKEN_FILE:/root/.terraform.d/credentials.tfrc.json \ | |
--platform $PLATFORM \ | |
--workdir=/data/terraform \ | |
hashicorp/terraform:latest \ | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment