This post goes through the steps explained in this presentation:
- Cumulus Circles: Automate AWS Infra Deployment using Terraform and GitHub Actions (2022), github
Steps:
- Create a
codeAWS account inAWS Organizations. - Assign your user as admin to the
codeAWS account inIAM Identity Center - Log into the
codeAWS account as yourself - In
IAM, createterraformuser, and give it Admin privileges - Create Access Keys for the
terraformuser- In the user details page, navigate to the
Security credentialstab.- Under the “Access keys” section, click on
Create access key. - Download and Store the Keys Safely:
- Under the “Access keys” section, click on
- Once the access key is created, AWS will offer you the option to download the key as a .csv file. This file contains the Access Key ID and Secret Access Key.
- Download and save this file in a secure location. This is the only time AWS will display the Secret Access Key. If you lose it, you’ll have to create a new access key.
- In the user details page, navigate to the
- Create Gitlab repo
aws-terraform- In repo, click
Settings, clickSecrets and variables->Actions,New repository secrets - Add
AWS_ACCESS_KEY_IDand `AWS_SECRET_ACCESS_KEY
- In repo, click
- Copy contents of github
- Copy
src/*at the top level of theaws-terraformsandbox- Change the bucket name. It must be unique across AWS.
- Copy
.gitignoreto the top level of theaws-terraformsandbox - Don’t copy the
.githubfolder with the git actions just yet - Run
git addat the top, check in and commit
- Copy
- In
main.tf- Comment out the terraform backend config for now
- Comment out
vpc-inframodule for now
- Install
terraforme.g. using these instructions - Source the AWS environment variables
- Run these commands:
terraform initterraform validateterraform planterraform apply
- Comment in the backend
- Update the bucket name in the back end to match the configured bucket
- Run these commands:
terraform init- Enter
yesto copy your state to the S3 backend
- Enter
terraform plan- Don’t run
terraform apply. We will apply the changes through Github Actions.
- Copy the
.gitlabfolder from the original sandbox- Change the path from
srcto.in theterraform.yaml
- Change the path from
- Enable the vpc module
- Check in. The changes will be applied through Gitlab Actions
- Review the Gitlab Actions log in the web UI
- Disable the vpc module, setting a
count=0variable (instead of commenting the module out) - Apply the changes again.