Remove existing records in gcloud (#308)
When record already exists in gcloud we can't add a new record without removing the other one first. This is a simple fix that doesn't attempt to create multiple entries for the record but just removes the previous data. fixes #218
This commit is contained in:
parent
85200a157c
commit
501b7b6e0f
2 changed files with 24 additions and 0 deletions
|
@ -68,6 +68,16 @@ func (c *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||
Additions: []*dns.ResourceRecordSet{rec},
|
||||
}
|
||||
|
||||
// Look for existing records.
|
||||
list, err := c.client.ResourceRecordSets.List(c.project, zone).Name(fqdn).Type("TXT").Do()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(list.Rrsets) > 0 {
|
||||
// Attempt to delete the existing records when adding our new one.
|
||||
change.Deletions = list.Rrsets
|
||||
}
|
||||
|
||||
chg, err := c.client.Changes.Create(c.project, zone, change).Do()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -70,6 +70,20 @@ func TestLiveGoogleCloudPresent(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLiveGoogleCloudPresentMultiple(t *testing.T) {
|
||||
if !gcloudLiveTest {
|
||||
t.Skip("skipping live test")
|
||||
}
|
||||
|
||||
provider, err := NewDNSProviderCredentials(gcloudProject)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Check that we're able to create multiple entries
|
||||
err = provider.Present(gcloudDomain, "1", "123d==")
|
||||
err = provider.Present(gcloudDomain, "2", "123d==")
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestLiveGoogleCloudCleanUp(t *testing.T) {
|
||||
if !gcloudLiveTest {
|
||||
t.Skip("skipping live test")
|
||||
|
|
Loading…
Reference in a new issue