Skip to content

cloudscheduler: fix headers drift when oidc_token/oauth_token is set#17074

Open
hamza-younas94 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
hamza-younas94:cloudscheduler-strip-authorization-header
Open

cloudscheduler: fix headers drift when oidc_token/oauth_token is set#17074
hamza-younas94 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
hamza-younas94:cloudscheduler-strip-authorization-header

Conversation

@hamza-younas94
Copy link
Copy Markdown

Fixes a perpetual diff on google_cloud_scheduler_job.http_target.headers when oidc_token or oauth_token is configured. The Cloud Scheduler API injects an Authorization header server-side in that case, which the existing flattener was not stripping — so the API-injected value landed in state and Terraform repeatedly tried to remove it.

The fix is gated on the presence of one of the token blocks under http_target, so:

  • Pub/Sub-only jobs (no http_target block at all) are unaffected.
  • app_engine_http_target.headers (which has no oidc_token/oauth_token siblings) is unaffected.
  • Users who set a literal Authorization header without token auth keep the existing preservation behaviour.

A validation warning (not an error) is also surfaced when both Authorization and a token block are configured, so users see a hint before hitting the drift.

Tests

  • New unit test TestCloudScheduler_FlattenHttpHeaders_AuthorizationStrippedWithOidc covers the oidc-set, oauth-set, and no-token cases against the http_target flattener using a populated *schema.ResourceData.
  • Extended TestCloudScheduler_FlattenHttpHeaders with a regression case asserting the App Engine flattener still preserves a literal Authorization header (pubsub/app-engine safety guard).

No related upstream issue found in hashicorp/terraform-provider-google, so no Fixes link.

cloudscheduler: fixed perpetual diff on `google_cloud_scheduler_job.http_target.headers` when `oidc_token` or `oauth_token` is set

…auth tokens are set

Cloud Scheduler injects an `Authorization` header server-side whenever
`http_target.oidc_token` or `http_target.oauth_token` is configured. The
existing `http_headers` flattener did not strip it, so the value showed up
in state and produced a perpetual diff against the user-supplied `headers`
map.

The strip is gated on the presence of one of the token blocks under
`http_target`, so:

  * Pubsub-only jobs (no `http_target` block) are unaffected — the
    `d.Get("http_target.0.oidc_token.#")` lookups return zero.
  * App Engine HTTP targets (which have no token blocks) are unaffected
    for the same reason.
  * Users who legitimately set a literal `Authorization` header without
    token auth keep the existing behaviour.

Also surface a validation warning (not an error) when both `Authorization`
and one of the token blocks would otherwise collide, so users get a hint
before they hit the drift.

Adds unit-test coverage for: oidc-set strip, oauth-set strip, no-token
preservation, and the existing app-engine flattener path.
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Apr 10, 2026
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 10, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@hamza-younas94 hamza-younas94 marked this pull request as ready for review April 11, 2026 08:47
@github-actions
Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@c2thorn, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@github-actions github-actions bot requested a review from c2thorn April 11, 2026 08:48
@github-actions
Copy link
Copy Markdown

@c2thorn This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

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

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants