Skip to content

Commit

Permalink
fix(workloads): Add validation on required fields (#2605)
Browse files Browse the repository at this point in the history
Co-authored-by: pranav-new-relic <[email protected]>
  • Loading branch information
jdvr and pranav-new-relic authored Mar 21, 2024
1 parent 757e731 commit 19593e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 11 additions & 1 deletion newrelic/resource_newrelic_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func resourceNewRelicWorkload() *schema.Resource {
"query": {
Type: schema.TypeString,
Required: true,
Description: "The query.",
Description: "A valid entity search query; empty, and null values are considered invalid.",
ValidateFunc: validation.All(
validation.StringIsNotEmpty,
validation.StringIsNotWhiteSpace,
validation.NoZeroValues,
),
},
},
},
Expand Down Expand Up @@ -122,6 +127,11 @@ func resourceNewRelicWorkload() *schema.Resource {
Type: schema.TypeString,
Required: true,
Description: "The entity search query that is used to perform the search of a group of entities.",
ValidateFunc: validation.All(
validation.StringIsNotEmpty,
validation.StringIsNotWhiteSpace,
validation.NoZeroValues,
),
},
},
},
Expand Down
21 changes: 21 additions & 0 deletions newrelic/resource_newrelic_workload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ func TestAccNewRelicWorkload_EntitySearchQueriesOnly(t *testing.T) {
testAccCheckNewRelicWorkloadExists(resourceName),
),
},
{
Config: testAccNewRelicWorkloadConfigWrongEntitySearchQueriesOnly(rName, ""),
ExpectError: regexp.MustCompile("Invalid value for \"query\""),
},
{
Config: testAccNewRelicWorkloadConfigWrongEntitySearchQueriesOnly(rName, " "),
ExpectError: regexp.MustCompile("Invalid value for \"query\""),
},
},
})
}
Expand Down Expand Up @@ -548,6 +556,19 @@ resource "newrelic_workload" "foo" {
`, testAccountID, name)
}

func testAccNewRelicWorkloadConfigWrongEntitySearchQueriesOnly(name string, esq string) string {
return fmt.Sprintf(`
resource "newrelic_workload" "foo" {
name = "%[2]s"
account_id = %[1]d
entity_search_query {
query = %[3]s
}
}
`, testAccountID, name, esq)
}

func testAccNewRelicWorkloadConfigEntityMultiSearchQueriesOnly(name string) string {
return fmt.Sprintf(`
resource "newrelic_workload" "foo" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/workload.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ The following arguments are supported:

All nested `entity_search_query` blocks support the following common arguments:

* `query` - (Required) The query.
* `query` - (Required) A valid entity search query; empty, and null values are considered invalid.

### Nested `status_config_automatic` blocks

Expand Down

0 comments on commit 19593e0

Please sign in to comment.