Skip to content

Commit c240667

Browse files
cloudsecuritycompliace: replace organization with parent to support PLE (#17644) (#1342)
[upstream:fbe417ab7d4cc96c24d79137c2b492289a2f6f06] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent a7c872b commit c240667

8 files changed

Lines changed: 418 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
data "google_project" "project" {}
2+
resource "google_cloud_security_compliance_cloud_control" "example" {
3+
parent = "projects/${data.google_project.project.number}"
4+
location = "global"
5+
cloud_control_id = "example-cloudcontrol-${local.name_suffix}"
6+
7+
display_name = "TF test CloudControl Name"
8+
description = "A test cloud control for security compliance"
9+
categories = ["CC_CATEGORY_INFRASTRUCTURE"]
10+
severity = "HIGH"
11+
finding_category = "SECURITY_POLICY"
12+
remediation_steps = "Review and update the security configuration according to best practices."
13+
14+
supported_cloud_providers = ["GCP"]
15+
16+
rules {
17+
description = "Ensure compute instances have secure boot enabled"
18+
rule_action_types = ["RULE_ACTION_TYPE_DETECTIVE"]
19+
20+
cel_expression {
21+
expression = "resource.data.shieldedInstanceConfig.enableSecureBoot == true"
22+
resource_types_values {
23+
values = ["compute.googleapis.com/Instance"]
24+
}
25+
}
26+
}
27+
28+
parameter_spec {
29+
name = "location"
30+
display_name = "Resource Location"
31+
description = "The location where the resource should be deployed"
32+
value_type = "STRING"
33+
is_required = true
34+
35+
default_value {
36+
string_value = "us-central1"
37+
}
38+
39+
validation {
40+
regexp_pattern {
41+
pattern = "^[a-z]+-[a-z]+[0-9]$"
42+
}
43+
}
44+
}
45+
46+
parameter_spec {
47+
name = "enable_secure_boot"
48+
display_name = "Enable Secure Boot"
49+
description = "Whether to enable secure boot for instances"
50+
value_type = "BOOLEAN"
51+
is_required = true
52+
53+
default_value {
54+
bool_value = true
55+
}
56+
57+
substitution_rules {
58+
attribute_substitution_rule {
59+
attribute = "rules[0].cel_expression.expression"
60+
}
61+
}
62+
63+
validation {
64+
allowed_values {
65+
values {
66+
bool_value = true
67+
}
68+
}
69+
}
70+
}
71+
72+
parameter_spec {
73+
name = "max_instances"
74+
display_name = "Maximum Instances"
75+
description = "Maximum number of instances allowed"
76+
value_type = "NUMBER"
77+
is_required = false
78+
79+
default_value {
80+
number_value = 10
81+
}
82+
83+
substitution_rules {
84+
placeholder_substitution_rule {
85+
attribute = "rules[0].description"
86+
}
87+
}
88+
89+
validation {
90+
int_range {
91+
min = "1"
92+
max = "100"
93+
}
94+
}
95+
}
96+
97+
parameter_spec {
98+
name = "allowed_regions"
99+
display_name = "Allowed Regions"
100+
description = "List of regions where resources can be deployed"
101+
value_type = "STRINGLIST"
102+
is_required = true
103+
104+
default_value {
105+
string_list_value {
106+
values = ["us-central1", "us-east1", "us-west1"]
107+
}
108+
}
109+
110+
validation {
111+
allowed_values {
112+
values {
113+
string_list_value {
114+
values = ["us-central1", "us-east1"]
115+
}
116+
}
117+
values {
118+
string_list_value {
119+
values = ["us-west1", "us-west2"]
120+
}
121+
}
122+
}
123+
}
124+
}
125+
126+
parameter_spec {
127+
name = "environment_type"
128+
display_name = "Environment Type"
129+
description = "The type of environment"
130+
value_type = "STRING"
131+
is_required = true
132+
133+
default_value {
134+
string_value = "production"
135+
}
136+
137+
validation {
138+
allowed_values {
139+
values {
140+
string_value = "production"
141+
}
142+
values {
143+
string_value = "staging"
144+
}
145+
values {
146+
number_value = 1
147+
}
148+
}
149+
}
150+
}
151+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Cloudsecuritycompliance Cloudcontrol Project Basic - Terraform
2+
3+
## Setup
4+
5+
<walkthrough-author name="rileykarson@google.com" analyticsId="UA-125550242-1" tutorialName="cloudsecuritycompliance_cloudcontrol_project_basic" repositoryUrl="https://github.com/terraform-google-modules/docs-examples"></walkthrough-author>
6+
7+
Welcome to Terraform in Google Cloud Shell! We need you to let us know what project you'd like to use with Terraform.
8+
9+
<walkthrough-project-billing-setup></walkthrough-project-billing-setup>
10+
11+
Terraform provisions real GCP resources, so anything you create in this session will be billed against this project.
12+
13+
## Terraforming!
14+
15+
Let's use {{project-id}} with Terraform! Click the Cloud Shell icon below to copy the command
16+
to your shell, and then run it from the shell by pressing Enter/Return. Terraform will pick up
17+
the project name from the environment variable.
18+
19+
```bash
20+
export GOOGLE_CLOUD_PROJECT={{project-id}}
21+
```
22+
23+
After that, let's get Terraform started. Run the following to pull in the providers.
24+
25+
```bash
26+
terraform init
27+
```
28+
29+
With the providers downloaded and a project set, you're ready to use Terraform. Go ahead!
30+
31+
```bash
32+
terraform apply
33+
```
34+
35+
Terraform will show you what it plans to do, and prompt you to accept. Type "yes" to accept the plan.
36+
37+
```bash
38+
yes
39+
```
40+
41+
42+
## Post-Apply
43+
44+
### Editing your config
45+
46+
Now you've provisioned your resources in GCP! If you run a "plan", you should see no changes needed.
47+
48+
```bash
49+
terraform plan
50+
```
51+
52+
So let's make a change! Try editing a number, or appending a value to the name in the editor. Then,
53+
run a 'plan' again.
54+
55+
```bash
56+
terraform plan
57+
```
58+
59+
Afterwards you can run an apply, which implicitly does a plan and shows you the intended changes
60+
at the 'yes' prompt.
61+
62+
```bash
63+
terraform apply
64+
```
65+
66+
```bash
67+
yes
68+
```
69+
70+
## Cleanup
71+
72+
Run the following to remove the resources Terraform provisioned:
73+
74+
```bash
75+
terraform destroy
76+
```
77+
```bash
78+
yes
79+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file has some scaffolding to make sure that names are unique and that
2+
# a region and zone are selected when you try to create your Terraform resources.
3+
4+
locals {
5+
name_suffix = "${random_pet.suffix.id}"
6+
}
7+
8+
resource "random_pet" "suffix" {
9+
length = 2
10+
}
11+
12+
provider "google" {
13+
region = "us-central1"
14+
zone = "us-central1-c"
15+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
data "google_project" "project" {}
2+
3+
# App Hub Application resource to act as the target
4+
resource "google_apphub_application" "application" {
5+
location = "us-central1"
6+
application_id = "example-app-${local.name_suffix}"
7+
scope {
8+
type = "REGIONAL"
9+
}
10+
}
11+
12+
resource "google_cloud_security_compliance_framework" "example" {
13+
parent = "projects/${data.google_project.project.number}"
14+
location = "global"
15+
framework_id = "example-framework-${local.name_suffix}"
16+
17+
display_name = "Terraform Framework Name"
18+
description = "A Terraform description for the framework"
19+
20+
cloud_control_details {
21+
name = "projects/${data.google_project.project.number}/locations/global/cloudControls/builtin-require-cmek-on-bigquery-datasets"
22+
major_revision_id = "2"
23+
24+
parameters {
25+
name = "location"
26+
parameter_value {
27+
number_value = 1
28+
}
29+
}
30+
}
31+
}
32+
33+
resource "google_cloud_security_compliance_framework_deployment" "example" {
34+
parent = "projects/${data.google_project.project.number}"
35+
location = "global"
36+
framework_deployment_id = "example-deployment-${local.name_suffix}"
37+
description = "A framework deployment with project parent targeting an application"
38+
39+
framework {
40+
framework = google_cloud_security_compliance_framework.example.name
41+
major_revision_id = "1"
42+
}
43+
44+
target_resource_config {
45+
# Target the App Hub Application's fully qualified ID
46+
# e.g., projects/abc/locations/us-central1/applications/app-name
47+
existing_target_resource = "projects/${data.google_project.project.number}/locations/us-central1/applications/${google_apphub_application.application.application_id}"
48+
}
49+
50+
cloud_control_metadata {
51+
enforcement_mode = "DETECTIVE"
52+
53+
cloud_control_details {
54+
name = "projects/${data.google_project.project.number}/locations/global/cloudControls/builtin-require-cmek-on-bigquery-datasets"
55+
major_revision_id = "2"
56+
57+
parameters {
58+
name = "location"
59+
parameter_value {
60+
number_value = 1
61+
}
62+
}
63+
}
64+
}
65+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===
2+
3+
These examples use real resources that will be billed to the
4+
Google Cloud Platform project you use - so make sure that you
5+
run "terraform destroy" before quitting!
6+
7+
===

0 commit comments

Comments
 (0)