You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,6 +193,8 @@ Example:
193
193
194
194
Terraform state reflects what the user cares about, not the entire API response.
195
195
196
+
For generated XML -> model conversions, see `internal/codegen/README.md`, especially the "Preserve User Intent For Optional Nested Objects" section. That generator-level rule is authoritative for optional nested object readback behavior.
197
+
196
198
**Computed** (not Optional) - Always read from API
Copy file name to clipboardExpand all lines: internal/codegen/README.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,6 +63,26 @@ The generator has two separate responsibilities:
63
63
64
64
Keep those layers separate. The parser should not accumulate ad hoc Terraform exceptions based on struct names. If a field needs special Terraform behavior, prefer a policy rule after reflection rather than embedding one-off conditionals into the reflector.
65
65
66
+
### Preserve User Intent For Optional Nested Objects
67
+
68
+
`Preserve user intent` is a generator-level contract, not a resource-by-resource preference.
69
+
70
+
For optional nested objects, XML omission and user omission are not the same thing:
71
+
72
+
- If the user did not configure an optional nested object, state should keep it `null`.
73
+
- If the user configured an optional nested object and libvirt omits that object when reading XML back, the conversion should preserve the planned object unless we have an explicit policy that omission means the field was cleared.
74
+
- Do not silently collapse an explicitly configured nested object to `null` only because the readback XML does not echo it.
75
+
76
+
This rule exists to prevent Terraform `Provider produced inconsistent result after apply` errors for fields such as `alias`, where libvirt may not round-trip the object exactly even though the user configured it explicitly.
77
+
78
+
In practice, this means the XML -> model conversion for optional nested objects must distinguish:
79
+
80
+
-`plan field is null`: user does not care, keep state `null`
81
+
-`plan field is non-null` and `xml field is present`: convert XML back into state
82
+
-`plan field is non-null` and `xml field is absent`: preserve the planned value unless an explicit override says otherwise
83
+
84
+
When changing converter templates, treat this as an invariant that applies uniformly across generated nested object fields. Do not patch individual resources to compensate for generator behavior unless the field truly needs special semantics.
85
+
66
86
### Policy rules
67
87
68
88
Policy should be applied in an ordered pass over `StructIR` / `FieldIR`:
0 commit comments