Skip to content

Commit ac7606e

Browse files
committed
zone tags
1 parent 84a8d7a commit ac7606e

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

ns1/data_source_zone.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ func dataSourceZone() *schema.Resource {
9999
Type: schema.TypeBool,
100100
Computed: true,
101101
},
102+
"tags": {
103+
Type: schema.TypeMap,
104+
Computed: true,
105+
},
102106
},
103107
Read: zoneRead,
104108
}

ns1/resource_record_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func TestAccRecord_updated(t *testing.T) {
9090
testAccCheckRecordAnswerRdata(
9191
t, &record, 0, []string{fmt.Sprintf("test2.%s", zoneName)},
9292
),
93+
testAccCheckRecordTagData(
94+
map[string]string{"tag1": "location1", "tag2": "location2"},
95+
&record,
96+
),
9397
),
9498
},
9599
{
@@ -1198,6 +1202,8 @@ resource "ns1_record" "it" {
11981202
filters {
11991203
filter = "geotarget_country"
12001204
}
1205+
1206+
tags = {tag1: "location1", tag2: "location2"}
12011207
}
12021208
12031209
resource "ns1_zone" "test" {

ns1/resource_zone.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ func resourceZone() *schema.Resource {
151151
Type: schema.TypeString,
152152
},
153153
},
154+
"tags": {
155+
Type: schema.TypeMap,
156+
Optional: true,
157+
Elem: &schema.Schema{
158+
Type: schema.TypeString,
159+
},
160+
},
154161
},
155162
Create: zoneCreate,
156163
Read: zoneRead,
@@ -208,6 +215,14 @@ func resourceZoneToResourceData(d *schema.ResourceData, z *dns.Zone) error {
208215
if z.Link != nil && *z.Link != "" {
209216
d.Set("link", *z.Link)
210217
}
218+
if len(z.Tags) > 0 {
219+
terraformTags := make(map[string]interface{}, len(z.Tags))
220+
for k, v := range z.Tags {
221+
terraformTags[k] = v
222+
}
223+
d.Set("tags", terraformTags)
224+
}
225+
211226
return nil
212227
}
213228

@@ -289,6 +304,14 @@ func resourceDataToZone(z *dns.Zone, d *schema.ResourceData) {
289304
z.Secondary.OtherPorts[i] = otherPort.(int)
290305
}
291306
}
307+
308+
if v, ok := d.GetOk("tags"); ok {
309+
tagsRaw := v.(map[string]interface{})
310+
z.Tags = make(map[string]string, len(tagsRaw))
311+
for t, val := range tagsRaw {
312+
z.Tags[t] = val.(string)
313+
}
314+
}
292315
// TODO: support OtherNetworks after ns1-go supports it
293316
if v, ok := d.GetOk("secondaries"); ok {
294317
secondariesSet := v.(*schema.Set)

ns1/resource_zone_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log"
66
"os"
7+
"reflect"
78
"strconv"
89
"strings"
910
"testing"
@@ -83,6 +84,7 @@ func TestAccZone_updated(t *testing.T) {
8384
testAccCheckZoneExpiry(&zone, 2592000),
8485
testAccCheckZoneNxTTL(&zone, 3601),
8586
testAccCheckZoneDNSSEC(&zone, false),
87+
testAccCheckZoneTags(&zone, map[string]string{"tag1": "location1"}),
8688
),
8789
},
8890
{
@@ -727,6 +729,15 @@ func testAccCheckZoneDNSSEC(zone *dns.Zone, expected bool) resource.TestCheckFun
727729
}
728730
}
729731

732+
func testAccCheckZoneTags(zone *dns.Zone, expected map[string]string) resource.TestCheckFunc {
733+
return func(s *terraform.State) error {
734+
if !reflect.DeepEqual(zone.Tags, expected) {
735+
return fmt.Errorf("Tags: got: %v want: %v", zone.Tags, expected)
736+
}
737+
return nil
738+
}
739+
}
740+
730741
func testAccCheckZoneHostmaster(zone *dns.Zone, expected string) resource.TestCheckFunc {
731742
return func(s *terraform.State) error {
732743
if zone.Hostmaster != expected {
@@ -773,6 +784,7 @@ resource "ns1_zone" "it" {
773784
expiry = 2592000
774785
nx_ttl = 3601
775786
dnssec = false
787+
tags = {tag1 = "location1"}
776788
# link = "1.2.3.4.in-addr.arpa" # TODO
777789
# primary = "1.2.3.4.in-addr.arpa" # TODO
778790
}

0 commit comments

Comments
 (0)