Skip to content

Commit 0c4f7b9

Browse files
allow google_dns_managed_zone.dnssec_config to be updated (#3313) (#1914)
* allow update for dns_managed_zone * add some input trues back in * add some input trues back in Signed-off-by: Modular Magician <[email protected]>
1 parent fdd3ca8 commit 0c4f7b9

File tree

4 files changed

+93
-64
lines changed

4 files changed

+93
-64
lines changed

.changelog/3313.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
dns: added ability to update `google_dns_managed_zone.dnssec_config`
3+
```

google-beta/resource_dns_managed_zone.go

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ Must be unique within the project.`,
6767
"dnssec_config": {
6868
Type: schema.TypeList,
6969
Optional: true,
70-
ForceNew: true,
7170
Description: `DNSSEC configuration`,
7271
MaxItems: 1,
7372
Elem: &schema.Resource{
@@ -76,29 +75,26 @@ Must be unique within the project.`,
7675
Type: schema.TypeList,
7776
Computed: true,
7877
Optional: true,
79-
ForceNew: true,
8078
Description: `Specifies parameters that will be used for generating initial DnsKeys
8179
for this ManagedZone. If you provide a spec for keySigning or zoneSigning,
82-
you must also provide one for the other.`,
80+
you must also provide one for the other.
81+
default_key_specs can only be updated when the state is 'off'.`,
8382
Elem: &schema.Resource{
8483
Schema: map[string]*schema.Schema{
8584
"algorithm": {
8685
Type: schema.TypeString,
8786
Optional: true,
88-
ForceNew: true,
8987
ValidateFunc: validation.StringInSlice([]string{"ecdsap256sha256", "ecdsap384sha384", "rsasha1", "rsasha256", "rsasha512", ""}, false),
9088
Description: `String mnemonic specifying the DNSSEC algorithm of this key`,
9189
},
9290
"key_length": {
9391
Type: schema.TypeInt,
9492
Optional: true,
95-
ForceNew: true,
9693
Description: `Length of the keys in bits`,
9794
},
9895
"key_type": {
9996
Type: schema.TypeString,
10097
Optional: true,
101-
ForceNew: true,
10298
ValidateFunc: validation.StringInSlice([]string{"keySigning", "zoneSigning", ""}, false),
10399
Description: `Specifies whether this is a key signing key (KSK) or a zone
104100
signing key (ZSK). Key signing keys have the Secure Entry
@@ -110,7 +106,6 @@ to sign all other types of resource record sets.`,
110106
"kind": {
111107
Type: schema.TypeString,
112108
Optional: true,
113-
ForceNew: true,
114109
Description: `Identifies what kind of resource this is`,
115110
Default: "dns#dnsKeySpec",
116111
},
@@ -121,7 +116,6 @@ to sign all other types of resource record sets.`,
121116
"kind": {
122117
Type: schema.TypeString,
123118
Optional: true,
124-
ForceNew: true,
125119
Description: `Identifies what kind of resource this is`,
126120
Default: "dns#managedZoneDnsSecConfig",
127121
AtLeastOneOf: []string{"dnssec_config.0.kind", "dnssec_config.0.non_existence", "dnssec_config.0.state", "dnssec_config.0.default_key_specs"},
@@ -130,15 +124,14 @@ to sign all other types of resource record sets.`,
130124
Type: schema.TypeString,
131125
Computed: true,
132126
Optional: true,
133-
ForceNew: true,
134127
ValidateFunc: validation.StringInSlice([]string{"nsec", "nsec3", ""}, false),
135-
Description: `Specifies the mechanism used to provide authenticated denial-of-existence responses.`,
128+
Description: `Specifies the mechanism used to provide authenticated denial-of-existence responses.
129+
non_existence can only be updated when the state is 'off'.`,
136130
AtLeastOneOf: []string{"dnssec_config.0.kind", "dnssec_config.0.non_existence", "dnssec_config.0.state", "dnssec_config.0.default_key_specs"},
137131
},
138132
"state": {
139133
Type: schema.TypeString,
140134
Optional: true,
141-
ForceNew: true,
142135
ValidateFunc: validation.StringInSlice([]string{"off", "on", "transfer", ""}, false),
143136
Description: `Specifies whether DNSSEC is enabled, and what mode it is in`,
144137
AtLeastOneOf: []string{"dnssec_config.0.kind", "dnssec_config.0.non_existence", "dnssec_config.0.state", "dnssec_config.0.default_key_specs"},
@@ -473,60 +466,56 @@ func resourceDNSManagedZoneUpdate(d *schema.ResourceData, meta interface{}) erro
473466
return err
474467
}
475468

476-
d.Partial(true)
477-
478-
if d.HasChange("description") || d.HasChange("labels") || d.HasChange("private_visibility_config") || d.HasChange("forwarding_config") || d.HasChange("peering_config") {
479-
obj := make(map[string]interface{})
469+
obj := make(map[string]interface{})
470+
descriptionProp, err := expandDNSManagedZoneDescription(d.Get("description"), d, config)
471+
if err != nil {
472+
return err
473+
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
474+
obj["description"] = descriptionProp
475+
}
476+
dnssecConfigProp, err := expandDNSManagedZoneDnssecConfig(d.Get("dnssec_config"), d, config)
477+
if err != nil {
478+
return err
479+
} else if v, ok := d.GetOkExists("dnssec_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, dnssecConfigProp)) {
480+
obj["dnssecConfig"] = dnssecConfigProp
481+
}
482+
labelsProp, err := expandDNSManagedZoneLabels(d.Get("labels"), d, config)
483+
if err != nil {
484+
return err
485+
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
486+
obj["labels"] = labelsProp
487+
}
488+
privateVisibilityConfigProp, err := expandDNSManagedZonePrivateVisibilityConfig(d.Get("private_visibility_config"), d, config)
489+
if err != nil {
490+
return err
491+
} else if v, ok := d.GetOkExists("private_visibility_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, privateVisibilityConfigProp)) {
492+
obj["privateVisibilityConfig"] = privateVisibilityConfigProp
493+
}
494+
forwardingConfigProp, err := expandDNSManagedZoneForwardingConfig(d.Get("forwarding_config"), d, config)
495+
if err != nil {
496+
return err
497+
} else if v, ok := d.GetOkExists("forwarding_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, forwardingConfigProp)) {
498+
obj["forwardingConfig"] = forwardingConfigProp
499+
}
500+
peeringConfigProp, err := expandDNSManagedZonePeeringConfig(d.Get("peering_config"), d, config)
501+
if err != nil {
502+
return err
503+
} else if v, ok := d.GetOkExists("peering_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, peeringConfigProp)) {
504+
obj["peeringConfig"] = peeringConfigProp
505+
}
480506

481-
descriptionProp, err := expandDNSManagedZoneDescription(d.Get("description"), d, config)
482-
if err != nil {
483-
return err
484-
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
485-
obj["description"] = descriptionProp
486-
}
487-
labelsProp, err := expandDNSManagedZoneLabels(d.Get("labels"), d, config)
488-
if err != nil {
489-
return err
490-
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
491-
obj["labels"] = labelsProp
492-
}
493-
privateVisibilityConfigProp, err := expandDNSManagedZonePrivateVisibilityConfig(d.Get("private_visibility_config"), d, config)
494-
if err != nil {
495-
return err
496-
} else if v, ok := d.GetOkExists("private_visibility_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, privateVisibilityConfigProp)) {
497-
obj["privateVisibilityConfig"] = privateVisibilityConfigProp
498-
}
499-
forwardingConfigProp, err := expandDNSManagedZoneForwardingConfig(d.Get("forwarding_config"), d, config)
500-
if err != nil {
501-
return err
502-
} else if v, ok := d.GetOkExists("forwarding_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, forwardingConfigProp)) {
503-
obj["forwardingConfig"] = forwardingConfigProp
504-
}
505-
peeringConfigProp, err := expandDNSManagedZonePeeringConfig(d.Get("peering_config"), d, config)
506-
if err != nil {
507-
return err
508-
} else if v, ok := d.GetOkExists("peering_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, peeringConfigProp)) {
509-
obj["peeringConfig"] = peeringConfigProp
510-
}
507+
url, err := replaceVars(d, config, "{{DNSBasePath}}projects/{{project}}/managedZones/{{name}}")
508+
if err != nil {
509+
return err
510+
}
511511

512-
url, err := replaceVars(d, config, "{{DNSBasePath}}projects/{{project}}/managedZones/{{name}}")
513-
if err != nil {
514-
return err
515-
}
516-
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
517-
if err != nil {
518-
return fmt.Errorf("Error updating ManagedZone %q: %s", d.Id(), err)
519-
}
512+
log.Printf("[DEBUG] Updating ManagedZone %q: %#v", d.Id(), obj)
513+
_, err = sendRequestWithTimeout(config, "PATCH", project, url, obj, d.Timeout(schema.TimeoutUpdate))
520514

521-
d.SetPartial("description")
522-
d.SetPartial("labels")
523-
d.SetPartial("private_visibility_config")
524-
d.SetPartial("forwarding_config")
525-
d.SetPartial("peering_config")
515+
if err != nil {
516+
return fmt.Errorf("Error updating ManagedZone %q: %s", d.Id(), err)
526517
}
527518

528-
d.Partial(false)
529-
530519
return resourceDNSManagedZoneRead(d, meta)
531520
}
532521

google-beta/resource_dns_managed_zone_test.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestAccDNSManagedZone_privateUpdate(t *testing.T) {
6868
})
6969
}
7070

71-
func TestAccDNSManagedZone_dnssec_on(t *testing.T) {
71+
func TestAccDNSManagedZone_dnssec_update(t *testing.T) {
7272
t.Parallel()
7373

7474
zoneSuffix := acctest.RandString(10)
@@ -86,11 +86,19 @@ func TestAccDNSManagedZone_dnssec_on(t *testing.T) {
8686
ImportState: true,
8787
ImportStateVerify: true,
8888
},
89+
{
90+
Config: testAccDnsManagedZone_dnssec_off(zoneSuffix),
91+
},
92+
{
93+
ResourceName: "google_dns_managed_zone.foobar",
94+
ImportState: true,
95+
ImportStateVerify: true,
96+
},
8997
},
9098
})
9199
}
92100

93-
func TestAccDNSManagedZone_dnssec_off(t *testing.T) {
101+
func TestAccDNSManagedZone_dnssec_empty(t *testing.T) {
94102
t.Parallel()
95103

96104
zoneSuffix := acctest.RandString(10)
@@ -101,7 +109,7 @@ func TestAccDNSManagedZone_dnssec_off(t *testing.T) {
101109
CheckDestroy: testAccCheckDNSManagedZoneDestroy,
102110
Steps: []resource.TestStep{
103111
{
104-
Config: testAccDnsManagedZone_dnssec_off(zoneSuffix),
112+
Config: testAccDnsManagedZone_dnssec_empty(zoneSuffix),
105113
},
106114
{
107115
ResourceName: "google_dns_managed_zone.foobar",
@@ -197,6 +205,8 @@ resource "google_dns_managed_zone" "foobar" {
197205
key_length = "2048"
198206
key_type = "keySigning"
199207
}
208+
209+
non_existence = "nsec"
200210
}
201211
}
202212
`, suffix, suffix)
@@ -208,6 +218,31 @@ resource "google_dns_managed_zone" "foobar" {
208218
name = "mzone-test-%s"
209219
dns_name = "tf-acctest-%s.hashicorptest.com."
210220
221+
dnssec_config {
222+
state = "off"
223+
default_key_specs {
224+
algorithm = "rsasha256"
225+
key_length = "2048"
226+
key_type = "zoneSigning"
227+
}
228+
default_key_specs {
229+
algorithm = "rsasha256"
230+
key_length = "2048"
231+
key_type = "keySigning"
232+
}
233+
234+
non_existence = "nsec3"
235+
}
236+
}
237+
`, suffix, suffix)
238+
}
239+
240+
func testAccDnsManagedZone_dnssec_empty(suffix string) string {
241+
return fmt.Sprintf(`
242+
resource "google_dns_managed_zone" "foobar" {
243+
name = "mzone-test-%s"
244+
dns_name = "tf-acctest-%s.hashicorptest.com."
245+
211246
dnssec_config {
212247
state = "off"
213248
}

website/docs/r/dns_managed_zone.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ The `dnssec_config` block supports:
261261
* `non_existence` -
262262
(Optional)
263263
Specifies the mechanism used to provide authenticated denial-of-existence responses.
264+
non_existence can only be updated when the state is `off`.
264265

265266
* `state` -
266267
(Optional)
@@ -270,7 +271,8 @@ The `dnssec_config` block supports:
270271
(Optional)
271272
Specifies parameters that will be used for generating initial DnsKeys
272273
for this ManagedZone. If you provide a spec for keySigning or zoneSigning,
273-
you must also provide one for the other. Structure is documented below.
274+
you must also provide one for the other.
275+
default_key_specs can only be updated when the state is `off`. Structure is documented below.
274276

275277

276278
The `default_key_specs` block supports:

0 commit comments

Comments
 (0)