@@ -95,31 +95,22 @@ func resourceDnsRecordSetCreate(d *schema.ResourceData, meta interface{}) error
95
95
},
96
96
}
97
97
98
- // we need to replace NS record sets in the same call. That means
99
- // we need to list all the current NS record sets attached to the
100
- // zone and add them to the change as deletions. We can't just add
101
- // new NS record sets, or we'll get an error about the NS record set
102
- // already existing; see terraform-providers/terraform-provider-google#95.
103
- // We also can't just remove the NS recordsets on creation, as at
104
- // least one is required. So the solution is to "update in place" by
105
- // putting the addition and the removal in the same API call.
106
- if rType == "NS" {
107
- log .Printf ("[DEBUG] DNS record list request for %q" , zone )
108
- res , err := config .clientDns .ResourceRecordSets .List (project , zone ).Do ()
109
- if err != nil {
110
- return fmt .Errorf ("Error retrieving record sets for %q: %s" , zone , err )
111
- }
112
- var deletions []* dns.ResourceRecordSet
98
+ // Detect any existing records
99
+ log .Printf ("[DEBUG] DNS record list request for %q" , zone )
100
+ res , err := config .clientDns .ResourceRecordSets .List (project , zone ).Do ()
101
+ if err != nil {
102
+ return fmt .Errorf ("Error retrieving record sets for %q: %s" , zone , err )
103
+ }
104
+ var deletions []* dns.ResourceRecordSet
113
105
114
- for _ , record := range res .Rrsets {
115
- if record .Type != "NS" || record .Name != name {
116
- continue
117
- }
118
- deletions = append (deletions , record )
119
- }
120
- if len (deletions ) > 0 {
121
- chg .Deletions = deletions
106
+ for _ , record := range res .Rrsets {
107
+ if record .Type != rType || record .Name != name {
108
+ continue
122
109
}
110
+ deletions = append (deletions , record )
111
+ }
112
+ if len (deletions ) > 0 {
113
+ chg .Deletions = deletions
123
114
}
124
115
125
116
log .Printf ("[DEBUG] DNS Record create request: %#v" , chg )
0 commit comments