Skip to content

fix(modules/folder): pass the folder number to the logging settings - #359

Merged
aghassemlouei merged 1 commit into
google:mainfrom
digitalresistor:fix/folder-logging-settings
Oct 26, 2026
Merged

aghassemlouei merged 1 commit into
google:mainfrom
digitalresistor:fix/folder-logging-settings

Conversation

@digitalresistor

Copy link
Copy Markdown
Contributor

Description

Let Terraform apply the logging settings of a folder that the modules/folder/ module manages, which currently fails for every folder that sets the logging_settings variable.

The google_logging_folder_settings resource builds the folders/{{folder}}/settings URL itself. The module passes the folder ID with its folders/ prefix, so the request goes to /v2/folders/folders/<number>/settings and the API returns 404.

  • The Stage 0 common services folder sets the logging_settings variable, so the first Stage 0 apply fails on it.
  • The new folder_number local in modules/folder/main.tf strips the folders/ prefix, matching the local of the same name in the upstream Cloud Foundation Fabric folder module.
  • The local uses the trimprefix function, so a caller that passes a bare folder number with folder_create = false keeps working.
  • The google_logging_folder_settings resource in modules/folder/logging.tf now uses that local.
  • The IAM, log sink, log exclusion, essential contacts, and organization policy resources in the module keep the folder ID, because their APIs accept the folders/ prefix.
  • The new tests/test_folder_logging_settings.py test checks both changes.
  • The change needs no README update, because no variable or output changes.

No GitHub issue exists for this change. The stellar CLI work in #306 found it during a lab Stage 0 apply. The Fabric sync in #311 brings the same upstream code, so whichever merges second takes the upstream version.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Deployment & Compliance Impact

  • Applicable Regimes:
    • US Region Restricted (e.g., Access Policy constraint)
    • FedRAMP Moderate
    • FedRAMP High
    • DoD IL4
    • DoD IL5
    • General / All
  • NIST 800-53r5 Controls: None changed. The fix lets the Stage 0 folders apply their configured log storage location, which supports the existing regional data boundary.

Checklist

Code Quality & Reusability

  • My code adheres to the Maximize Reusability principle. I have not redefined common elements and have reused existing base configurations and modules where possible.
  • I have checked that no existing module or configuration in modules/ or fast/stages-aw/ can be leveraged for this change.
  • My code follows the established naming conventions outlined in docs/naming-convention.md.

Documentation

  • I have updated the README.md of the modified module or blueprint.
  • I have added/updated documentation for inputs (variables) and outputs.

Security

  • My change adheres to GCP security best practices and the principle of least privilege.
  • I have ensured compliance with the targeted regime (FedRAMP Moderate, FedRAMP High, IL4, IL5, etc.).

Testing

  • I have tested my changes locally.
  • I have included details of my testing in this PR.

Testing Performed

  • A lab Stage 0 apply from main failed on module.branch-common-services-folder.google_logging_folder_settings.default[0] with a 404 for the /v2/folders/folders/<number>/settings URL.
  • terraform init -backend=false and terraform validate pass for the modules/folder/ module and the fast/stages-aw/0-bootstrap/ stage.
  • terraform fmt -check passes for the module.
  • tools/check_documentation.py passes for the module.
  • uv run --locked pytest in the repository root passes 109 tests.
  • The new test fails against the code on main.
  • A rerun of the lab apply with this change waits for the next lab session.

The google_logging_folder_settings resource builds the
folders/{{folder}}/settings URL itself, so the folders/ prefix of the
folder ID doubled it and the API returned 404 on every folder with
logging_settings, such as the Stage 0 common services folder.

- Add a folder_number local, matching the local of the same name in the
  upstream Fabric folder module. trimprefix keeps a bare folder number
  that callers pass with folder_create = false.
- Pass it to google_logging_folder_settings.
- Add a test for both.
@github-actions github-actions Bot added the Scope - Module Related to reusable Terraform modules in the modules directory label Oct 26, 2026
@aghassemlouei aghassemlouei added Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent labels Oct 26, 2026

@aghassemlouei aghassemlouei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified modules/folder with terraform test (mock_provider), bash tools/run_tests.sh (tests/test_folder_logging_settings.py), and bash tools/lint.sh:

  • local.folder_number = trimprefix(local.folder_id, "folders/") normalizes both newly created folders (google_folder.folder[0].id returning folders/<number>) and existing folders (folder_create = false) so google_logging_folder_settings.default[0].folder always receives the bare folder number expected by the Cloud Logging API.

@aghassemlouei
aghassemlouei merged commit d74fa6e into google:main Oct 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent Scope - Module Related to reusable Terraform modules in the modules directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants