Skip to content

Commit c74d7d2

Browse files
committed
Add labels functionality to managed DNS
1 parent 62cee9b commit c74d7d2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

google/resource_dns_managed_zone.go

+16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ func resourceDnsManagedZone() *schema.Resource {
5353
Computed: true,
5454
ForceNew: true,
5555
},
56+
57+
"labels": &schema.Schema{
58+
Type: schema.TypeMap,
59+
Optional: true,
60+
Elem: &schema.Schema{Type: schema.TypeString},
61+
},
5662
},
5763
}
5864
}
@@ -72,7 +78,12 @@ func resourceDnsManagedZoneCreate(d *schema.ResourceData, meta interface{}) erro
7278
Description: d.Get("description").(string),
7379
}
7480

81+
if _, ok := d.GetOk("labels"); ok {
82+
zone.Labels = expandLabels(d)
83+
}
84+
7585
log.Printf("[DEBUG] DNS ManagedZone create request: %#v", zone)
86+
7687
zone, err = config.clientDns.ManagedZones.Create(project, zone).Do()
7788
if err != nil {
7889
return fmt.Errorf("Error creating DNS ManagedZone: %s", err)
@@ -102,6 +113,7 @@ func resourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error
102113
d.Set("dns_name", zone.DnsName)
103114
d.Set("description", zone.Description)
104115
d.Set("project", project)
116+
d.Set("labels", zone.Labels)
105117

106118
return nil
107119
}
@@ -120,6 +132,10 @@ func resourceDnsManagedZoneUpdate(d *schema.ResourceData, meta interface{}) erro
120132
Description: d.Get("description").(string),
121133
}
122134

135+
if _, ok := d.GetOk("labels"); ok {
136+
zone.Labels = expandLabels(d)
137+
}
138+
123139
op, err := config.clientDnsBeta.ManagedZones.Patch(project, d.Id(), zone).Do()
124140
if err != nil {
125141
return err

google/resource_dns_managed_zone_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,8 @@ resource "google_dns_managed_zone" "foobar" {
8585
name = "mzone-test-%s"
8686
dns_name = "tf-acctest-%s.hashicorptest.com."
8787
description = "%s"
88+
labels = {
89+
foo = "bar"
90+
}
8891
}`, suffix, suffix, description)
8992
}

website/docs/r/dns_managed_zone.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ resource "google_dns_managed_zone" "prod" {
1818
name = "prod-zone"
1919
dns_name = "prod.mydomain.com."
2020
description = "Production DNS zone"
21+
22+
labels = {
23+
foo = "bar"
24+
}
2125
}
2226
```
2327

@@ -37,6 +41,8 @@ The following arguments are supported:
3741
* `project` - (Optional) The ID of the project in which the resource belongs. If it
3842
is not provided, the provider project is used.
3943

44+
* `labels` - (Optional) A set of key/value label pairs to assign to the instance.
45+
4046
## Attributes Reference
4147

4248
In addition to the arguments listed above, the following computed attributes are

0 commit comments

Comments
 (0)