From 16f8f8d59fa44295a87904f78ac4b98e50ff196c Mon Sep 17 00:00:00 2001 From: Vaishak Dinesh Date: Tue, 19 Nov 2024 08:45:34 -0800 Subject: [PATCH] feat: zone dns sec testdata and custom code --- internal/services/zone_dnssec/custom.go | 27 +++++++++++++++++++ internal/services/zone_dnssec/resource.go | 2 ++ .../testdata/zonednsdatasourceconfig.tf | 9 +++++++ .../testdata/zonednssecresourceconfig.tf | 2 +- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 internal/services/zone_dnssec/custom.go create mode 100644 internal/services/zone_dnssec/testdata/zonednsdatasourceconfig.tf diff --git a/internal/services/zone_dnssec/custom.go b/internal/services/zone_dnssec/custom.go new file mode 100644 index 0000000000..a99933365b --- /dev/null +++ b/internal/services/zone_dnssec/custom.go @@ -0,0 +1,27 @@ +package zone_dnssec + +import ( + "context" + + "github.com/cloudflare/cloudflare-go/v3" + "github.com/cloudflare/cloudflare-go/v3/dnssec" + "github.com/cloudflare/cloudflare-go/v3/option" + "github.com/cloudflare/terraform-provider-cloudflare/internal/logging" + "github.com/hashicorp/terraform-plugin-framework/resource" +) + +func disableDNSSECRecord(ctx context.Context, r *ZoneDNSSECResource, zoneID string, resp *resource.DeleteResponse) { + var err error + _, err = r.client.DNSSEC.Edit( + ctx, + dnssec.DNSSECEditParams{ + ZoneID: cloudflare.F(zoneID), + Status: cloudflare.F[dnssec.DNSSECEditParamsStatus](dnssec.DNSSECEditParamsStatusDisabled), + }, + option.WithMiddleware(logging.Middleware(ctx)), + ) + if err != nil { + resp.Diagnostics.AddError("failed to make http request", err.Error()) + return + } +} diff --git a/internal/services/zone_dnssec/resource.go b/internal/services/zone_dnssec/resource.go index b456264794..5f4d9a8399 100644 --- a/internal/services/zone_dnssec/resource.go +++ b/internal/services/zone_dnssec/resource.go @@ -188,6 +188,8 @@ func (r *ZoneDNSSECResource) Delete(ctx context.Context, req resource.DeleteRequ return } + disableDNSSECRecord(ctx, r, data.ZoneID.ValueString(), resp) + _, err := r.client.DNSSEC.Delete( ctx, dnssec.DNSSECDeleteParams{ diff --git a/internal/services/zone_dnssec/testdata/zonednsdatasourceconfig.tf b/internal/services/zone_dnssec/testdata/zonednsdatasourceconfig.tf new file mode 100644 index 0000000000..86fb012592 --- /dev/null +++ b/internal/services/zone_dnssec/testdata/zonednsdatasourceconfig.tf @@ -0,0 +1,9 @@ +resource "cloudflare_zone_dnssec" "%[1]s" { + zone_id = "%[2]s" + status = "active" +} + +data "cloudflare_zone_dnssec" "%[1]s" { + zone_id = "%[2]s" + depends_on = [ "cloudflare_dns_zone_dnssec.%[1]s" ] +} diff --git a/internal/services/zone_dnssec/testdata/zonednssecresourceconfig.tf b/internal/services/zone_dnssec/testdata/zonednssecresourceconfig.tf index 58503e8230..40bfb9eab7 100644 --- a/internal/services/zone_dnssec/testdata/zonednssecresourceconfig.tf +++ b/internal/services/zone_dnssec/testdata/zonednssecresourceconfig.tf @@ -1,4 +1,4 @@ - resource "cloudflare_zone_dnssec" "%s" { zone_id = "%s" + status = "active" } \ No newline at end of file