logo

Amazon CodeCatalyst workflow for a PR branch for Terraform using GitHub Actions

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

Cobus Bernard
Cobus Bernard
Amazon Employee
Published May 5, 2023

⏰ Last Updated
2023-03-01

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 standard CodeCatalyst workflow.

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
31
32
33
34
35
36
37
38
39
40
Name: TerraformPRBranch
SchemaVersion: "1.0"

# Optional - Set automatic triggers.
Triggers:
- Type: PULLREQUEST
Branches:
- main
Events:
- OPEN
- REVISION

# Build actions
Actions:
Terraform-PR-Branch-Plan:
Identifier: aws/github-actions-runner@v1
Inputs:
Sources:
- WorkflowSource
Environment:
Connections:
- Role: PR-Branch-Infrastructure
Name: "123456789012"
Name: TerraformBootstrap
Configuration:
Steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.3.7
- name: Terraform Format
run: terraform fmt -check -no-color
- name: Terraform Init
run: terraform init -no-color
- name: Terraform Validate
run: terraform validate -no-color
- name: Terraform Plan
run: terraform plan -no-color -input=false
Compute:
Type: EC2