Repository navigation
155 lines (137 loc) · 5.65 KB
/
Copy pathtf-plan.yml
File metadata and controls
155 lines (137 loc) · 5.65 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Terraform Plan
on:
workflow_call:
inputs:
aws_account_id:
description: "AWS account ID"
type: string
default: "553637109631"
aws_region:
description: "AWS region"
type: string
default: "eu-central-1"
tf_root:
description: "Terraform root directory"
type: string
default: "terraform"
team:
description: "Team from app.yaml (the broker verifies the repo belongs to it)"
type: string
default: ""
outputs:
has_changes:
description: "Whether the plan has changes"
value: ${{ jobs.plan.outputs.has_changes }}
plan_key:
description: "S3 key of the plan artifact"
value: ${{ jobs.plan.outputs.plan_key }}
plan_sha256:
description: "SHA256 hash of the plan artifact"
value: ${{ jobs.plan.outputs.plan_sha256 }}
risk_level:
description: "Risk level from LLM review (LOW, MEDIUM, HIGH, FAILED)"
value: ${{ jobs.plan.outputs.risk_level }}
planned_sha:
description: "Commit the plan was made from (includes generated Terraform)"
value: ${{ jobs.plan.outputs.planned_sha }}
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
plan:
name: Terraform Plan
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.plan.outputs.has_changes }}
plan_key: ${{ steps.upload.outputs.plan_key }}
plan_sha256: ${{ steps.upload.outputs.plan_sha256 }}
risk_level: ${{ steps.review.outputs.risk_level }}
planned_sha: ${{ steps.sha.outputs.sha }}
env:
PLAN_BUCKET: javabin-ci-plan-artifacts-${{ inputs.aws_account_id }}
steps:
- name: Set session name
# Bot actors (renovate[bot]) contain characters STS rejects in session names
run: echo "SESSION_NAME=$(echo "${GITHUB_ACTOR}-${GITHUB_SHA:0:8}-${GITHUB_RUN_ID}" | tr -c 'A-Za-z0-9+=,.@_\n-' '-' | head -c 64)" >> "$GITHUB_ENV"
# Branch head, not github.sha: expand may have just committed generated
# Terraform on top of the triggering commit.
- uses: actions/checkout@v6
with:
ref: ${{ github.head_ref || github.ref }}
- name: Record planned commit
id: sha
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- uses: hashicorp/setup-terraform@v4
with:
terraform_version: "1.7"
terraform_wrapper: false
# javaBin/platform is public: the caller's own GITHUB_TOKEN can read it,
# so app repos need no GitHub App credentials for any pipeline step.
- name: Checkout platform scripts
uses: actions/checkout@v6
with:
repository: javaBin/platform
ref: main
path: .platform
sparse-checkout: scripts
persist-credentials: false
- name: Assume broker role via OIDC
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::${{ inputs.aws_account_id }}:role/javabin-ci-app-broker
aws-region: ${{ inputs.aws_region }}
role-session-name: ${{ env.SESSION_NAME }}
- name: Get team credentials from broker
id: broker
env:
PROJECT: javabin
APP_TEAM: ${{ inputs.team }}
run: sh .platform/scripts/invoke-ci-broker.sh plan
- name: Ensure Terraform boilerplate
env:
AWS_ACCOUNT_ID: ${{ inputs.aws_account_id }}
AWS_REGION: ${{ inputs.aws_region || 'eu-central-1' }}
GH_TOKEN: ${{ github.token }}
run: sh .platform/scripts/ensure-tf-boilerplate.sh "${{ inputs.tf_root }}"
- name: Terraform Init
working-directory: ${{ inputs.tf_root }}
run: terraform init -input=false
- name: Terraform Validate
working-directory: ${{ inputs.tf_root }}
run: terraform validate
- name: Terraform Format Check
working-directory: ${{ inputs.tf_root }}
run: terraform fmt -check -recursive
- name: Terraform Plan
id: plan
run: .platform/scripts/run-plan.sh "${{ inputs.tf_root }}"
- name: Upload plan to S3
id: upload
if: steps.plan.outputs.has_changes == 'true'
run: .platform/scripts/upload-plan.sh "${{ inputs.tf_root }}"
# ----------------------------------------------------------------
# LLM plan review — done by the javabin-plan-review Lambda with
# platform credentials (team roles have no Bedrock access, and only
# the Lambda may write risk.json). Re-assume the broker OIDC role,
# which may invoke it.
# ----------------------------------------------------------------
- name: Assume broker role for plan review
if: steps.plan.outputs.has_changes == 'true'
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::${{ inputs.aws_account_id }}:role/javabin-ci-app-broker
aws-region: ${{ inputs.aws_region }}
role-session-name: ${{ env.SESSION_NAME }}
- name: Run LLM review
id: review
if: steps.plan.outputs.has_changes == 'true'
env:
NOTIFY: ${{ github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
run: sh .platform/scripts/invoke-plan-review.sh "${{ steps.upload.outputs.plan_key }}"
- name: Post plan + review to PR
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: sh .platform/scripts/post-plan-comment.sh "${{ inputs.tf_root }}/plan-output.txt" "${{ steps.plan.outputs.has_changes }}"