resource/alicloud_gpdb_instance: backfill parameters on terraform import - #10155
Open
api-tool-agent wants to merge 1 commit into
Open
resource/alicloud_gpdb_instance: backfill parameters on terraform import#10155api-tool-agent wants to merge 1 commit into
api-tool-agent wants to merge 1 commit into
Conversation
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
force-pushed
the
worktree-85189348-gpdb-import-params
branch
from
August 7, 2026 07:58
57094c2 to
82b5522
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
alicloud_gpdb_instance.parameterswas not backfilled into state afterterraform import, so the imported state never reflected the server-side parameters of the instance.Root cause
The Read function refreshed
parametersonly inside a guardif documented, ok := d.GetOk("parameters"); ok.terraform importusesImportStatePassthrough, which seeds state with only the instance id, sod.GetOk("parameters")was false on import and the entireDescribeParametersblock was skipped.The guard was intentional for ordinary refresh:
DescribeParametersreturns 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
DescribeParametersout of the guard and split refresh into two branches:terraform import) — the full server-side parameter set is written back into state so the imported state reflects the real instance. BecauseparametersisOptional+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 anyparameters, imports it, and assertsparameters.#is non-empty after import (previously the imported state had an emptyparametersset).