Skip to content

Commit 36eaae5

Browse files
authored
Merge pull request #303 from ns1-terraform/release-v2.0.9
release v2.0.9
2 parents 222d94c + c11b493 commit 36eaae5

11 files changed

Lines changed: 227 additions & 19 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.9 (October 11, 2023)
2+
ENHANCEMENTS
3+
* Added support for zone and record tags
4+
BUG FIX
5+
* Updated test host names
6+
17
## 2.0.8 (October 5, 2023)
28
BUG FIX
39

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ require (
77
github.com/hashicorp/go-retryablehttp v0.7.2
88
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
99
github.com/stretchr/testify v1.8.1
10-
gopkg.in/ns1/ns1-go.v2 v2.7.11
10+
gopkg.in/ns1/ns1-go.v2 v2.7.12
11+
1112
)
1213

1314
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
250250
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
251251
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
252252
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
253-
gopkg.in/ns1/ns1-go.v2 v2.7.11 h1:fs8fkDjfdWdR2Gg//HO+LHrtC38+Z+xpUs3z4iojsn8=
254-
gopkg.in/ns1/ns1-go.v2 v2.7.11/go.mod h1:pfaU0vECVP7DIOr453z03HXS6dFJpXdNRwOyRzwmPSc=
253+
gopkg.in/ns1/ns1-go.v2 v2.7.12 h1:QhpKxzYNN12DfoKwwPqR2+BslU4oFPP+bF4s0imbNoI=
254+
gopkg.in/ns1/ns1-go.v2 v2.7.12/go.mod h1:pfaU0vECVP7DIOr453z03HXS6dFJpXdNRwOyRzwmPSc=
255255
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
256256
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
257257
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

ns1/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
var (
22-
clientVersion = "2.0.8"
22+
clientVersion = "2.0.9"
2323
providerUserAgent = "tf-ns1" + "/" + clientVersion
2424
defaultRetryMax = 3
2525
)

ns1/data_source_record.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func dataSourceRecord() *schema.Resource {
100100
},
101101
},
102102
},
103+
"tags": {
104+
Type: schema.TypeMap,
105+
Computed: true,
106+
},
103107
},
104108
Read: RecordRead,
105109
}

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_pulsar_job_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestAccPulsarJob_basic(t *testing.T) {
3535
testAccCheckPulsarJobActive(&job, true),
3636
testAccCheckPulsarJobShared(&job, false),
3737
testAccCheckPulsarJobSCommunity(&job, false),
38-
testAccCheckPulsarJobSHost(&job, "testAccHost"),
38+
testAccCheckPulsarJobSHost(&job, "testAccHost.com"),
3939
testAccCheckPulsarJobSUrlPath(&job, "/testAccURLPath"),
4040
),
4141
},
@@ -90,7 +90,7 @@ func TestAccPulsarJob_updated_same_type(t *testing.T) {
9090
testAccCheckPulsarJobActive(&job, true),
9191
testAccCheckPulsarJobShared(&job, false),
9292
testAccCheckPulsarJobSCommunity(&job, false),
93-
testAccCheckPulsarJobSHost(&job, "testAccHost"),
93+
testAccCheckPulsarJobSHost(&job, "testAccHost.com"),
9494
testAccCheckPulsarJobSUrlPath(&job, "/testAccURLPath"),
9595
),
9696
},
@@ -105,7 +105,7 @@ func TestAccPulsarJob_updated_same_type(t *testing.T) {
105105
testAccCheckPulsarJobActive(&job, false),
106106
testAccCheckPulsarJobShared(&job, false),
107107
testAccCheckPulsarJobSCommunity(&job, false),
108-
testAccCheckPulsarJobSHost(&job, "testAccUpdatedHost"),
108+
testAccCheckPulsarJobSHost(&job, "testAccUpdatedHost.com"),
109109
testAccCheckPulsarJobSUrlPath(&job, "/testAccUpdatedURLPath"),
110110
),
111111
},
@@ -176,7 +176,7 @@ func TestAccPulsarJob_updated_different_type(t *testing.T) {
176176
testAccCheckPulsarJobActive(&job, true),
177177
testAccCheckPulsarJobShared(&job, false),
178178
testAccCheckPulsarJobSCommunity(&job, false),
179-
testAccCheckPulsarJobSHost(&job, "testAccHost"),
179+
testAccCheckPulsarJobSHost(&job, "testAccHost.com"),
180180
testAccCheckPulsarJobSUrlPath(&job, "/testAccURLPath"),
181181
),
182182
},
@@ -226,7 +226,7 @@ func TestAccPulsarJob_updated_different_type(t *testing.T) {
226226
testAccCheckPulsarJobActive(&job, false),
227227
testAccCheckPulsarJobShared(&job, false),
228228
testAccCheckPulsarJobSCommunity(&job, false),
229-
testAccCheckPulsarJobSHost(&job, "testAccUpdatedHost"),
229+
testAccCheckPulsarJobSHost(&job, "testAccUpdatedHost.com"),
230230
testAccCheckPulsarJobSUrlPath(&job, "/testAccUpdatedURLPath"),
231231
),
232232
},
@@ -276,7 +276,7 @@ func TestAccPulsarJob_BlendMetricWeights(t *testing.T) {
276276
testAccCheckPulsarJobActive(&job, true),
277277
testAccCheckPulsarJobShared(&job, false),
278278
testAccCheckPulsarJobSCommunity(&job, false),
279-
testAccCheckPulsarJobSHost(&job, "testAccCompleteHost"),
279+
testAccCheckPulsarJobSHost(&job, "testAccCompleteHost.com"),
280280
testAccCheckPulsarJobSUrlPath(&job, "/testAccCompleteURLPath"),
281281
testAccCHeckPulsarJobBlendMetricWeights_timestamp(&job, 123),
282282
testAccCHeckPulsarJobBlendMetricWeights_weights(&job, weights),
@@ -298,7 +298,7 @@ func TestAccPulsarJob_BlendMetricWeights(t *testing.T) {
298298
testAccCheckPulsarJobExists("ns1_pulsarjob.it", &job),
299299
testAccCheckPulsarJobName(&job, jobName),
300300
testAccCheckPulsarJobTypeID(&job, "custom"),
301-
testAccCheckPulsarJobSHost(&job, "testAccHost"),
301+
testAccCheckPulsarJobSHost(&job, "testAccHost.com"),
302302
testAccCheckPulsarJobSUrlPath(&job, "/testAccUrlPath"),
303303
testAccCheckPulsarJobAppID(&job, &app),
304304
testAccCheckPulsarJobActive(&job, true),
@@ -385,7 +385,7 @@ func testAccJSPulsarJobBasic(appName, jobName string) string {
385385
type_id = "latency"
386386
app_id = "${ns1_application.app.id}"
387387
config {
388-
host = "testAccHost"
388+
host = "testAccHost.com"
389389
url_path = "/testAccURLPath"
390390
}
391391
}
@@ -404,7 +404,7 @@ func testAccJSPulsarJobUpdated(appName, jobName string) string {
404404
active = false
405405
shared = false
406406
config {
407-
host = "testAccUpdatedHost"
407+
host = "testAccUpdatedHost.com"
408408
url_path = "/testAccUpdatedURLPath"
409409
}
410410
}
@@ -421,7 +421,7 @@ func testAccJSPulsarJobBlendMetricWeights(appName, jobName string) string {
421421
type_id = "latency"
422422
app_id = "${ns1_application.app.id}"
423423
config {
424-
host = "testAccCompleteHost"
424+
host = "testAccCompleteHost.com"
425425
url_path = "/testAccCompleteURLPath"
426426
}
427427
blend_metric_weights {
@@ -481,7 +481,7 @@ func testAccBBPulsarJobConverted(appName, jobName string) string {
481481
type_id = "custom"
482482
app_id = "${ns1_application.app.id}"
483483
config {
484-
host = ""
484+
host = "testAccBBPulsarJobConverted.com"
485485
url_path = ""
486486
}
487487
}
@@ -498,7 +498,7 @@ func testAccBBPulsarJobBlendMetricWeights(appName, jobName string) string {
498498
type_id = "custom"
499499
app_id = "${ns1_application.app.id}"
500500
config {
501-
host = "testAccHost"
501+
host = "testAccHost.com"
502502
url_path = "/testAccUrlPath"
503503
}
504504
blend_metric_weights {

ns1/resource_record.go

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ It is suggested to migrate to a regular "answers" block. Using Terraform 0.12+,
166166
},
167167
},
168168
},
169+
"blocked_tags": {
170+
Type: schema.TypeList,
171+
Optional: true,
172+
Elem: &schema.Schema{
173+
Type: schema.TypeString,
174+
},
175+
},
176+
"tags": {
177+
Type: schema.TypeMap,
178+
Optional: true,
179+
Elem: &schema.Schema{
180+
Type: schema.TypeString,
181+
},
182+
},
169183
},
170184
Create: RecordCreate,
171185
Read: RecordRead,
@@ -212,6 +226,22 @@ func recordToResourceData(d *schema.ResourceData, r *dns.Record) error {
212226
d.Set("type", r.Type)
213227
d.Set("ttl", r.TTL)
214228

229+
if len(r.Tags) > 0 {
230+
terraformTags := make(map[string]interface{}, len(r.Tags))
231+
for k, v := range r.Tags {
232+
terraformTags[k] = v
233+
}
234+
d.Set("tags", terraformTags)
235+
}
236+
237+
if len(r.BlockedTags) > 0 {
238+
terraformBlockedTags := make([]interface{}, 0)
239+
for _, v := range r.BlockedTags {
240+
terraformBlockedTags = append(terraformBlockedTags, v)
241+
}
242+
d.Set("blocked_tags", terraformBlockedTags)
243+
}
244+
215245
d.Set("override_ttl", nil)
216246
if r.Type == "ALIAS" && r.OverrideTTL != nil {
217247
err := d.Set("override_ttl", *r.OverrideTTL)
@@ -444,6 +474,20 @@ func resourceDataToRecord(r *dns.Record, d *schema.ResourceData) error {
444474
r.Regions[region["name"].(string)] = ns1R
445475
}
446476
}
477+
478+
// Even though blocked_tags are not evaluated on GET, dual update logic is currently enforced on POST
479+
if _, tagsExist := d.GetOk("tags"); tagsExist == true {
480+
if _, blockedTagsExist := d.GetOk("blocked_tags"); blockedTagsExist == false {
481+
r.BlockedTags = []string{}
482+
log.Println("empty 'blocked tags' key added")
483+
}
484+
}
485+
if _, blockedTagsExist := d.GetOk("blocked_tags"); blockedTagsExist == true {
486+
if _, tagsExist := d.GetOk("tags"); tagsExist == false {
487+
r.Tags = map[string]string{}
488+
log.Println("empty 'tags' key added")
489+
}
490+
}
447491
return nil
448492
}
449493

@@ -461,7 +505,31 @@ func removeEmptyMeta(v map[string]interface{}) {
461505
// RecordCreate creates DNS record in ns1
462506
func RecordCreate(d *schema.ResourceData, meta interface{}) error {
463507
client := meta.(*ns1.Client)
464-
r := dns.NewRecord(d.Get("zone").(string), d.Get("domain").(string), d.Get("type").(string))
508+
509+
terraformTags := d.Get("tags").(map[string]interface{})
510+
tags := make(map[string]string)
511+
512+
for key, value := range terraformTags {
513+
switch value := value.(type) {
514+
case string:
515+
tags[key] = value
516+
}
517+
}
518+
519+
terraformBlockedTags := d.Get("blocked_tags").([]interface{})
520+
blockedTags := make([]string, 0)
521+
522+
for _, v := range terraformBlockedTags {
523+
blockedTags = append(blockedTags, v.(string))
524+
}
525+
526+
r := dns.NewRecord(
527+
d.Get("zone").(string),
528+
d.Get("domain").(string),
529+
d.Get("type").(string),
530+
tags,
531+
blockedTags,
532+
)
465533
if err := resourceDataToRecord(r, d); err != nil {
466534
return err
467535
}
@@ -500,7 +568,31 @@ func RecordDelete(d *schema.ResourceData, meta interface{}) error {
500568
// RecordUpdate updates the given dns record in ns1
501569
func RecordUpdate(d *schema.ResourceData, meta interface{}) error {
502570
client := meta.(*ns1.Client)
503-
r := dns.NewRecord(d.Get("zone").(string), d.Get("domain").(string), d.Get("type").(string))
571+
572+
terraformTags := d.Get("tags").(map[string]interface{})
573+
tags := make(map[string]string)
574+
575+
for key, value := range terraformTags {
576+
switch value := value.(type) {
577+
case string:
578+
tags[key] = value
579+
}
580+
}
581+
582+
terraformBlockedTags := d.Get("blocked_tags").([]interface{})
583+
blockedTags := make([]string, 0)
584+
585+
for _, v := range terraformBlockedTags {
586+
blockedTags = append(blockedTags, v.(string))
587+
}
588+
589+
r := dns.NewRecord(
590+
d.Get("zone").(string),
591+
d.Get("domain").(string),
592+
d.Get("type").(string),
593+
tags,
594+
blockedTags,
595+
)
504596
if err := resourceDataToRecord(r, d); err != nil {
505597
return err
506598
}

0 commit comments

Comments
 (0)