Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CONFIG_APP_CLIENT_ID: Iv23lipEOAvwk5QqNUie
TF_CLI_ARGS: "-no-color"
TF_IN_AUTOMATION: "true"
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v3
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
client-id: Iv23lipEOAvwk5QqNUie
client-id: ${{ env.CONFIG_APP_CLIENT_ID }}
private-key: ${{ secrets.CONFIG_APP_SECRET }}
owner: ${{ github.repository_owner }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
repositories: ${{ github.event.repository.name }}
- name: Setup OpenTofu
uses: opentofu/setup-opentofu@v2
uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2
with:
tofu_wrapper: false
- name: TF init
Expand Down
128 changes: 128 additions & 0 deletions .github/workflows/plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Plan

on:
pull_request_target:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
paths:
- "**/*.tf"
- "**/*.csv"

permissions:
contents: read
pull-requests: write

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
plan:
runs-on: ubuntu-latest
environment: plan
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
CONFIG_APP_CLIENT_ID: Iv23lipEOAvwk5QqNUie
TF_CLI_ARGS: "-no-color"
TF_IN_AUTOMATION: "true"
steps:
- name: Checkout PR
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
ref: ${{ github.event.pull_request.head.sha }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
persist-credentials: false

- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
with:
client-id: ${{ env.CONFIG_APP_CLIENT_ID }}
private-key: ${{ secrets.CONFIG_APP_SECRET }}
owner: ${{ github.repository_owner }}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
repositories: ${{ github.event.repository.name }}
permission-contents: read

- name: Setup OpenTofu
uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2
with:
tofu_wrapper: false

- name: TF init
run: tofu init

- name: TF Validate
run: tofu validate

- name: TF Lint
uses: terraform-linters/setup-tflint@6e1e0642c0289bd619021bf6b34e3c08ed1e005a # v6.3.0
- run: tflint --init && tflint

- name: TF Plan
id: plan
run: |
set +e
tofu plan -detailed-exitcode 2>&1 | tee plan_output.txt
exitcode=${PIPESTATUS[0]}
echo "exitcode=$exitcode" >> "$GITHUB_OUTPUT"
if [ "$exitcode" -eq 1 ]; then
exit 1
fi
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

- name: Comment plan on PR
if: always() && steps.plan.outcome != 'skipped'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const fs = require('fs');
const raw = fs.readFileSync('plan_output.txt', 'utf8');
const plan = raw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
const exitcode = '${{ steps.plan.outputs.exitcode }}';

let summary;
if (exitcode === '0') {
summary = 'No changes. Infrastructure is up-to-date.';
} else if (exitcode === '2') {
summary = 'Changes detected. Review the plan below.';
} else {
summary = 'Plan failed. See details below.';
}

const marker = '<!-- tofu-plan -->';
const body = [
marker,
`### OpenTofu Plan`,
'',
summary,
'',
'<details><summary>Show plan output</summary>',
'',
`<pre>${plan.substring(0, 60000)}</pre>`,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
'',
'</details>',
'',
`*Commit: ${context.payload.pull_request.head.sha}*`,
].join('\n');

const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));

if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
10 changes: 6 additions & 4 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ jobs:
env:
TF_CLI_ARGS: "-no-color"
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v6
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
with:
python-version: "3.13"
- uses: opentofu/setup-opentofu@v2
- uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2
with:
tofu_wrapper: false
- uses: pre-commit/action@v3.0.1
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
with:
extra_args: --all-files
36 changes: 36 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Validate

on:
pull_request:
paths:
- "**/*.tf"
- "**/*.csv"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
validate:
runs-on: ubuntu-latest
env:
TF_CLI_ARGS: "-no-color"
TF_IN_AUTOMATION: "true"
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
Comment thread
coderabbitai[bot] marked this conversation as resolved.
with:
persist-credentials: false

- name: Setup OpenTofu
uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2
with:
tofu_wrapper: false

- name: TF init (no backend)
run: tofu init -backend=false

- name: TF Validate
run: tofu validate
Loading