Skip to content

Commit 2ca1683

Browse files
authored
chore: create access context manager policy ID in test if needed (#1252)
1 parent e1605bd commit 2ca1683

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/integration/org/org_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ func TestOrg(t *testing.T) {
5252
terraformSA := bootstrap.GetStringOutput("organization_step_terraform_service_account_email")
5353
utils.SetEnv(t, "GOOGLE_IMPERSONATE_SERVICE_ACCOUNT", terraformSA)
5454

55+
// Create Access Context Manager Policy ID if needed
56+
orgID := terraform.OutputMap(t, bootstrap.GetTFOptions(), "common_config")["org_id"]
57+
policyID := testutils.GetOrgACMPolicyID(t, orgID)
58+
59+
if policyID == "" {
60+
_, err := gcloud.RunCmdE(t, fmt.Sprintf("access-context-manager policies create --organization %s --title %s --impersonate-service-account %s", orgID, "defaultpolicy", terraformSA))
61+
// ignore creation error and proceed with the test
62+
if err != nil {
63+
fmt.Printf("Ignore error in creation of access-context-manager policy ID for organization %s. Error: [%s]", orgID, err.Error())
64+
}
65+
}
66+
5567
org := tft.NewTFBlueprintTest(t,
5668
tft.WithTFDir("../../../1-org/envs/shared"),
5769
tft.WithVars(vars),
@@ -241,10 +253,9 @@ func TestOrg(t *testing.T) {
241253
prjLogsExportDefaultSink := gcloud.Runf(t, "logging sinks describe _Default --project=%s", auditLogsProjectID)
242254
exclusions := prjLogsExportDefaultSink.Get("exclusions").Array()
243255
assert.NotEmpty(exclusions, fmt.Sprintf("exclusion list for _Default sink in project %s must not be empty", auditLogsProjectID))
244-
exclusionFilter := fmt.Sprintf("-logName : \"/%s/\"",auditLogsProjectID)
256+
exclusionFilter := fmt.Sprintf("-logName : \"/%s/\"", auditLogsProjectID)
245257
assert.Equal(exclusions[0].Get("filter").String(), exclusionFilter)
246258

247-
248259
// logging sinks
249260
logsFilter := []string{
250261
"logName: /logs/cloudaudit.googleapis.com%2Factivity",

0 commit comments

Comments
 (0)