Skip to content

google_alloydb_instance: fix permadiff on network_config.enable_public_ip#18245

Open
BBBmau wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
BBBmau:alloydb-permadiff-fix-network-config
Open

google_alloydb_instance: fix permadiff on network_config.enable_public_ip#18245
BBBmau wants to merge 3 commits into
GoogleCloudPlatform:mainfrom
BBBmau:alloydb-permadiff-fix-network-config

Conversation

@BBBmau

@BBBmau BBBmau commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes a permadiff issue where google_alloydb_instance continuously shows a diff adding network_config { enable_public_ip = false } even after it has been applied.

Upstream issue: hashicorp/terraform-provider-google#22197

Root Cause

The AlloyDB API omits networkConfig entirely from GET responses when both enable_public_ip and enable_outbound_public_ip are false (the default). This created a perpetual diff cycle:

  1. User sets network_config { enable_public_ip = false } and applies
  2. On expand, false is treated as an empty value by IsEmptyValue and is not sent to the API
  3. API returns nil for networkConfig in subsequent reads
  4. Flatten returns nil → state is cleared (network_config = [])
  5. Next plan: config has the block, state is empty → diff shown forever

This is the same pattern that was previously fixed for connection_pool_config.

Fix

mmv1/products/alloydb/Instance.yaml:

  • Added custom_flatten pointing to a new template for networkConfig
  • Added send_empty_value: true to enablePublicIp and enableOutboundPublicIp so that false is sent explicitly to the API (changes expand logic from !IsEmptyValue check to != nil)
  • Added default_from_api: true to those same fields so they are treated as computed in state

mmv1/templates/terraform/custom_flatten/alloydb_instance_networkconfig_flatten.go.tmpl (new):

  • When the API returns nil or empty networkConfig, preserves the existing state values instead of clearing the block — eliminates the permadiff

Testing

Manually reproduced the scenario described in the issue:

  • Set network_config { enable_public_ip = false }
  • Without fix: subsequent terraform plan shows the block being added
  • With fix: no diff on subsequent plans

Related

Release Notes

alloydb: fixed permadiff on `network_config` for `google_alloydb_instance` when `enable_public_ip` is set to `false`

BBBmau added 3 commits July 9, 2026 15:11
Trim the empty-block fallback to reconstruct only the two boolean
fields, drop redundant send_empty_value/default_from_api on the
booleans, and define the required child flatteners in the template
(previously undefined, which broke compilation).
Combine the separate nil and empty-map checks into a single comma-ok
type assertion.
@modular-magician

modular-magician commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit 0e0db27:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 1 file changed, 17 insertions(+), 6 deletions(-)
google-beta provider View Diff 2 files changed, 99 insertions(+), 6 deletions(-)
terraform-google-conversion View Diff 2 files changed, 18 insertions(+), 18 deletions(-)

Test report

Analytics

Total Tests Passed Skipped Affected
91 77 3 11
Affected Service Packages
  • alloydb

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 11 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit.

Click here to see the affected tests
  • TestAccAlloydbInstance_ObservabilityConfig_Update
  • TestAccAlloydbInstance_clientConnectionConfig
  • TestAccAlloydbInstance_connectionPoolConfig
  • TestAccAlloydbInstance_networkConfigNoPublicIpNoDiff
  • TestAccAlloydbInstance_secondaryInstanceUpdateDatabaseFlag
  • TestAccAlloydbInstance_secondaryInstanceUpdateMachineConfig
  • TestAccAlloydbInstance_secondaryInstanceUpdateQueryInsightConfig
  • TestAccAlloydbInstance_stopstart
  • TestAccAlloydbInstance_update
  • TestAccAlloydbInstance_updateInstanceWithPscInterfaceConfigs
  • TestAccAlloydbInstance_updatePscInstanceConfig

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
✅ Log TestAccAlloydbInstance_ObservabilityConfig_Update
✅ Log TestAccAlloydbInstance_clientConnectionConfig
✅ Log TestAccAlloydbInstance_connectionPoolConfig
✅ Log TestAccAlloydbInstance_networkConfigNoPublicIpNoDiff
✅ Log TestAccAlloydbInstance_secondaryInstanceUpdateDatabaseFlag
✅ Log TestAccAlloydbInstance_secondaryInstanceUpdateMachineConfig
✅ Log TestAccAlloydbInstance_secondaryInstanceUpdateQueryInsightConfig
✅ Log TestAccAlloydbInstance_stopstart
✅ Log TestAccAlloydbInstance_update
✅ Log TestAccAlloydbInstance_updateInstanceWithPscInterfaceConfigs
✅ Log TestAccAlloydbInstance_updatePscInstanceConfig

🟢 All tests passed!

View the recording VCR build log or the debug logs folder for detailed results.

@BBBmau VCR tests complete for 0e0db27!

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