Skip to content

Terraform

Ilya Sytchev edited this page Feb 28, 2019 · 21 revisions

Terraform Documentation

Tested with Terraform version v0.11.7 and AWS provider v1.16.0

Install Terraform using Homebrew (on OS X):

$ brew install terraform

Create S3 bucket (if doesn't already exist) to store Terraform infrastructure states:

$ aws s3 mb s3://<state-bucket-name> --region us-east-1

Note: all commands below should be executed from deployment/terraform/live directory.

Initialize Terraform (once per repo clone):

$ terraform init -upgrade -backend-config="bucket=<state-bucket-name>" -backend-config="region=us-east-1"
  • NOTE: When terraform init is re-run with providers already installed, it will use an already-installed provider that meets the constraints in preference to downloading a new version. To upgrade to the latest acceptable version of each provider, run terraform init -upgrade. This command also upgrades to the latest versions of all Terraform modules. https://www.terraform.io/docs/configuration/providers.html#provider-versions

Initialize site infrastructure configuration:

$ terraform workspace new <workspace-name>

Note: will be used as a prefix for naming infrastructure resources like S3 buckets.

Create site infrastructure resources on AWS (or update if exists):

$ terraform apply

check that proposed actions are correct before typing yes to confirm


Switch to a different site infrastructure configuration:

$ terraform workspace select <workspace-name>

update terraform.tfvars (make sure values match the current workspace)

Delete site infrastructure resources on AWS:

$ terraform destroy

check that proposed actions are correct before typing yes to confirm

Delete site infrastructure configuration:

$ terraform workspace delete <workspace-name>

To pull module updates (after editing):

$ terraform get

To update providers to the latest version

Note: also upgrades all modules to the latest versions

$ terraform init -upgrade \
    -backend-config="bucket=<state-bucket-name>" \
    -backend-config="region=us-east-1"
Clone this wiki locally