-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ValidateFunc for name to r/tfe_policy_set to catch errors at plan…
… time (#168)
- Loading branch information
1 parent
bca4d41
commit 0798563
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package tfe | |
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
tfe "github.com/hashicorp/go-tfe" | ||
|
@@ -732,6 +733,20 @@ func testAccCheckTFEPolicySetDestroy(s *terraform.State) error { | |
return nil | ||
} | ||
|
||
func TestAccTFEPolicySet_invalidName(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckTFEPolicySetDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccTFEPolicySet_invalidName, | ||
ExpectError: regexp.MustCompile(`can only include letters, numbers, -, and _.`), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccTFEPolicySet_basic = ` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform" | ||
|
@@ -970,3 +985,22 @@ resource "tfe_policy_set" "foobar" { | |
GITHUB_POLICY_SET_BRANCH, | ||
GITHUB_POLICY_SET_PATH, | ||
) | ||
|
||
const testAccTFEPolicySet_invalidName = ` | ||
resource "tfe_organization" "foobar" { | ||
name = "tst-terraform" | ||
email = "[email protected]" | ||
} | ||
resource "tfe_sentinel_policy" "foo" { | ||
name = "policy-foo" | ||
policy = "main = rule { true }" | ||
organization = "${tfe_organization.foobar.id}" | ||
} | ||
resource "tfe_policy_set" "foobar" { | ||
name = "not the right format" | ||
description = "Policy Set" | ||
organization = "${tfe_organization.foobar.id}" | ||
policy_ids = ["${tfe_sentinel_policy.foo.id}"] | ||
}` |