logo
Menu

Amazon CodeCatalyst workflow for Terraform for a PR branch

Example CodeCatalyst workflow to run Terraform plan on a PR branch.

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 validate and plan to test if the Terraform code is valid on a PR. It is intended to be used on a PR branch - see this example of the main 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: TerraformPRBranch
SchemaVersion: "1.0"

Triggers:
- Type: PULLREQUEST
Events:
- OPEN
- REVISION

Actions:
Terraform-PR-Branch-Plan:
Identifier: aws/build@v1
Inputs:
Sources:
- WorkflowSource
Environment:
Connections:
- Role: PR-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
Compute:
Type: EC2