Skip to content

resource/alicloud_gpdb_instance: backfill parameters on terraform import - #10155

Open
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:worktree-85189348-gpdb-import-params
Open

resource/alicloud_gpdb_instance: backfill parameters on terraform import#10155
api-tool-agent wants to merge 1 commit into
aliyun:masterfrom
api-tool-agent:worktree-85189348-gpdb-import-params

Conversation

@api-tool-agent

Copy link
Copy Markdown
Collaborator

Summary

alicloud_gpdb_instance.parameters was not backfilled into state after terraform import, so the imported state never reflected the server-side parameters of the instance.

Root cause

The Read function refreshed parameters only inside a guard if documented, ok := d.GetOk("parameters"); ok. terraform import uses ImportStatePassthrough, which seeds state with only the instance id, so d.GetOk("parameters") was false on import and the entire DescribeParameters block was skipped.

The guard was intentional for ordinary refresh: DescribeParameters returns the full server-side parameter set, while the configuration typically declares only a subset. Writing the full set back into state in that case surfaces the extra parameters as removed elements on every plan, producing a permanent non-empty plan.

Fix

Lift DescribeParameters out of the guard and split refresh into two branches:

  • Configuration declares a subset of parameters — only those declared parameters are refreshed, using their current server-side values. This preserves the existing behavior that avoids a permanent diff from the extra server-side parameters.
  • No parameters declared in the configuration (e.g. right after terraform import) — the full server-side parameter set is written back into state so the imported state reflects the real instance. Because parameters is Optional + Computed, a configuration that omits it keeps the server-side value without producing a plan; a subsequent configuration that declares a subset is reconciled by the following plan/apply.

Testing

Added TestAccAliCloudGPDBDBInstance_importBackfillsParameters: creates an instance without declaring any parameters, imports it, and asserts parameters.# is non-empty after import (previously the imported state had an empty parameters set).

DescribeParameters refresh was guarded by d.GetOk("parameters"), which is
false on `terraform import` because ImportStatePassthrough seeds state with
only the instance id, so the whole parameters block was skipped and the
imported state never reflected the server-side parameters.

Lift DescribeParameters out of the guard and split refresh into two branches:
- when the configuration declares a subset of parameters, only those declared
  parameters are refreshed with their current server-side values, preserving
  the existing behavior that avoids a permanent diff from the extra
  server-side parameters;
- when no parameters are declared in the configuration (e.g. right after
  import), the full server-side parameter set is written back into state so
  the imported state reflects the real instance. Because `parameters` is
  Optional+Computed, a configuration that omits it keeps the server-side
  value without producing a plan.

Add a regression acceptance test that creates an instance without declaring
parameters, imports it, and asserts parameters.# is non-empty.
@api-tool-agent
api-tool-agent force-pushed the worktree-85189348-gpdb-import-params branch from 57094c2 to 82b5522 Compare August 7, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant