Fix terraform import fidelity: stop reverting, dropping, and rotating real state - #30
Open
Rupam-It wants to merge 4 commits into
Open
Fix terraform import fidelity: stop reverting, dropping, and rotating real state#30Rupam-It wants to merge 4 commits into
Rupam-It wants to merge 4 commits into
Conversation
Signed-off-by: Rupam-It <mannarupam3@gmail.com>
Signed-off-by: Rupam-It <mannarupam3@gmail.com>
Signed-off-by: Rupam-It <mannarupam3@gmail.com>
Signed-off-by: Rupam-It <mannarupam3@gmail.com>
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
Three separate bugs meant
terraform importdid not produce full-fidelitystate, violating the basic contract that import + plan should show no
changes and shouldn't mutate real infrastructure:
Systemic Default-clobbering (node_policy, node_policy_target,
workload_policy, workload_policy_target — ~81 attributes): the framework
re-applies an Optional+Computed attribute's
Defaulton every planwhenever config omits it, even when state already holds a real value.
Invisible for resources this provider creates itself, but it silently
reverted any imported (or externally set) value back to its default on
the very next apply. Added
preserve*StateOverDefaultplan modifiers andapplied them wherever
Defaultis used.Cluster token rotated on every apply after import (
devzero_cluster):tokenis write-once — onlyCreateClusterever returns it,GetClusternever does. A
ModifyPlanhook treated a null token in state assomething to auto-fix, forcing
Update(and a realResetClusterTokencall) on every single apply of an imported cluster — rotating a live
cluster's auth token as a side effect of having imported it. Removed the
hook; a null token is now just carried forward as-is.
Real nested-rule data dropped on read after import
(
devzero_workload_rule): a custompreserveNullsFromhelper nulled outcpu_rule/memory_rule/gpu_rule/hpa_rule/emergency_response/containers(and 4 scalar fields) inReadwhenever prior state hadthem null — always true immediately after import — wiping real backend
data on the first refresh. Removed it in favor of plain Optional+Computed,
paired with
UseStateForUnknownmodifiers to avoid a follow-on decodecrash when both config and prior state are null for these nested fields.
Also adds a CLI-level acceptance harness (
ProtoV6ProviderFactorieswiredto the existing in-memory fake backend) and import → clean-plan → edit →
reapply round-trip tests per affected resource, plus a regression test for
an already-fixed
node_policybug (azure.image_version-only blocksgetting dropped as "empty" on read).
Test plan
go build ./...go test ./...TF_ACC=1 go test ./...— includes new import round-trip tests fornode_policy,devzero_cluster, anddevzero_workload_rule(import → clean plan → edit an attribute → reapply → verify against
backend)
terraform importagainst a real DevZero backend (not runthis session — recommended before merge)