Remote state
Now that we have created the environment definition file, we can bootstrap the environment.
Terraform state is a file that tracks the resources Terraform has created. By default, this file is stored locally. The bootstrap command creates the S3 bucket and DynamoDB table needed to store Terraform state remotely.
After these steps, you will have a foundation for all the other stacks you create inside this environment.
Step 1: Add and configure the remote-state package
In package-config.yml, set S3Backend to false:
Step 2: Install the package
Step 3: Initialize and apply the remote-state stack
Initialize and apply the stack to create the S3 bucket and DynamoDB table:
SSH Key
If you haven't already added a SSH key to your GitHub account (or have gh(GitHub CLI) configured). See GitHub SSH key guide for more information. This is required for Terraform to be able to fetch the modules from the golden-path-iac repository.
Step 4: Verify
Verify that the S3 bucket for storing remote Terraform state was created.
You are looking for a bucket with the following name:
For example:
Step 5: Move your current local Terraform state to the S3 backend
You now have remote storage for all future stacks. However, this stack still uses a local state file (terraform.tfstate).
Transfer the local state to the S3 bucket by reconfiguring Terraform to use S3 as the backend.
Edit package-config.yml and set S3Backend to true:
Reinstall the package:
Initialize the new configuration:
Verify that everything is working by running terraform plan. There should not be any changes to apply at this point:
Delete terraform.tfstate since it's now stored in S3. This ensures Terraform uses the remote state instead of creating a new local file.
Commit your files
At this stage it is a good idea to commit your files.
Next step
Set up DNS.