Terraform state for each environment/prefix is stored in the S3 bucket using Terraform S3 data source. Remote state currently does not lock regions of your infrastructure to allow parallel modification using Terraform. Therefore, you must still collaborate with teammates to safely run Terraform. Keep in mind that Terraform state contains sensitive information.
To start working in a given environment you need to prepare the config file and to init the S3 backend (state storage).
You must use Terraform 0.9 or superior
Configuration is done using a terraform.tfvars
file. Do not commit it to the repository.
prefix = "development"
State storage is configured on files terraform.backend.development
. Create new files for other environments
The following commands expect that you have configure an AWS cli profile named myprofile
with admin access to the target AWS account.
- Execute
cd terraform; rm .terraform/*; terraform init -backend-config=terraform.backend.development
- Dry-run with
terraform plan
- (Danger) Apply with
terraform apply
- Change the "key" value in the
terraform.backend.development
files to match the new project name. - If the state for a new project or environment is stored on a different bucket, you need to change bucket, region and profile too.
- Create a proper
terraform.tfvars
by copyingterraform.tfvars.example
- Init the state
In order to do provisioning on the instance you create, do not forget to modify your identity_location
and public_key
inside of your terraform.tfvars
.