Skip to content

Test infra plan/apply with multiple projects#354

Draft
mamu0 wants to merge 16 commits into
mainfrom
test-infra-apply-matrix
Draft

Test infra plan/apply with multiple projects#354
mamu0 wants to merge 16 commits into
mainfrom
test-infra-apply-matrix

Conversation

@mamu0

@mamu0 mamu0 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

PR for testing

@changeset-bot

changeset-bot Bot commented Mar 31, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b360110

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines +52 to +66
name: Get Terraform Version
runs-on: ubuntu-latest
outputs:
terraform_version: ${{ steps.get-version.outputs.terraform_version }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Get terraform version from .terraform-version file
id: get-version
uses: pagopa/dx/.github/actions/get-terraform-version@main
with:
default_version: "1.10.4"

detect-projects:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

In general, fix this by explicitly setting a permissions block that grants the minimal required scopes for the GITHUB_TOKEN. You can add it at the workflow root so it applies to all jobs, or per job if some need additional rights. For a workflow that only needs to read repository contents (e.g., checkout code, run Terraform, static analysis) and not update PRs or issues, contents: read is usually sufficient.

For this specific file, the best minimal non-breaking fix is to add a workflow-level permissions block right after the on: section and before env:. This will apply to all jobs (get-terraform-version, detect-projects, tf-modules-check, tf_plan, etc.) unless a job explicitly overrides it. Based on the visible snippets, these jobs only need to read repository contents, so contents: read is an appropriate least-privilege setting. No imports or additional methods are required; this is purely a YAML configuration change in .github/workflows/infra_apply.yaml.

Concretely:

  • In .github/workflows/infra_apply.yaml, insert:
permissions:
  contents: read

after the workflow_call inputs block (line 35/36) and before the existing env: block (line 37). No other changes are necessary.

Suggested changeset 1
.github/workflows/infra_apply.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_apply.yaml b/.github/workflows/infra_apply.yaml
--- a/.github/workflows/infra_apply.yaml
+++ b/.github/workflows/infra_apply.yaml
@@ -34,6 +34,9 @@
         required: false
         default: ""
 
+permissions:
+  contents: read
+
 env:
   ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
   ARM_USE_OIDC: true
EOF
@@ -34,6 +34,9 @@
required: false
default: ""

permissions:
contents: read

env:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_USE_OIDC: true
Copilot is powered by AI and may make mistakes. Always verify output.

- name: Get terraform version from .terraform-version file
id: get-version
uses: pagopa/dx/.github/actions/get-terraform-version@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_apply.yaml' step
Uses Step: get-version
uses 'pagopa/dx/.github/actions/get-terraform-version' with ref 'main', not a pinned commit hash
Comment on lines +67 to +127
name: Detect Terraform Projects
runs-on: ubuntu-latest
needs: [get-terraform-version]
outputs:
matrix: ${{ steps.detect.outputs.matrix }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

- name: Detect Terraform projects
id: detect
env:
BASE_PATH: ${{ inputs.base_path }}
ENVIRONMENT: ${{ inputs.environment }}
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
BEFORE: ${{ github.event.before }}
SHA: ${{ github.sha }}
run: |
set -euo pipefail
BASE_PATH="${BASE_PATH%/}"
DIR="$BASE_PATH/$ENVIRONMENT"

if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
CHANGED=$(find "$DIR" -maxdepth 2 -name '*.tf' -not -path "*/_modules/*" 2>/dev/null || true)
elif [ "$EVENT_NAME" = "pull_request" ]; then
CHANGED=$(git diff --name-only "origin/${BASE_REF}...HEAD" -- "$DIR" || true)
else
CHANGED=$(git diff --name-only "$BEFORE" "$SHA" -- "$DIR" || true)
fi

# The two layouts are mutually exclusive:
# - flat: a .tf exists directly in $DIR → $DIR is the single project root
# - multi-project: no .tf directly in $DIR → each first-level subdir is a project root
IS_FLAT=$(printf '%s\n' "$CHANGED" | while IFS= read -r file; do
rel="${file#"${DIR}/"}"
case "$rel" in
*/*) ;; # file in a subdir: not a flat indicator
*.tf) echo 1; break ;; # .tf directly in $DIR: flat project
esac
done)

if [ -n "$IS_FLAT" ]; then
MATRIX=$(jq -cn --arg d "$DIR" '[$d]')
else
MATRIX=$(printf '%s\n' "$CHANGED" \
| while IFS= read -r file; do
[ -z "$file" ] && continue
rel="${file#"${DIR}/"}"
case "$rel" in */*) echo "${DIR}/${rel%%/*}" ;; esac
done \
| sort -u \
| jq -R . | jq -sc .)
fi

MATRIX=${MATRIX:-[]}
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
echo "Detected matrix: $MATRIX"

tf-modules-check:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

To fix the problem, explicitly define a permissions block that restricts the GITHUB_TOKEN to the least privileges needed. In this workflow, jobs primarily read repository contents (checkout, git diff) and do not appear to need write access or special scopes like pull-requests: write. The minimal safe baseline is contents: read at the workflow root so that it applies to all jobs (get-terraform-version, detect-projects, tf-modules-check, tf_plan, tf_apply, etc.) that don’t override it.

The best fix without changing existing functionality is to add a root-level permissions block just after the on: trigger configuration (before env: or concurrency:). This will ensure all jobs use a read-only token for repository contents. No other code changes are required in the jobs themselves. Concretely, in .github/workflows/infra_apply.yaml, insert:

permissions:
  contents: read

between the on: block and the env: block (around existing lines 36–37). This does not affect any other behavior of the workflow, only the GitHub token’s allowed operations.

Suggested changeset 1
.github/workflows/infra_apply.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_apply.yaml b/.github/workflows/infra_apply.yaml
--- a/.github/workflows/infra_apply.yaml
+++ b/.github/workflows/infra_apply.yaml
@@ -34,6 +34,9 @@
         required: false
         default: ""
 
+permissions:
+  contents: read
+
 env:
   ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
   ARM_USE_OIDC: true
EOF
@@ -34,6 +34,9 @@
required: false
default: ""

permissions:
contents: read

env:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_USE_OIDC: true
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +128 to +143
uses: pagopa/dx/.github/workflows/static_analysis.yaml@main
name: Check terraform registry modules hashes
needs: [get-terraform-version, detect-projects]
if: ${{ needs.detect-projects.outputs.matrix != '[]' }}
secrets: inherit
strategy:
fail-fast: false
matrix:
dir: ${{ fromJSON(needs.detect-projects.outputs.matrix) }}
with:
terraform_version: ${{ needs.get-terraform-version.outputs.terraform_version }}
check_to_run: lock_modules
folder: ${{ matrix.dir }}/
verbose: true

tf_plan:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

Copilot Autofix

AI 4 months ago

To fix the problem, explicitly declare a permissions block to restrict the GITHUB_TOKEN on the tf-modules-check job (and optionally at the workflow root, but the reported issue is specifically on this job). Since this job runs static analysis and does not obviously need to write to the repo, a safe and minimal starting point is contents: read. If the reusable workflow requires additional scopes, they can be added later, but we should not assume write access is needed.

Concretely:

  • Edit .github/workflows/infra_apply.yaml.
  • In the tf-modules-check job definition (around line 134–149), add a permissions: section indented to the same level as needs: and strategy:.
  • Set:
    • contents: read as a minimal permission.
    • If you know this job needs nothing else (no PR comments, etc.), keep only that. Given the provided snippet, we will add just contents: read.

No imports or other code changes are needed; only the YAML for this job is updated.

Suggested changeset 1
.github/workflows/infra_apply.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_apply.yaml b/.github/workflows/infra_apply.yaml
--- a/.github/workflows/infra_apply.yaml
+++ b/.github/workflows/infra_apply.yaml
@@ -137,6 +137,8 @@
     needs: [get-terraform-version, detect-projects]
     if: ${{ needs.detect-projects.outputs.matrix != '[]' }}
     secrets: inherit
+    permissions:
+      contents: read
     strategy:
       fail-fast: false
       matrix:
EOF
@@ -137,6 +137,8 @@
needs: [get-terraform-version, detect-projects]
if: ${{ needs.detect-projects.outputs.matrix != '[]' }}
secrets: inherit
permissions:
contents: read
strategy:
fail-fast: false
matrix:
Copilot is powered by AI and may make mistakes. Always verify output.
done

- name: Cloud Login
uses: pagopa/dx/actions/csp-login@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_apply.yaml' step
Uses Step
uses 'pagopa/dx/actions/csp-login' with ref 'main', not a pinned commit hash

- name: Get terraform version from .terraform-version file
id: get-version
uses: pagopa/dx/.github/actions/get-terraform-version@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_plan.yaml' step
Uses Step: get-version
uses 'pagopa/dx/.github/actions/get-terraform-version' with ref 'main', not a pinned commit hash
done

- name: Cloud Login
uses: pagopa/dx/actions/csp-login@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_plan.yaml' step
Uses Step
uses 'pagopa/dx/actions/csp-login' with ref 'main', not a pinned commit hash

- name: Terraform Setup
id: set-terraform-version
uses: pagopa/dx/.github/actions/terraform-setup@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_plan.yaml' step
Uses Step: set-terraform-version
uses 'pagopa/dx/.github/actions/terraform-setup' with ref 'main', not a pinned commit hash

- name: Terraform Plan
id: plan
uses: pagopa/dx/actions/filter-terraform-plan@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_plan.yaml' step
Uses Step: plan
uses 'pagopa/dx/actions/filter-terraform-plan' with ref 'main', not a pinned commit hash
- name: Post Plan on PR
id: comment
if: always() && github.event_name == 'pull_request'
uses: pagopa/dx/actions/pr-comment@main

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'infra_plan.yaml' step
Uses Step: comment
uses 'pagopa/dx/actions/pr-comment' with ref 'main', not a pinned commit hash
@github-actions

Copy link
Copy Markdown
Contributor
📋 Pre-commit Output Log
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[INFO] Initializing environment for https://github.com/pagopa/dx.
Lock Terraform Registry modules......................(no files to check)Skipped

Generated on Tue Mar 31 15:12:23 UTC 2026
Run lock_modules on folder: infra/resources/dev/_modules/

Comment on lines +51 to +71
name: Fork PR Gate
runs-on: ubuntu-latest
outputs:
run: ${{ steps.evaluate.outputs.run }}
steps:
- name: Evaluate fork PR
id: evaluate
env:
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
CURRENT_REPO: ${{ github.repository }}
run: |
# Only block forked PRs; allow all other events
if [ "$EVENT_NAME" = "pull_request" ] && [ -n "$PR_HEAD_REPO" ] && [ "$PR_HEAD_REPO" != "$CURRENT_REPO" ]; then
echo "Blocking forked PR from $PR_HEAD_REPO"
echo "run=false" >> "$GITHUB_OUTPUT"
else
echo "run=true" >> "$GITHUB_OUTPUT"
fi

get-terraform-version:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

Copilot Autofix

AI 4 months ago

Generally, the fix is to explicitly declare a permissions block for the workflow (or per job) that grants only the minimal scopes required. Since this workflow primarily checks out code and runs Terraform, it only needs read access to repository contents by default.

The best minimally invasive change is to add a root-level permissions block near the top of .github/workflows/infra_plan.yaml (for example, immediately after the on: configuration and before env:). This block should set contents: read, which aligns with GitHub’s recommended baseline for workflows that only need to read the repo. All jobs (including gate, get-terraform-version, and subsequent Terraform-related jobs) will then inherit these least-privilege permissions, preserving existing functionality while constraining the GITHUB_TOKEN by default. No imports or additional methods are needed because this is a YAML configuration change only.

Suggested changeset 1
.github/workflows/infra_plan.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_plan.yaml b/.github/workflows/infra_plan.yaml
--- a/.github/workflows/infra_plan.yaml
+++ b/.github/workflows/infra_plan.yaml
@@ -34,6 +34,9 @@
         required: false
         default: ""
 
+permissions:
+  contents: read
+
 env:
   ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
   ARM_USE_OIDC: true
EOF
@@ -34,6 +34,9 @@
required: false
default: ""

permissions:
contents: read

env:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_USE_OIDC: true
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +72 to +88
name: Get Terraform Version
runs-on: ubuntu-latest
needs: gate
if: ${{ needs.gate.outputs.run == 'true' }}
outputs:
terraform_version: ${{ steps.get-version.outputs.terraform_version }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Get terraform version from .terraform-version file
id: get-version
uses: pagopa/dx/.github/actions/get-terraform-version@main
with:
default_version: "1.10.4"

detect-projects:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

In general, fix this by explicitly declaring a permissions: block that grants only the minimal required permissions to the GITHUB_TOKEN. You can put this block at the workflow root (applies to all jobs not overriding it) or on the specific job that CodeQL flagged. Given the suggestion and the job’s behavior (only checking out code and running an internal action), contents: read is sufficient.

The best minimally invasive fix is to add a root-level permissions: block after the on: section so it applies to all jobs, using contents: read. This both resolves the CodeQL warning and documents that the workflow only needs read access to the repository contents. No imports or additional methods are needed; this is a YAML-only change within .github/workflows/infra_plan.yaml.

Concretely, in .github/workflows/infra_plan.yaml, insert:

permissions:
  contents: read

between the on: workflow_call: ... inputs block and the existing env: block (after line 35 and before line 37 in the snippet). This keeps all existing functionality while constraining the GITHUB_TOKEN for all jobs, including get-terraform-version.

Suggested changeset 1
.github/workflows/infra_plan.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_plan.yaml b/.github/workflows/infra_plan.yaml
--- a/.github/workflows/infra_plan.yaml
+++ b/.github/workflows/infra_plan.yaml
@@ -34,6 +34,9 @@
         required: false
         default: ""
 
+permissions:
+  contents: read
+
 env:
   ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
   ARM_USE_OIDC: true
EOF
@@ -34,6 +34,9 @@
required: false
default: ""

permissions:
contents: read

env:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_USE_OIDC: true
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +89 to +150
name: Detect Terraform Projects
runs-on: ubuntu-latest
needs: [gate, get-terraform-version]
if: ${{ needs.gate.outputs.run == 'true' }}
outputs:
matrix: ${{ steps.detect.outputs.matrix }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0

- name: Detect Terraform projects
id: detect
env:
BASE_PATH: ${{ inputs.base_path }}
ENVIRONMENT: ${{ inputs.environment }}
EVENT_NAME: ${{ github.event_name }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
BEFORE: ${{ github.event.before }}
SHA: ${{ github.sha }}
run: |
set -euo pipefail
BASE_PATH="${BASE_PATH%/}"
DIR="$BASE_PATH/$ENVIRONMENT"

if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
CHANGED=$(find "$DIR" -maxdepth 2 -name '*.tf' -not -path "*/_modules/*" 2>/dev/null || true)
elif [ "$EVENT_NAME" = "pull_request" ]; then
CHANGED=$(git diff --name-only "origin/${BASE_REF}...HEAD" -- "$DIR" || true)
else
CHANGED=$(git diff --name-only "$BEFORE" "$SHA" -- "$DIR" || true)
fi

# The two layouts are mutually exclusive:
# - flat: a .tf exists directly in $DIR → $DIR is the single project root
# - multi-project: no .tf directly in $DIR → each first-level subdir is a project root
IS_FLAT=$(printf '%s\n' "$CHANGED" | while IFS= read -r file; do
rel="${file#"${DIR}/"}"
case "$rel" in
*/*) ;; # file in a subdir: not a flat indicator
*.tf) echo 1; break ;; # .tf directly in $DIR: flat project
esac
done)

if [ -n "$IS_FLAT" ]; then
MATRIX=$(jq -cn --arg d "$DIR" '[$d]')
else
MATRIX=$(printf '%s\n' "$CHANGED" \
| while IFS= read -r file; do
[ -z "$file" ] && continue
rel="${file#"${DIR}/"}"
case "$rel" in */*) echo "${DIR}/${rel%%/*}" ;; esac
done \
| sort -u \
| jq -R . | jq -sc .)
fi

MATRIX=${MATRIX:-[]}
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
echo "Detected matrix: $MATRIX"

tf-modules-check:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 4 months ago

In general, the problem is fixed by explicitly defining a permissions block that limits the GITHUB_TOKEN to the minimal scopes required. For this workflow, all shown jobs (gate, get-terraform-version, detect-projects, plus downstream reusable-workflow jobs) only need to read repository contents and metadata; they do not push commits, create releases, or modify issues/PRs. Therefore, contents: read at the workflow root is an appropriate default minimal permission. If any downstream reusable workflow requires broader permissions, it can define or override its own permissions block.

The best fix without changing functionality is to add a root-level permissions: section near the top of .github/workflows/infra_plan.yaml, alongside on: and env:, setting contents: read. This restricts the default for all jobs that don’t define permissions themselves, including detect-projects (the one flagged by CodeQL). No other code changes, imports, or definitions are needed, and the workflow behavior remains the same because all current operations are compatible with read-only repository access.

Concretely: in .github/workflows/infra_plan.yaml, between the on: block (lines 1–12 shown) and the env: block (line 37), add:

permissions:
  contents: read

No additional methods or dependencies are required.

Suggested changeset 1
.github/workflows/infra_plan.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_plan.yaml b/.github/workflows/infra_plan.yaml
--- a/.github/workflows/infra_plan.yaml
+++ b/.github/workflows/infra_plan.yaml
@@ -34,6 +34,9 @@
         required: false
         default: ""
 
+permissions:
+  contents: read
+
 env:
   ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
   ARM_USE_OIDC: true
EOF
@@ -34,6 +34,9 @@
required: false
default: ""

permissions:
contents: read

env:
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
ARM_USE_OIDC: true
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +151 to +166
uses: pagopa/dx/.github/workflows/static_analysis.yaml@main
name: Check terraform registry modules hashes
needs: [gate, get-terraform-version, detect-projects]
if: ${{ needs.gate.outputs.run == 'true' && needs.detect-projects.outputs.matrix != '[]' }}
secrets: inherit
strategy:
fail-fast: false
matrix:
dir: ${{ fromJSON(needs.detect-projects.outputs.matrix) }}
with:
terraform_version: ${{ needs.get-terraform-version.outputs.terraform_version }}
check_to_run: lock_modules
folder: ${{ matrix.dir }}/
verbose: true

tf_plan:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}

Copilot Autofix

AI 4 months ago

To fix this, we should add an explicit permissions block to the tf-modules-check job so that the GITHUB_TOKEN is restricted to only what is needed. Since this job runs a static analysis workflow and does not appear to push code or change repository state, a conservative and safe default is read-only repository contents: contents: read. If the called reusable workflow needs more (e.g., to comment on PRs), that should be granted there; in this caller, we’ll keep it minimal.

Concretely, in .github/workflows/infra_plan.yaml, within the tf-modules-check job (starting at line 158), add a permissions section at the same indentation level as needs, if, secrets, and strategy. The new block should be:

    permissions:
      contents: read

This does not change any existing logic or behavior beyond restricting the default GITHUB_TOKEN rights and aligns with the least‑privilege recommendation. No imports or additional definitions are required.

Suggested changeset 1
.github/workflows/infra_plan.yaml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/infra_plan.yaml b/.github/workflows/infra_plan.yaml
--- a/.github/workflows/infra_plan.yaml
+++ b/.github/workflows/infra_plan.yaml
@@ -161,6 +161,8 @@
     needs: [gate, get-terraform-version, detect-projects]
     if: ${{ needs.gate.outputs.run == 'true' && needs.detect-projects.outputs.matrix != '[]' }}
     secrets: inherit
+    permissions:
+      contents: read
     strategy:
       fail-fast: false
       matrix:
EOF
@@ -161,6 +161,8 @@
needs: [gate, get-terraform-version, detect-projects]
if: ${{ needs.gate.outputs.run == 'true' && needs.detect-projects.outputs.matrix != '[]' }}
secrets: inherit
permissions:
contents: read
strategy:
fail-fast: false
matrix:
Copilot is powered by AI and may make mistakes. Always verify output.
@mamu0
mamu0 temporarily deployed to infra-dev-ci April 2, 2026 11:02 — with GitHub Actions Inactive
@mamu0
mamu0 temporarily deployed to infra-dev-ci April 2, 2026 11:02 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ All Terraform module locks are up to date

No module changes detected - everything is in sync!

📋 Pre-commit Output Log
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[INFO] Initializing environment for https://github.com/pagopa/dx.
Terraform fmt........................................................................Passed
Terraform docs.......................................................................Failed
- hook id: terraform_docs
- files were modified by this hook
Terraform validate...................................................................Failed
- hook id: terraform_validate
- files were modified by this hook

Command 'terraform init' successfully done: infra/resources/_modules/api
Command 'terraform init' successfully done: infra/resources/dev/dummy_project
Command 'terraform init' successfully done: infra/resources/dev/base_project

Terraform Providers Lock (on staged .terraform.lock.hcl files).......................Passed
- hook id: terraform_providers_lock_staged
- duration: 0.01s

No .terraform.lock.hcl files to process.

Lock Terraform Registry modules......................................................Passed
All changes made by hooks:
diff --git a/infra/resources/_modules/api/.terraform.lock.hcl b/infra/resources/_modules/api/.terraform.lock.hcl
index 50584c8..6d27a2b 100644
--- a/infra/resources/_modules/api/.terraform.lock.hcl
+++ b/infra/resources/_modules/api/.terraform.lock.hcl
@@ -5,6 +5,7 @@ provider "registry.terraform.io/hashicorp/azurerm" {
   version = "4.14.0"
   hashes = [
     "h1:FYWhn/x1jSjnxUsKkV4+sXIfOc+H3Sq8ja/ZBB2IAaU=",
+    "h1:FYZ9qh8i3X2gDmUTe1jJ/VzdSyjGjVmhBzv2R8D6CBo=",
     "h1:cGkb9Ps5A1FwXO7BaZ9T7Ufe79gsNzk6lfaNfcWn0+s=",
     "zh:05aaea16fc5f27b14d9fbad81654edf0638949ed3585576b2219c76a2bee095a",
     "zh:065ce6ed16ba3fa7efcf77888ea582aead54e6a28f184c6701b73d71edd64bb0",
diff --git a/infra/resources/dev/base_project/README.md b/infra/resources/dev/base_project/README.md
index b206fc3..a2dcea1 100644
--- a/infra/resources/dev/base_project/README.md
+++ b/infra/resources/dev/base_project/README.md
@@ -24,9 +24,9 @@
 | <a name="module_apim"></a> [apim](#module\_apim) | pagopa-dx/azure-api-management/azurerm | ~> 2.1 |
 | <a name="module_cosmos"></a> [cosmos](#module\_cosmos) | pagopa-dx/azure-cosmos-account/azurerm | ~> 0.3 |
 | <a name="module_naming_convention"></a> [naming\_convention](#module\_naming\_convention) | pagopa-dx/azure-naming-convention/azurerm | ~> 0.0 |
-| <a name="module_playground_monitoring"></a> [playground\_monitoring](#module\_playground\_monitoring) | ../_modules/monitoring | n/a |
+| <a name="module_playground_monitoring"></a> [playground\_monitoring](#module\_playground\_monitoring) | ../../_modules/monitoring | n/a |
 | <a name="module_postgres"></a> [postgres](#module\_postgres) | pagopa-dx/azure-postgres-server/azurerm | ~> 3.0 |
-| <a name="module_to_do_api"></a> [to\_do\_api](#module\_to\_do\_api) | ../_modules/api | n/a |
+| <a name="module_to_do_api"></a> [to\_do\_api](#module\_to\_do\_api) | ../../_modules/api | n/a |
 | <a name="module_todo_api_function_app"></a> [todo\_api\_function\_app](#module\_todo\_api\_function\_app) | pagopa-dx/azure-function-app/azurerm | ~> 4.1 |
 | <a name="module_todo_api_function_app_roles"></a> [todo\_api\_function\_app\_roles](#module\_todo\_api\_function\_app\_roles) | pagopa-dx/azure-role-assignments/azurerm | ~> 1.0 |
 | <a name="module_todo_webapp_app_service"></a> [todo\_webapp\_app\_service](#module\_todo\_webapp\_app\_service) | pagopa-dx/azure-app-service/azurerm | ~> 2.0 |

Generated on Thu Apr 2 11:21:48 UTC 2026
Run all checks on modified files

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ All Terraform module locks are up to date

No module changes detected - everything is in sync!

📋 Pre-commit Output Log
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[INFO] Initializing environment for https://github.com/pagopa/dx.
Lock Terraform Registry modules..........................................Passed

Generated on Thu Apr 2 11:21:52 UTC 2026
Run lock_modules on folder: infra/resources/dev/dummy_project/

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ All Terraform module locks are up to date

No module changes detected - everything is in sync!

📋 Pre-commit Output Log
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[INFO] Initializing environment for https://github.com/pagopa/dx.
Lock Terraform Registry modules..........................................Passed

Generated on Thu Apr 2 11:21:53 UTC 2026
Run lock_modules on folder: infra/resources/dev/base_project/

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

📖 Terraform Plan (infra/resources/dev/dummy_project) - success

Show Plan
No changes detected.

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

📖 Terraform Plan (infra/resources/dev/base_project) - success

Show Plan
No changes detected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants