Skip to content

Instantly share code, notes, and snippets.

@sodonnell
Created August 28, 2024 15:47
Show Gist options
  • Save sodonnell/2e9b87f006b7ef4ff6524d925091753c to your computer and use it in GitHub Desktop.
Save sodonnell/2e9b87f006b7ef4ff6524d925091753c to your computer and use it in GitHub Desktop.
terraform.apply.destroy.remote.state.example
#!/usr/bin/env bash
TF_STATE_BUCKET=tfstate-ops
TF_STATE_PREFIX=cluster/ops
### USE REMOTE TFSTATE via S3
terraform init \
-backend-config=bucket=${TF_STATE_BUCKET} \
-backend-config=key=${TF_STATE_PREFIX}/cluster.tfstate \
-backend-config=region=us-west-2 \
-force-copy \
-no-color;
### CREATE
terraform plan -no-color -var-file=tfvars/ops.tfvars -out=cluster-ops.pln
time terraform apply -auto-approve -no-color cluster-ops.pln &> cluster-ops-apply.log
exit
### DESTROY
terraform plan -destroy -no-color -var-file=tfvars/ops.tfvars -out=destroy-ops.pln
time terraform apply -auto-approve -no-color destroy-ops.pln &> cluster-ops-destroy.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment