fix(zonerrset): make SOA records settable via update-on-create (#1289)#1469
fix(zonerrset): make SOA records settable via update-on-create (#1289)#1469nikolauspschuetz wants to merge 1 commit into
Conversation
4ca1cb6 to
f801998
Compare
|
Hey, before going any further, please have a quick look at our contributing guideline, in particular the AI/LLM policy: https://github.com/hetznercloud/terraform-provider-hcloud?tab=contributing-ov-file#ai--llm-policy I suspect this PR was created with the assistance of an AI tool, but this was not disclosed. |
|
You're right, and apologies for the omission — I've updated the PR description with an AI/LLM disclosure per the policy. To be explicit on accountability: I hit and reproduced the |
|
See my answer to your question in the related issue. |
…ercloud#1289) SOA RRSets are created by the API together with the parent Zone, so they cannot be created a second time. Previously Create only imported the existing SOA RRSet and ignored the configured records, so applying a SOA RRSet whose records differed from the API-assigned values failed with "Provider produced inconsistent result after apply". Create now updates the pre-existing SOA RRSet with the user-provided records (via SetRRSetRecords), so the SOA record can be managed through this resource in a single apply. The SERIAL field is normalized to 0 in the state (as before) and must be set to 0 in the configuration, keeping plan and apply consistent. Closes hetznercloud#1289
f801998 to
064504e
Compare
|
Thanks for the steer, @jooola — you're right that option 1 threw away the ability to manage the SOA record, which we want to keep. I've reworked this to the settable update-on-create approach you described:
The acceptance test Disclosure: drafted with AI assistance (Claude Code); I've reviewed and verified the change and can defend it in review. |
|
Verified the settable update-on-create rework end-to-end against the live Hetzner API. The acceptance test ( I ran it through the project's own Passing run: https://github.com/nikolauspschuetz/terraform-provider-hcloud/actions/runs/28606982956 (Running the Disclosure: developed with AI assistance (Claude Code); I reproduced the issue, validated the diagnosis, ran the verification above, and reviewed every line. |
Problem
For
type = "SOA"RRSets, the RRSet is created by the Hetzner Cloud API together with the parent Zone, so it cannot be created a second time. Previously theCreatemethod only imported the existing SOA RRSet and ignored the configuredrecords. Applying a SOA RRSet whose configured records differed from the values the API assigned to the Zone therefore failed with:because the planned
records(the user's config) never matched the value read back from the API. This is #1289.Fix (settable, update-on-create)
Following @jooola's steer on #1289 — "the Create method for the resource must be able to update the existing SOA record with the user provided value, without having to rely on a 2 steps process" — SOA
recordsstay a normal settable attribute, andCreatenow:GetRRSetByNameAndType) to obtain its ID.SetRRSetRecords— so the SOA record is managed through this resource in a single apply, no 2-step process.SERIAL normalization: the API auto-increments the SOA
SERIALfield, so it can never be predicted from config. As @jooola noted, the provider normalizesSERIALto0in state (OverrideRecordsSOASerial, unchanged) — and the user is required to setSERIALto0in their configuration. With both sides pinned to0, plan and apply stay consistent and there is no perpetual diff. This is documented on the resource.Net effect: applying a SOA RRSet with non-default records succeeds in one apply, and subsequent plans are empty — the #1289 symptom is gone.
Changes
internal/zonerrset/resource.go—Createperforms update-on-create for SOA (SetRRSetRecordsagainst the existing RRSet); dropped the "records are imported/ignored" warning since records are now applied; added areturnafter the not-found diagnostic (the code path previously fell through to a nil deref).internal/zonerrset/resource_test.go—TestAccZoneRRSetResource_SOAnow asserts the settable behaviour: applying user-provided SOA records (that differ from the API defaults) succeeds and the state reflects the configured value, changing them applies, and re-plans are empty.docs/resources/zone_rrset.md— regenerated viamake generate; documents update-on-create and theSERIAL = 0requirement.Testing
go build ./...,go vet ./...,gofmt -l— clean.TestOverrideRecordsSOASerial,TestModel,TestTXTRecordFunction).TestAccZoneRRSetResource_SOAhas NOT been run — it needsTF_ACC=1+ a liveHCLOUD_TOKENand hits the real Hetzner DNS API (creates/destroys a real Zone). I've verified it compiles and the plan-consistency reasoning, but it needs a CI run or a maintainer/token run to confirm the API round-trips the configured SOA value exactly.Closes #1289
AI assistance
Disclosing per the AI / LLM policy (thanks for the pointer, @jooola): this PR was developed with AI assistance — Claude Code (Anthropic). I reviewed and verified every line, take responsibility for the change, and can explain/defend it in review. This is my only open AI-assisted PR on this repo.