Skip to content

Commit

Permalink
domain: only set nameservers when livedns is not enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nlewo committed Apr 15, 2022
1 parent 50f6a14 commit 6c805e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions gandi/resource_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 6c805e6

Please sign in to comment.