Skip to content

Commit 321989e

Browse files
committed
Merge remote-tracking branch 'origin/mc-parameterized' into mc-parameterized
2 parents c4e2b4e + 205254c commit 321989e

File tree

3 files changed

+84
-16
lines changed

3 files changed

+84
-16
lines changed

mmv1/products/orgpolicy/Policy.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ examples:
5757
- name: 'org_policy_policy_parameters_enforce'
5858
primary_resource_id: 'primary'
5959
exclude_test: true
60-
min_version: 'beta'
6160
parameters:
6261
- name: 'parent'
6362
type: String
@@ -127,7 +126,6 @@ properties:
127126
custom_expand: 'templates/terraform/custom_expand/enum_bool.go.tmpl'
128127
- name: 'parameters'
129128
description: 'Optional. Required for Managed Constraints if parameters defined in constraints. Pass parameter values when policy enforcement is enabled. Ensure that parameter value types match those defined in the constraint definition. For example: { \"allowedLocations\" : [\"us-east1\", \"us-west1\"], \"allowAll\" : true }'
130-
min_version: beta
131129
custom_flatten: 'templates/terraform/custom_flatten/json_schema.tmpl'
132130
custom_expand: 'templates/terraform/custom_expand/json_schema.tmpl'
133131
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'
@@ -211,7 +209,6 @@ properties:
211209
custom_expand: 'templates/terraform/custom_expand/enum_bool.go.tmpl'
212210
- name: 'parameters'
213211
description: 'Optional. Required for Managed Constraints if parameters defined in constraints. Pass parameter values when policy enforcement is enabled. Ensure that parameter value types match those defined in the constraint definition. For example: { \"allowedLocations\" : [\"us-east1\", \"us-west1\"], \"allowAll\" : true }'
214-
min_version: beta
215212
custom_flatten: 'templates/terraform/custom_flatten/json_schema.tmpl'
216213
custom_expand: 'templates/terraform/custom_expand/json_schema.tmpl'
217214
state_func: 'func(v interface{}) string { s, _ := structure.NormalizeJsonString(v); return s }'

mmv1/templates/terraform/examples/org_policy_policy_parameters_enforce.tf.tmpl

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
resource "google_org_policy_policy" "primary" {
2-
provider = google-beta
3-
name = "projects/${google_project.basic.name}/policies/iam.managed.disableServiceAccountKeyUpload"
2+
name = "projects/${google_project.basic.name}/policies/compute.managed.restrictDiskCreation"
43
parent = "projects/${google_project.basic.name}"
54

65
spec {
76
rules {
8-
enforce = "FALSE"
9-
parameters {
10-
"allowAll" : true
11-
"allowedLocations" : ["us-east1", "us-west1"]
12-
}
7+
enforce = "TRUE"
8+
parameters = jsonencode({"isSizeLimitCheck" : true, "allowedDiskTypes" : ["pd-ssd", "pd-standard"]})
139
}
1410
}
1511
}

mmv1/third_party/terraform/services/orgpolicy/resource_org_policy_policy_test.go

+81-6
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,95 @@ func testAccCheckOrgPolicyPolicyDestroyProducer(t *testing.T) func(s *terraform.
458458
return nil
459459
}
460460
}
461+
func TestAccOrgPolicyPolicy_EnforceParameterizedMCPolicy(t *testing.T) {
462+
// Skip this test as no constraints yet launched in production, verified functionality with manual testing.
463+
t.Skip()
464+
t.Parallel()
461465

466+
context := map[string]interface{}{
467+
"org_id": envvar.GetTestOrgFromEnv(t),
468+
"random_suffix": acctest.RandString(t, 10),
469+
}
470+
471+
acctest.VcrTest(t, resource.TestCase{
472+
PreCheck: func() { acctest.AccTestPreCheck(t) },
473+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
474+
CheckDestroy: testAccCheckOrgPolicyPolicyDestroyProducer(t),
475+
Steps: []resource.TestStep{
476+
{
477+
Config: testAccOrgPolicyPolicy_EnforceParameterizedMCPolicy(context),
478+
},
479+
{
480+
ResourceName: "google_org_policy_policy.primary",
481+
ImportState: true,
482+
ImportStateVerify: true,
483+
ImportStateVerifyIgnore: []string{"name", "spec.0.rules.0.condition.0.expression"},
484+
},
485+
},
486+
})
487+
}
462488
func testAccOrgPolicyPolicy_EnforceParameterizedMCPolicy(context map[string]interface{}) string {
463-
return acctest.Nprintf(`
489+
return acctest.Nprintf(`
464490
resource "google_org_policy_policy" "primary" {
465-
name = "projects/${google_project.basic.name}/policies/constraints/compute.managed.restrictDiskCreation"
491+
name = "projects/${google_project.basic.name}/policies/essentialcontacts.managed.allowedContactDomains"
466492
parent = "projects/${google_project.basic.name}"
467493
468494
spec {
469495
rules {
470496
enforce = "TRUE"
471-
parameters {
472-
"isSizeLimitCheck" = True,
473-
"allowedDiskTypes" = ["pd-ssd"]
474-
}
497+
parameters = "{\"allowedDomains\": [\"@google.com\"]}"
498+
}
499+
}
500+
}
501+
502+
resource "google_project" "basic" {
503+
project_id = "tf-test-id%{random_suffix}"
504+
name = "tf-test-id%{random_suffix}"
505+
org_id = "%{org_id}"
506+
deletion_policy = "DELETE"
507+
}
508+
509+
510+
`, context)
511+
}
512+
513+
func TestAccOrgPolicyPolicy_EnforceParameterizedMCDryRunPolicy(t *testing.T) {
514+
// Skip this test as no constraints yet launched in production, verified functionality with manual testing.
515+
t.Skip()
516+
t.Parallel()
517+
518+
context := map[string]interface{}{
519+
"org_id": envvar.GetTestOrgFromEnv(t),
520+
"random_suffix": acctest.RandString(t, 10),
521+
}
522+
523+
acctest.VcrTest(t, resource.TestCase{
524+
PreCheck: func() { acctest.AccTestPreCheck(t) },
525+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
526+
CheckDestroy: testAccCheckOrgPolicyPolicyDestroyProducer(t),
527+
Steps: []resource.TestStep{
528+
{
529+
Config: testAccOrgPolicyPolicy_EnforceParameterizedMCDryRunPolicy(context),
530+
},
531+
{
532+
ResourceName: "google_org_policy_policy.primary",
533+
ImportState: true,
534+
ImportStateVerify: true,
535+
ImportStateVerifyIgnore: []string{"name", "spec.0.rules.0.condition.0.expression"},
536+
},
537+
},
538+
})
539+
}
540+
func testAccOrgPolicyPolicy_EnforceParameterizedMCDryRunPolicy(context map[string]interface{}) string {
541+
return acctest.Nprintf(`
542+
resource "google_org_policy_policy" "primary" {
543+
name = "projects/${google_project.basic.name}/policies/essentialcontacts.managed.allowedContactDomains"
544+
parent = "projects/${google_project.basic.name}"
545+
546+
dry_run_spec {
547+
rules {
548+
enforce = "TRUE"
549+
parameters = "{\"allowedDomains\": [\"@google.com\"]}"
475550
}
476551
}
477552
}

0 commit comments

Comments
 (0)