Examples of:
- Running Terraform CLI from within a docker container on the Host
- Running Terraform scripts against localstack
docker-compose up
docker-compose down
./tf
is a script provided to execute the terraform 0.13.4 CLI with the
specifications in the ./docker-compose.terraform.yml
file. This way
terraform does not have to be installed locally on the machine.
# create the sample-bucket in S3
./tf apply
# destroy the bucket
./tf destroy
This function allows running the Terraform CLI in a docker container. An
alternative/example if you don't want to run it using the ./tf
script.
function tf () {
# grants access to host network and uses the current directory as
# the working directory with read-write mode
docker run \
--interactive \
--tty \
--network host \
--volume "$(pwd):/tf:rw" \
--user "$(id -u):$(id -g)" \
--workdir '/tf' \
--rm \
hashicorp/terraform:light \
"$@"
}
This assumes docker-compose up
has already been run.
export AWS_ACCESS_KEY_ID=mock
export AWS_SECRET_ACCESS_KEY=mock
export AWS_REGION=us-east-1
aws --endpoint-url 'http://localhost:4566' s3api list-buckets
aws --endpoint-url 'http://localhost:4566' s3 ls