Repository navigation
fix(terraform): compute ignore_changes paths in the Terraform schema shape - #806
fabioaraujopt wants to merge 1 commit into
Conversation
…shape NewFileProducer computed the lifecycle ignore_changes paths for initProvider-only fields from spec.forProvider and spec.initProvider as the reconciled CRD version serves them. When that version serves a Terraform singleton list as an embedded object, a field of it came out as block["field"], which does not address the list block's element in Terraform, so the field was not ignored. The correct path is block[0].field. Compute the paths on copies of both parameter sets with the Terraform conversions applied, as crossplane#728 did for the Terraform plugin SDK client and initProviderOnlyPaths does for the plugin framework client. The copies are needed because ApplyTFConversions converts in place and the caller still merges and converts the original maps. Also add a regression test for filterInitExclusiveDiffs (crossplane#728 shipped without one), driven by the SDK's own diff for the failover case of crossplane-contrib/provider-upjet-azure#1303. Signed-off-by: Fabio Araujo <fabioaraujoorg@gmail.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Description of your changes
#728 fixed
filterInitExclusiveDiffsfor CRD versions that serve a Terraform singleton list as an embedded object.initProviderOnlyPathsalready handles the same case for the plugin framework client. The CLI-based client still has the bug.NewFileProducerbuilds thelifecycle.ignore_changeslist fromspec.forProviderandspec.initProviderin the shape the CRD serves them. For an initProvider-only field inside such a block, it emitsblock["field"]. That path doesn't address the list block's element in Terraform, so the field isn't ignored. The correct path isblock[0].field.This PR computes the paths on copies of both parameter sets with
ApplyTFConversions(_, config.ToTerraform)applied, so the paths follow the Terraform schema like the other two clients.Why copies:
ApplyTFConversionsconverts in place, andNewFileProducerstill merges and converts the original maps afterwards.ToSingletonListisn't idempotent, so converting the originals early would wrap the block twice. The copy is ajson.TFParserround trip, which is how generatedGetParametersbuilds these maps.The PR also adds
TestFilterInitExclusiveDiffs, because #728 shipped without a test. The test drivesfilterInitExclusiveDiffswith the SDK's ownInstanceDiff, not a hand-written one, so it checks the real attribute key format (high_availability.0.standby_availability_zone). The scenario is theazurerm_postgresql_flexible_serverfailover from crossplane-contrib/provider-upjet-azure#1303: both zones are set only ininitProvider, and Azure swaps them. The cases cover:With #728's two
ApplyTFConversionscalls removed, all three cases fail onhigh_availability.0.standby_availability_zone. They also pass at 7b0ca4f, the upjet commit provider-upjet-azure v2.8.0 ships, so #1303 is fixed from v2.8.0.Not changed here: an initProvider path that indexes into a
TypeSetstill can't match. SDK diff keys for set elements are hash codes, not positions. The plugin framework client skips such paths withindexesIntoSet.I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
TestWriteMainTF/SuccessManagementPoliciesSingletonListConversion: fails onmainwithblock["standby_zone"]and passes with the fix (block[0].standby_zone).TestFilterInitExclusiveDiffs: passes onmain. It fails with fix: apply TF conversions before filtering initProvider-exclusive diffs #728's conversion removed, which confirms it covers fix: apply TF conversions before filtering initProvider-exclusive diffs #728.go test ./pkg/... -count=1passes, andgo vetis clean.golangci-lint run ./pkg/terraform/... ./pkg/controller/...with the pinned v2.13.2 reports 0 issues.make reviewablewas not run, because I don't have the build submodule set up locally.