Skip to content

Commit 960ccaa

Browse files
authored
Fix datafeed params + minor polishing of monitors (#371)
* Fix datafeed params + minor polishing of monitors * Distinguish error messages
1 parent 5aa067f commit 960ccaa

6 files changed

Lines changed: 135 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## 2.8.1 (Unreleased)
1+
## 2.8.1 (February 12 2026)
22
ENHANCEMENTS
3+
* Fix datadog and webcheck datafeed params
34
* Update documentation to contain the default values of the fields
45

56
## 2.8.0 (January 15 2026)

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.8.0"
22+
clientVersion = "2.8.1"
2323
providerUserAgent = "tf-ns1" + "/" + clientVersion
2424
defaultRetryMax = 3
2525
)

ns1/resource_datafeed.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,33 @@ func dataFeedToResourceData(d *schema.ResourceData, f *data.Feed) {
4848
func resourceDataToDataFeed(d *schema.ResourceData) (feed *data.Feed, e error) {
4949
config := d.Get("config").(map[string]interface{})
5050
if config != nil {
51-
test_id := config["test_id"]
52-
if test_id != nil {
53-
test_id_int, err := strconv.Atoi(test_id.(string))
51+
if testId := config["test_id"]; testId != nil {
52+
intTestId, err := strconv.Atoi(testId.(string))
5453
if err != nil {
55-
return &data.Feed{}, fmt.Errorf("could not convert %v as int %w", test_id, err)
54+
return &data.Feed{}, fmt.Errorf("could not convert test_id = %v as int: %w", testId, err)
5655
}
57-
config["test_id"] = test_id_int
56+
config["test_id"] = intTestId
57+
}
58+
if checkId := config["check_id"]; checkId != nil {
59+
intCheckId, err := strconv.Atoi(checkId.(string))
60+
if err != nil {
61+
return &data.Feed{}, fmt.Errorf("could not convert check_id = %v as int: %w", checkId, err)
62+
}
63+
config["check_id"] = intCheckId
64+
}
65+
if failOnWarning := config["fail_on_warning"]; failOnWarning != nil {
66+
boolFailOnWarning, err := strconv.ParseBool(failOnWarning.(string))
67+
if err != nil {
68+
return &data.Feed{}, fmt.Errorf("could not convert fail_on_warning = %v as bool: %w", failOnWarning, err)
69+
}
70+
config["fail_on_warning"] = boolFailOnWarning
71+
}
72+
if failOnNoData := config["fail_on_no_data"]; failOnNoData != nil {
73+
boolFailOnNoData, err := strconv.ParseBool(failOnNoData.(string))
74+
if err != nil {
75+
return &data.Feed{}, fmt.Errorf("could not convert fail_on_no_data = %v as bool: %w", failOnNoData, err)
76+
}
77+
config["fail_on_no_data"] = boolFailOnNoData
5878
}
5979
}
6080

@@ -124,12 +144,23 @@ func DataFeedUpdate(d *schema.ResourceData, meta interface{}) error {
124144
func configAdapterOut(f *data.Feed) {
125145
config := f.Config
126146
if config != nil {
127-
test_id := config["test_id"]
128-
if test_id != nil {
129-
test_id_str := strconv.Itoa(int(test_id.(float64)))
130-
config["test_id"] = test_id_str
131-
f.Config = config
147+
if testId := config["test_id"]; testId != nil {
148+
strTestId := strconv.Itoa(int(testId.(float64)))
149+
config["test_id"] = strTestId
150+
}
151+
if checkId := config["check_id"]; checkId != nil {
152+
strCheckId := strconv.Itoa(int(checkId.(float64)))
153+
config["check_id"] = strCheckId
154+
}
155+
if failOnWarning := config["fail_on_warning"]; failOnWarning != nil {
156+
strFailOnWarning := strconv.FormatBool(failOnWarning.(bool))
157+
config["fail_on_warning"] = strFailOnWarning
158+
}
159+
if failOnNoData := config["fail_on_no_data"]; failOnNoData != nil {
160+
strFailOnNoData := strconv.FormatBool(failOnNoData.(bool))
161+
config["fail_on_no_data"] = strFailOnNoData
132162
}
163+
f.Config = config
133164
}
134165
}
135166

ns1/resource_datafeed_test.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,44 @@ func TestThousandeyes_Basic(t *testing.T) {
5151
})
5252
}
5353

54+
func TestWebcheck_Basic(t *testing.T) {
55+
var dataFeed data.Feed
56+
resource.Test(t, resource.TestCase{
57+
PreCheck: func() { testAccPreCheck(t) },
58+
Providers: testAccProviders,
59+
CheckDestroy: testAccCheckDataFeedDestroy,
60+
Steps: []resource.TestStep{
61+
{
62+
Config: testWebcheckBasic,
63+
Check: resource.ComposeTestCheckFunc(
64+
testAccCheckDataFeedExists("ns1_datafeed.uswest_feed", "ns1_datasource.api", &dataFeed, t),
65+
testAccCheckDataFeedName(&dataFeed, "uswest_feed"),
66+
testThousandeyesConfig(&dataFeed, "check_id", 123),
67+
),
68+
},
69+
},
70+
})
71+
}
72+
73+
func TestDatadog_Basic(t *testing.T) {
74+
var dataFeed data.Feed
75+
resource.Test(t, resource.TestCase{
76+
PreCheck: func() { testAccPreCheck(t) },
77+
Providers: testAccProviders,
78+
CheckDestroy: testAccCheckDataFeedDestroy,
79+
Steps: []resource.TestStep{
80+
{
81+
Config: testDatadogBasic,
82+
Check: resource.ComposeTestCheckFunc(
83+
testAccCheckDataFeedExists("ns1_datafeed.uswest_feed", "ns1_datasource.api", &dataFeed, t),
84+
testAccCheckDataFeedName(&dataFeed, "uswest_feed"),
85+
testDatadogConfig(&dataFeed, "DataDog Test", true, true),
86+
),
87+
},
88+
},
89+
})
90+
}
91+
5492
func TestAccDataFeed_updated(t *testing.T) {
5593
var dataFeed data.Feed
5694
resource.Test(t, resource.TestCase{
@@ -208,6 +246,25 @@ func testThousandeyesConfig(dataFeed *data.Feed, key string, expected float64) r
208246
}
209247
}
210248

249+
func testDatadogConfig(dataFeed *data.Feed, name string, failOnWarning, failOnNoData bool) resource.TestCheckFunc {
250+
return func(s *terraform.State) error {
251+
252+
if dataFeed.Config["test_name"] != name {
253+
return fmt.Errorf("dataFeed.Config[name]: got: %#v, want: %s", dataFeed.Config["test_name"], name)
254+
}
255+
256+
if dataFeed.Config["fail_on_warning"] != failOnWarning {
257+
return fmt.Errorf("dataFeed.Config[fail_on_warning]: got: %#v, want: %t", dataFeed.Config["fail_on_warning"], failOnWarning)
258+
}
259+
260+
if dataFeed.Config["fail_on_no_data"] != failOnNoData {
261+
return fmt.Errorf("dataFeed.Config[fail_on_no_data]: got: %#v, want: %t", dataFeed.Config["fail_on_no_data"], failOnNoData)
262+
}
263+
264+
return nil
265+
}
266+
}
267+
211268
// Simulate a manual deletion of a data feed.
212269
func testAccManualDeleteDataFeed(dataFeed *data.Feed) func() {
213270
return func() {
@@ -248,6 +305,36 @@ resource "ns1_datafeed" "uswest_feed" {
248305
}
249306
}`
250307

308+
const testDatadogBasic = `
309+
resource "ns1_datasource" "api" {
310+
name = "terraform test"
311+
sourcetype = "datadog"
312+
}
313+
314+
resource "ns1_datafeed" "uswest_feed" {
315+
name = "uswest_feed"
316+
source_id = "${ns1_datasource.api.id}"
317+
config = {
318+
fail_on_warning = true
319+
fail_on_no_data = true
320+
test_name = "DataDog Test"
321+
}
322+
}`
323+
324+
const testWebcheckBasic = `
325+
resource "ns1_datasource" "api" {
326+
name = "terraform test"
327+
sourcetype = "webcheck"
328+
}
329+
330+
resource "ns1_datafeed" "uswest_feed" {
331+
name = "uswest_feed"
332+
source_id = "${ns1_datasource.api.id}"
333+
config = {
334+
check_id = "123"
335+
}
336+
}`
337+
251338
const testAccDataFeedUpdated = `
252339
resource "ns1_datasource" "api" {
253340
name = "terraform test"

ns1/resource_monitoringjob.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,20 @@ func monitoringJobToResourceData(d *schema.ResourceData, r *monitor.Job) error {
134134
d.Set("rapid_recheck", r.RapidRecheck)
135135
config := make(map[string]string)
136136
for k, v := range r.Config {
137-
if k == "ssl" {
137+
switch k {
138+
case "ssl":
138139
if v.(bool) {
139140
config[k] = "1"
140141
} else {
141142
config[k] = "0"
142143
}
143-
} else if k == "follow_redirect" || k == "ipv6" || k == "tls_skip_verify" || k == "tls_add_verify" {
144+
case "follow_redirect", "ipv6", "tls_skip_verify", "tls_add_verify":
144145
if v.(bool) {
145146
config[k] = "true"
146147
} else {
147148
config[k] = "false"
148149
}
149-
} else {
150+
default:
150151
switch t := v.(type) {
151152
case string:
152153
config[k] = t
@@ -194,7 +195,6 @@ func resourceDataToMonitoringJob(r *monitor.Job, d *schema.ResourceData) error {
194195
}
195196
r.Frequency = d.Get("frequency").(int)
196197
r.RapidRecheck = d.Get("rapid_recheck").(bool)
197-
var rawRules []interface{}
198198
if rawRules := d.Get("rules"); rawRules != nil {
199199
r.Rules = make([]*monitor.Rule, len(rawRules.([]interface{})))
200200
for i, v := range rawRules.([]interface{}) {
@@ -208,19 +208,6 @@ func resourceDataToMonitoringJob(r *monitor.Job, d *schema.ResourceData) error {
208208
} else {
209209
r.Rules = make([]*monitor.Rule, 0)
210210
}
211-
for i, v := range rawRules {
212-
rule := v.(map[string]interface{})
213-
r.Rules[i] = &monitor.Rule{
214-
Comparison: rule["comparison"].(string),
215-
Key: rule["key"].(string),
216-
}
217-
value := rule["value"].(string)
218-
if i, err := strconv.Atoi(value); err == nil {
219-
r.Rules[i].Value = i
220-
} else {
221-
r.Rules[i].Value = value
222-
}
223-
}
224211
config := make(map[string]interface{})
225212
if rawConfig := d.Get("config"); rawConfig != nil {
226213
for k, v := range rawConfig.(map[string]interface{}) {

ns1/resource_monitoringjob_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,6 @@ func TestAccMonitoringJob_ManualDelete(t *testing.T) {
147147
})
148148
}
149149

150-
func testAccCheckMonitoringJobState(key, value string) resource.TestCheckFunc {
151-
return func(s *terraform.State) error {
152-
rs, ok := s.RootModule().Resources["ns1_monitoringjob.it"]
153-
if !ok {
154-
return fmt.Errorf("not found: %s", "ns1_monitoringjob.it")
155-
}
156-
157-
if rs.Primary.ID == "" {
158-
return fmt.Errorf("no ID is set")
159-
}
160-
161-
p := rs.Primary
162-
if p.Attributes[key] != value {
163-
return fmt.Errorf(
164-
"%s != %s (actual: %s)", key, value, p.Attributes[key])
165-
}
166-
167-
return nil
168-
}
169-
}
170-
171150
func testAccCheckMonitoringJobExists(n string, monitoringJob *monitor.Job) resource.TestCheckFunc {
172151
return func(s *terraform.State) error {
173152
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)