Skip to content

fix: use dynamic iap block to prevent perpetual no-op diff#586

Open
ianb-pomelo wants to merge 1 commit into
terraform-google-modules:mainfrom
ianb-pomelo:fix/dynamic-iap-block
Open

fix: use dynamic iap block to prevent perpetual no-op diff#586
ianb-pomelo wants to merge 1 commit into
terraform-google-modules:mainfrom
ianb-pomelo:fix/dynamic-iap-block

Conversation

@ianb-pomelo

Copy link
Copy Markdown

Problem

When iap_config is not provided in a backend configuration, the static iap block sets oauth2_client_id to null. However, the GCP API returns " " (a single space) for unset oauth2_client_id values, causing Terraform to detect a diff on every plan:

~ iap {
    - oauth2_client_id = " " -> null
  }

This results in a perpetual no-op update to google_compute_backend_service resources that don't use IAP.

Solution

Make the iap block dynamic so it is only rendered when iap_config is explicitly provided. When iap_config is absent, the block is omitted entirely, and Terraform no longer tries to reconcile null vs the " " returned by the API.

Changes

The same change is applied in all 4 locations where the iap block appears:

  • main.tf
  • modules/serverless_negs/main.tf
  • modules/dynamic_backends/main.tf
  • autogen/main.tf.tmpl

Before:

iap {
  enabled              = try(each.value["iap_config"], null) == null ? false : ...
  oauth2_client_id     = try(each.value["iap_config"], null) == null ? null : ...
  oauth2_client_secret = try(each.value["iap_config"], null) == null ? null : ...
}

After:

dynamic "iap" {
  for_each = try(each.value["iap_config"], null) != null ? [each.value["iap_config"]] : []
  content {
    enabled              = lookup(iap.value, "enable", false)
    oauth2_client_id     = lookup(iap.value, "oauth2_client_id", null)
    oauth2_client_secret = lookup(iap.value, "oauth2_client_secret", null)
  }
}

Backward Compatibility

This is a non-breaking change:

  • Backends with iap_config set behave identically to before
  • Backends without iap_config simply stop producing the phantom diff

Related: #451, hashicorp/terraform-provider-google#16585

When `iap_config` is not provided in a backend configuration, the static
`iap` block sets `oauth2_client_id` to `null`. However, the GCP API
returns `" "` (a single space) for unset `oauth2_client_id` values,
causing Terraform to detect a diff on every plan:

    ~ iap {
        - oauth2_client_id = " " -> null
      }

By making the `iap` block dynamic, it is only rendered when `iap_config`
is explicitly provided. This eliminates the perpetual no-op diff for
backends that don't use IAP, while preserving existing behavior for
backends that do.
@ianb-pomelo

Copy link
Copy Markdown
Author

/gcbrun

@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions Bot added the Stale label May 3, 2026
@ianb-pomelo

Copy link
Copy Markdown
Author

Still would like this if possible, it causes a good amount of churn in our state for no reason

@github-actions github-actions Bot removed the Stale label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant