Skip to content

Commit

Permalink
Merge pull request #200 from hisume/fix-stanza-validation
Browse files Browse the repository at this point in the history
Update stanza validation in resource_splunk_configs_conf.go
  • Loading branch information
mploski authored Dec 6, 2024
2 parents e59e9b4 + bc0bf9a commit 2728d13
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion splunk/resource_splunk_configs_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func configsConf() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9_\-.]+/[a-zA-Z0-9_\-.]+`), "A '/' separated string consisting of {conf_file_name}/{stanza_name} ex. props/custom_stanza"),
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9_\-.]+/[a-zA-Z0-9_\-.:/]+`), "A '/' separated string consisting of {conf_file_name}/{stanza_name} ex. props/custom_stanza"),
Description: `A '/' separated string consisting of {conf_file_name}/{stanza_name} ex. props/custom_stanza`,
},
"acl": aclSchema(),
Expand Down
53 changes: 53 additions & 0 deletions splunk/resource_splunk_configs_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,59 @@ func TestAccCreateSplunkConfigsConf(t *testing.T) {
})
}

const newConfigsConfSpecialChars = `
resource "splunk_configs_conf" "tftest-stanza-special-chars" {
name = "tf_test/sqs://tftest_stanza_special_chars"
variables = {
"disabled": "false"
"key": "value"
}
}
`

const updateConfigsConfSpecialChars = `
resource "splunk_configs_conf" "tftest-stanza-special-chars" {
name = "tf_test/sqs://tftest_stanza_special_chars"
variables = {
"disabled": "false"
"key": "new-value"
}
}
`

func TestAccCreateSplunkConfigsConfSpecialChars(t *testing.T) {
resourceName := "splunk_configs_conf.tftest-stanza-special-chars"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccSplunkConfigsConfDestroyResources,
Steps: []resource.TestStep{
{
Config: newConfigsConfSpecialChars,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "variables.key", "value"),
),
},
{
Config: updateConfigsConfSpecialChars,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "variables.key", "new-value"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}


func testAccSplunkConfigsConfDestroyResources(s *terraform.State) error {
client, err := newTestClient()
if err != nil {
Expand Down

0 comments on commit 2728d13

Please sign in to comment.