Skip to content

Commit e8e7efe

Browse files
committed
ci(dev-experience): run IaC checks in Terraform/OpenTofu matrix
Merge Terraform and OpenTofu validation into one matrix-based workflow job. Keep Terraform PR comments scoped to Terraform entries while adding OpenTofu runs for ~1.11.0, ~1.10.0, and ~1.9.0.
1 parent d856d1b commit e8e7efe

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

.github/workflows/dev-experience.yml

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ concurrency:
1818

1919
jobs:
2020
terraform-check:
21-
name: Terraform Check
21+
name: IaC Check (${{ matrix.label }})
2222
runs-on: ubuntu-latest
2323
permissions:
2424
contents: read # for actions/checkout to fetch code
@@ -28,50 +28,89 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
include:
31-
- version: ~1.9.0
32-
- version: ~1.10.0
33-
- version: ~1.11.0
34-
- version: ~1.12.0
35-
- version: ~1.13.0
36-
- version: ~1.14.0
31+
- engine: terraform
32+
cli: terraform
33+
version: "~1.9.0"
34+
label: "Terraform ~1.9.0"
35+
- engine: terraform
36+
cli: terraform
37+
version: "~1.10.0"
38+
label: "Terraform ~1.10.0"
39+
- engine: terraform
40+
cli: terraform
41+
version: "~1.11.0"
42+
label: "Terraform ~1.11.0"
43+
- engine: terraform
44+
cli: terraform
45+
version: "~1.12.0"
46+
label: "Terraform ~1.12.0"
47+
- engine: terraform
48+
cli: terraform
49+
version: "~1.13.0"
50+
label: "Terraform ~1.13.0"
51+
- engine: terraform
52+
cli: terraform
53+
version: "~1.14.0"
54+
label: "Terraform ~1.14.0"
55+
- engine: tofu
56+
cli: tofu
57+
version: "~1.11.0"
58+
label: "OpenTofu ~1.11.0"
59+
- engine: tofu
60+
cli: tofu
61+
version: "~1.10.0"
62+
label: "OpenTofu ~1.10.0"
63+
- engine: tofu
64+
cli: tofu
65+
version: "~1.9.0"
66+
label: "OpenTofu ~1.9.0"
3767
steps:
3868
- name: Checkout
3969
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4070
with:
4171
ref: refs/pull/${{ github.event.pull_request.number }}/merge
42-
- name: Configure Terraform plugin cache
72+
- name: Configure IaC plugin cache
4373
run: |
4474
echo 'plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"' > ~/.terraformrc
4575
mkdir -p ~/.terraform.d/plugin-cache
46-
- name: Cache Terraform
76+
- name: Cache IaC
4777
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
4878
with:
4979
path: ~/.terraform.d/plugin-cache
50-
key: "${{ runner.os }}-terraform-${{ hashFiles(format('{0}/.terraform.lock.hcl', matrix.version)) }}"
51-
restore-keys: "${{ runner.os }}-terraform-"
80+
key: "${{ runner.os }}-${{ matrix.engine }}-${{ matrix.version }}-${{ hashFiles('.terraform.lock.hcl') }}"
81+
restore-keys: "${{ runner.os }}-${{ matrix.engine }}-"
5282
- name: Setup Terraform
83+
if: matrix.engine == 'terraform'
5384
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
5485
with:
5586
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
5687
terraform_version: ${{ matrix.version }}
88+
- name: Setup OpenTofu
89+
if: matrix.engine == 'tofu'
90+
uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8
91+
with:
92+
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
93+
tofu_version: ${{ matrix.version }}
5794
- name: Save terraform version to output
95+
if: matrix.engine == 'terraform'
5896
id: terraform-version
5997
run: |
6098
terraform version
6199
echo "TERRAFORM_VERSION=$(terraform version --json | jq -r '.terraform_version')" >> $GITHUB_OUTPUT
62-
- name: Terraform Format
100+
- name: IaC Format
63101
id: fmt
64-
run: terraform fmt -recursive -check -diff
102+
run: ${{ matrix.cli }} fmt -recursive -check -diff
65103
continue-on-error: true
66-
- name: Terraform Init
104+
- name: IaC Init
67105
id: init
68-
run: terraform init -no-color
106+
run: ${{ matrix.cli }} init -no-color
69107
continue-on-error: true
70-
- name: Terraform Validate
108+
- name: IaC Validate
71109
id: validate
72-
run: terraform validate -no-color
110+
run: ${{ matrix.cli }} validate -no-color
73111
continue-on-error: true
74112
- name: Find Comment
113+
if: matrix.engine == 'terraform'
75114
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
76115
id: find-comment
77116
with:
@@ -80,6 +119,7 @@ jobs:
80119
body-includes: |
81120
Terraform-Check (version: ${{ steps.terraform-version.outputs.TERRAFORM_VERSION }})
82121
- name: Create or update comment
122+
if: matrix.engine == 'terraform'
83123
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
84124
with:
85125
comment-id: ${{ steps.find-comment.outputs.comment-id }}

0 commit comments

Comments
 (0)