Skip to content

Commit 77973ca

Browse files
ksobrenat32pabloem
andauthored
GCP User IAM workflow modified to post Terraform plan as a comment on PRs (#36375)
* GCP User IAM workflow modified to post Terraform plan as a comment on PRs * Update GCP IAM roles in users.yml and modify workflow permissions for pull requests * Update role for user to use custom beam_viewer role for testing * Update beam_Infrastructure_UsersPermissions.yml Changing event_name to p_r_t, and removing the specific ref to checkout * Update beam_Infrastructure_UsersPermissions.yml removing all p_r_t filters to make it match all prs * Return the filer on pull_request_target beam_Infrastructure_UsersPermissions.yml --------- Co-authored-by: P <pabloem@users.noreply.github.com>
1 parent 661c730 commit 77973ca

2 files changed

Lines changed: 35 additions & 11 deletions

File tree

.github/workflows/beam_Infrastructure_UsersPermissions.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
# This workflow modifies the GCP User Roles when the infra/users.yml file is updated.
1919
# It applies the changes using Terraform to manage the IAM roles for users defined in the users.yml
20+
# If the workflow is triggered by a pull request, it will post the Terraform plan as a comment on the PR
21+
# as a code block for easy review.
2022

2123
name: Modify the GCP User Roles according to the infra/users.yml file
2224

@@ -28,6 +30,10 @@ on:
2830
- main
2931
paths:
3032
- 'infra/iam/users.yml'
33+
pull_request_target:
34+
types: [opened, synchronize, reopened]
35+
paths:
36+
- 'infra/iam/users.yml'
3137

3238
# This allows a subsequently queued workflow run to interrupt previous runs
3339
concurrency:
@@ -36,7 +42,8 @@ concurrency:
3642

3743
#Setting explicit permissions for the action to avoid the default permissions which are `write-all` in case of pull_request_target event
3844
permissions:
39-
contents: read
45+
contents: write
46+
pull-requests: write
4047

4148
jobs:
4249
beam_UserRoles:
@@ -57,6 +64,28 @@ jobs:
5764
- name: Terraform Plan
5865
working-directory: ./infra/iam
5966
run: terraform plan -out=tfplan
67+
68+
- name: Convert plan to plaintext
69+
if: github.event_name == 'pull_request_target'
70+
working-directory: ./infra/iam
71+
run: terraform show -no-color tfplan > tfplan.txt
72+
73+
- name: Create comment body
74+
if: github.event_name == 'pull_request_target'
75+
run: |
76+
echo "### Terraform Plan for User Roles Changes" > comment_body.txt
77+
echo '```' >> comment_body.txt
78+
cat ./infra/iam/tfplan.txt >> comment_body.txt
79+
echo '```' >> comment_body.txt
80+
81+
- name: Upload plan as a comment to PR
82+
if: github.event_name == 'pull_request_target'
83+
env:
84+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
GH_REPO: ${{ github.repository }}
86+
run: gh pr comment ${{ github.event.pull_request.number }} --body-file comment_body.txt
87+
6088
- name: Terraform Apply
89+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'apache/beam'
6190
working-directory: ./infra/iam
6291
run: terraform apply -auto-approve tfplan

infra/iam/users.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@
1414
# limitations under the License.
1515

1616
# IAM policy for project apache-beam-testing
17-
# Generated on 2025-09-19 18:17:58 UTC
17+
# Generated on 2025-10-07 16:00:39 UTC
1818

1919
- username: WhatWouldAustinDo
2020
email: WhatWouldAustinDo@gmail.com
2121
permissions:
2222
- role: roles/editor
23-
- username: a.khorbaladze
24-
email: a.khorbaladze@akvelon.us
25-
permissions:
26-
- role: roles/bigquery.admin
27-
- role: roles/container.admin
28-
- role: roles/editor
29-
- role: roles/iam.serviceAccountUser
30-
- role: roles/secretmanager.admin
3123
- username: aaronleeiv
3224
email: aaronleeiv@google.com
3325
permissions:
@@ -84,6 +76,7 @@
8476
- role: roles/iam.serviceAccountTokenCreator
8577
- role: roles/iam.serviceAccountUser
8678
- role: roles/iam.workloadIdentityUser
79+
- role: roles/storage.objectAdmin
8780
- role: roles/viewer
8881
- username: allows-impersonation-new
8982
email: allows-impersonation-new@apache-beam-testing.iam.gserviceaccount.com
@@ -197,6 +190,7 @@
197190
- role: roles/managedkafka.schemaRegistryEditor
198191
- role: roles/monitoring.metricWriter
199192
- role: roles/monitoring.viewer
193+
- role: roles/secretmanager.admin
200194
- role: roles/spanner.databaseAdmin
201195
- role: roles/stackdriver.resourceMetadata.writer
202196
- role: roles/storage.admin
@@ -238,6 +232,7 @@
238232
- role: roles/iam.serviceAccountTokenCreator
239233
- role: roles/iam.serviceAccountUser
240234
- role: roles/pubsub.admin
235+
- role: roles/secretmanager.admin
241236
- role: roles/spanner.admin
242237
- role: roles/storage.admin
243238
- role: roles/storage.folderAdmin
@@ -372,7 +367,7 @@
372367
- username: enriquecaol04
373368
email: enriquecaol04@gmail.com
374369
permissions:
375-
- role: roles/viewer
370+
- role: projects/apache-beam-testing/roles/beam_viewer
376371
- username: eventarc-workflow-sa
377372
email: eventarc-workflow-sa@apache-beam-testing.iam.gserviceaccount.com
378373
permissions:

0 commit comments

Comments
 (0)