From 6c805e6401a109fc128d9c2cba63018334db3ff6 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Tue, 5 Apr 2022 17:34:05 +0200 Subject: [PATCH] domain: only set nameservers when livedns is not enabled When importing a domain resource, we don't want to import nameservers if livedns is enabled on this domain: livedns manages the nameservers and they can be updated by Gandi without any user intervention. --- gandi/resource_domain.go | 15 +++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gandi/resource_domain.go b/gandi/resource_domain.go index 8c73c0e8..422f4484 100644 --- a/gandi/resource_domain.go +++ b/gandi/resource_domain.go @@ -180,8 +180,19 @@ func resourceDomainRead(d *schema.ResourceData, meta interface{}) error { if err = d.Set("name", response.FQDN); err != nil { return fmt.Errorf("failed to set name for %s: %w", d.Id(), err) } - if err = d.Set("nameservers", response.Nameservers); err != nil { - return fmt.Errorf("failed to set nameservers for %s: %w", d.Id(), err) + + // Nameservers are only set when livedns is not used. When + // livedns is used, this nameservers list is managed by Gandi: + // the user should not have to care about them. + livedns, err := client.GetLiveDNS(fqdn) + if err != nil { + d.SetId("") + return err + } + if livedns.Current != "livedns" { + if err = d.Set("nameservers", response.Nameservers); err != nil { + return fmt.Errorf("failed to set nameservers for %s: %w", d.Id(), err) + } } if err = d.Set("autorenew", response.AutoRenew.Enabled); err != nil { return fmt.Errorf("failed to set autorenew for %s: %w", d.Id(), err) diff --git a/go.mod b/go.mod index d9775c05..d5ef10dd 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/fatih/color v1.9.0 // indirect - github.com/go-gandi/go-gandi v0.3.0 + github.com/go-gandi/go-gandi v0.4.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1 github.com/hashicorp/yamux v0.0.0-20190923154419-df201c70410d // indirect github.com/oklog/run v1.1.0 // indirect diff --git a/go.sum b/go.sum index 85c201e8..85ce4fd9 100644 --- a/go.sum +++ b/go.sum @@ -89,8 +89,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= -github.com/go-gandi/go-gandi v0.3.0 h1:57hWAcN5QiMXcFFF3iV09s4Ny7RGQoMPaHVmstHwx58= -github.com/go-gandi/go-gandi v0.3.0/go.mod h1:9NoYyfWCjFosClPiWjkbbRK5UViaZ4ctpT8/pKSSFlw= +github.com/go-gandi/go-gandi v0.4.0 h1:iFVD+x3nJrI611fYvVMk6TKOlUOND/bKnvdQxuZKPSI= +github.com/go-gandi/go-gandi v0.4.0/go.mod h1:9NoYyfWCjFosClPiWjkbbRK5UViaZ4ctpT8/pKSSFlw= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=