logo
Menu

Amazon CodeCatalyst workflow for Terraform

Example CodeCatalyst workflow to apply Terraform infrastructure changes.

Cobus Bernard
Cobus Bernard
Amazon Employee
Published May 5, 2023

⏰ Last Updated
2023-05-05

This snippet shows a CodeCatalyst workflow that will run Terraform to apply infrastructure changes. It uses validate and plan to test if the Terraform code is valid. It is intended to be used on the main branch, and run after merging a PR that has been validated - see this example of the PR branch workflow. Alternative version using GitHub Actions.

Used in:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Name: TerraformMainBranch
SchemaVersion: "1.0"

Triggers:
- Type: Push
Branches:
- main

Actions:
Terraform-Main-Branch-Apply:
Identifier: aws/build@v1
Inputs:
Sources:
- WorkflowSource
Environment:
Connections:
- Role: Main-Branch-Infrastructure
Name: "123456789012"
Name: TerraformBootstrap
Configuration:
Steps:
- Run: export TF_VERSION=1.3.7 && wget -O terraform.zip "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip"
- Run: unzip terraform.zip && rm terraform.zip && mv terraform /usr/bin/terraform && chmod +x /usr/bin/terraform
- Run: terraform fmt -check -no-color
- Run: terraform init -no-color
- Run: terraform validate -no-color
- Run: terraform plan -no-color -input=false
- Run: terraform apply -auto-approve -no-color -input=false
Compute:
Type: EC2