mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-07 03:01:06 +00:00
Fix organization policy tests.
This updates the organization policy tests to be run sequentially, instead of in parallel, as they share a resource that they're modifying. It also updates them to use a separate organization than the one all our other tests are running in, which prevents other tests from failing because they're run in parallel to the organization policy changing under them.
This commit is contained in:
parent
33f8bc790c
commit
0c3cbfc2e6
@ -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,25 @@ 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)
|
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 +44,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 +58,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 +76,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 +96,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 +105,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 +117,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 +137,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 +272,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 +285,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 +300,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 +318,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