mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 10:41:07 +00:00
Merge pull request #1272 from terraform-providers/paddy_org_tests_fix
Fix organization policy tests.
This commit is contained in:
commit
69dc1c290c
@ -37,6 +37,10 @@ var orgEnvVars = []string{
|
|||||||
"GOOGLE_ORG",
|
"GOOGLE_ORG",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var orgTargetEnvVars = []string{
|
||||||
|
"GOOGLE_ORG_2",
|
||||||
|
}
|
||||||
|
|
||||||
var billingAccountEnvVars = []string{
|
var billingAccountEnvVars = []string{
|
||||||
"GOOGLE_BILLING_ACCOUNT",
|
"GOOGLE_BILLING_ACCOUNT",
|
||||||
}
|
}
|
||||||
@ -154,6 +158,11 @@ func getTestOrgFromEnv(t *testing.T) string {
|
|||||||
return multiEnvSearch(orgEnvVars)
|
return multiEnvSearch(orgEnvVars)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTestOrgTargetFromEnv(t *testing.T) string {
|
||||||
|
skipIfEnvNotSet(t, orgTargetEnvVars...)
|
||||||
|
return multiEnvSearch(orgTargetEnvVars)
|
||||||
|
}
|
||||||
|
|
||||||
func getTestBillingAccountFromEnv(t *testing.T) string {
|
func getTestBillingAccountFromEnv(t *testing.T) string {
|
||||||
skipIfEnvNotSet(t, billingAccountEnvVars...)
|
skipIfEnvNotSet(t, billingAccountEnvVars...)
|
||||||
return multiEnvSearch(billingAccountEnvVars)
|
return multiEnvSearch(billingAccountEnvVars)
|
||||||
|
@ -18,9 +18,29 @@ var DENIED_ORG_POLICIES = []string{
|
|||||||
|
|
||||||
// Since each test here is acting on the same organization, run the tests serially to
|
// Since each test here is acting on the same organization, run the tests serially to
|
||||||
// avoid race conditions and aborted operations.
|
// avoid race conditions and aborted operations.
|
||||||
|
func TestAccOrganizationPolicy(t *testing.T) {
|
||||||
|
testCases := map[string]func(t *testing.T){
|
||||||
|
"boolean": testAccOrganizationPolicy_boolean,
|
||||||
|
"list_allowAll": testAccOrganizationPolicy_list_allowAll,
|
||||||
|
"list_allowSome": testAccOrganizationPolicy_list_allowSome,
|
||||||
|
"list_denySome": testAccOrganizationPolicy_list_denySome,
|
||||||
|
"list_update": testAccOrganizationPolicy_list_update,
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccOrganizationPolicy_boolean(t *testing.T) {
|
for name, tc := range testCases {
|
||||||
org := getTestOrgFromEnv(t)
|
// shadow the tc variable into scope so that when
|
||||||
|
// the loop continues, if t.Run hasn't executed tc(t)
|
||||||
|
// yet, we don't have a race condition
|
||||||
|
// see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
|
||||||
|
tc := tc
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
tc(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccOrganizationPolicy_boolean(t *testing.T) {
|
||||||
|
org := getTestOrgTargetFromEnv(t)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
@ -28,12 +48,12 @@ func TestAccOrganizationPolicy_boolean(t *testing.T) {
|
|||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
// Test creation of an enforced boolean policy
|
// Test creation of an enforced boolean policy
|
||||||
Config: testAccOrganizationPolicy_boolean(org, true),
|
Config: testAccOrganizationPolicyConfig_boolean(org, true),
|
||||||
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", true),
|
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", true),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test update from enforced to not
|
// Test update from enforced to not
|
||||||
Config: testAccOrganizationPolicy_boolean(org, false),
|
Config: testAccOrganizationPolicyConfig_boolean(org, false),
|
||||||
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", false),
|
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", false),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -42,12 +62,12 @@ func TestAccOrganizationPolicy_boolean(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test creation of a not enforced boolean policy
|
// Test creation of a not enforced boolean policy
|
||||||
Config: testAccOrganizationPolicy_boolean(org, false),
|
Config: testAccOrganizationPolicyConfig_boolean(org, false),
|
||||||
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", false),
|
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", false),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Test update from not enforced to enforced
|
// Test update from not enforced to enforced
|
||||||
Config: testAccOrganizationPolicy_boolean(org, true),
|
Config: testAccOrganizationPolicyConfig_boolean(org, true),
|
||||||
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", true),
|
Check: testAccCheckGoogleOrganizationBooleanPolicy("bool", true),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -60,15 +80,15 @@ func TestAccOrganizationPolicy_boolean(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccOrganizationPolicy_list_allowAll(t *testing.T) {
|
func testAccOrganizationPolicy_list_allowAll(t *testing.T) {
|
||||||
org := getTestOrgFromEnv(t)
|
org := getTestOrgTargetFromEnv(t)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccOrganizationPolicy_list_allowAll(org),
|
Config: testAccOrganizationPolicyConfig_list_allowAll(org),
|
||||||
Check: testAccCheckGoogleOrganizationListPolicyAll("list", "ALLOW"),
|
Check: testAccCheckGoogleOrganizationListPolicyAll("list", "ALLOW"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -80,8 +100,8 @@ func TestAccOrganizationPolicy_list_allowAll(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccOrganizationPolicy_list_allowSome(t *testing.T) {
|
func testAccOrganizationPolicy_list_allowSome(t *testing.T) {
|
||||||
org := getTestOrgFromEnv(t)
|
org := getTestOrgTargetFromEnv(t)
|
||||||
project := getTestProjectFromEnv()
|
project := getTestProjectFromEnv()
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
@ -89,7 +109,7 @@ func TestAccOrganizationPolicy_list_allowSome(t *testing.T) {
|
|||||||
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccOrganizationPolicy_list_allowSome(org, project),
|
Config: testAccOrganizationPolicyConfig_list_allowSome(org, project),
|
||||||
Check: testAccCheckGoogleOrganizationListPolicyAllowedValues("list", []string{"projects/" + project, "projects/debian-cloud"}),
|
Check: testAccCheckGoogleOrganizationListPolicyAllowedValues("list", []string{"projects/" + project, "projects/debian-cloud"}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -101,15 +121,15 @@ func TestAccOrganizationPolicy_list_allowSome(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccOrganizationPolicy_list_denySome(t *testing.T) {
|
func testAccOrganizationPolicy_list_denySome(t *testing.T) {
|
||||||
org := getTestOrgFromEnv(t)
|
org := getTestOrgTargetFromEnv(t)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccOrganizationPolicy_list_denySome(org),
|
Config: testAccOrganizationPolicyConfig_list_denySome(org),
|
||||||
Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
|
Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -121,19 +141,19 @@ func TestAccOrganizationPolicy_list_denySome(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccOrganizationPolicy_list_update(t *testing.T) {
|
func testAccOrganizationPolicy_list_update(t *testing.T) {
|
||||||
org := getTestOrgFromEnv(t)
|
org := getTestOrgTargetFromEnv(t)
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
CheckDestroy: testAccCheckGoogleOrganizationPolicyDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccOrganizationPolicy_list_allowAll(org),
|
Config: testAccOrganizationPolicyConfig_list_allowAll(org),
|
||||||
Check: testAccCheckGoogleOrganizationListPolicyAll("list", "ALLOW"),
|
Check: testAccCheckGoogleOrganizationListPolicyAll("list", "ALLOW"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Config: testAccOrganizationPolicy_list_denySome(org),
|
Config: testAccOrganizationPolicyConfig_list_denySome(org),
|
||||||
Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
|
Check: testAccCheckGoogleOrganizationListPolicyDeniedValues("list", DENIED_ORG_POLICIES),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -256,7 +276,7 @@ func getGoogleOrganizationPolicyTestResource(s *terraform.State, n string) (*clo
|
|||||||
}).Do()
|
}).Do()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccOrganizationPolicy_boolean(org string, enforced bool) string {
|
func testAccOrganizationPolicyConfig_boolean(org string, enforced bool) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_organization_policy" "bool" {
|
resource "google_organization_policy" "bool" {
|
||||||
org_id = "%s"
|
org_id = "%s"
|
||||||
@ -269,7 +289,7 @@ resource "google_organization_policy" "bool" {
|
|||||||
`, org, enforced)
|
`, org, enforced)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccOrganizationPolicy_list_allowAll(org string) string {
|
func testAccOrganizationPolicyConfig_list_allowAll(org string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_organization_policy" "list" {
|
resource "google_organization_policy" "list" {
|
||||||
org_id = "%s"
|
org_id = "%s"
|
||||||
@ -284,7 +304,7 @@ resource "google_organization_policy" "list" {
|
|||||||
`, org)
|
`, org)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccOrganizationPolicy_list_allowSome(org, project string) string {
|
func testAccOrganizationPolicyConfig_list_allowSome(org, project string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_organization_policy" "list" {
|
resource "google_organization_policy" "list" {
|
||||||
org_id = "%s"
|
org_id = "%s"
|
||||||
@ -302,7 +322,7 @@ resource "google_organization_policy" "list" {
|
|||||||
`, org, project)
|
`, org, project)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccOrganizationPolicy_list_denySome(org string) string {
|
func testAccOrganizationPolicyConfig_list_denySome(org string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_organization_policy" "list" {
|
resource "google_organization_policy" "list" {
|
||||||
org_id = "%s"
|
org_id = "%s"
|
||||||
|
Loading…
Reference in New Issue
Block a user