Skip to content

Commit 4100a1e

Browse files
Changes to add Shielded VMs support in google_dataproc_workflow_templ… (#6481) (#12451)
* Changes to add Shielded VMs support in google_dataproc_workflow_template resource and would also address : /issues/10565 * Added new shielded vm test case to vcr test * updated `go` dependencies and separated the test cases * reverted all dependencies other than dcl * removed enterprise-certificate-proxy dependency * reverted extra dependencies other than dcl Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 308b17d commit 4100a1e

6 files changed

+194
-3
lines changed

.changelog/6481.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
dataproc: added option `shielded_instance_config` to resource `google_dataproc_workflow_template`.
3+
```

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ go 1.18
33

44
require (
55
cloud.google.com/go/bigtable v1.16.0
6-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.18.0
6+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.19.0
77
github.com/apparentlymart/go-cidr v1.1.0
88
github.com/client9/misspell v0.3.4
99
github.com/davecgh/go-spew v1.1.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
7676
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
7777
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM=
7878
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
79-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.18.0 h1:0NWhlgF7eg/jpecAhG/QUwp0MH7D4jYekpljiLUaE74=
80-
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.18.0/go.mod h1:i6Pmzp7aolLmJY86RaJ9wjqm/HFleMeN7Vl5uIWLwE8=
79+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.19.0 h1:4YAtk4xuOCxUSkGdwlDhkX7DTP4VwLZCoebGGEsU+U4=
80+
github.com/GoogleCloudPlatform/declarative-resource-client-library v1.19.0/go.mod h1:i6Pmzp7aolLmJY86RaJ9wjqm/HFleMeN7Vl5uIWLwE8=
8181
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
8282
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
8383
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=

google/resource_dataproc_workflow_template.go

+68
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,15 @@ func DataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigSchema
12221222
Elem: &schema.Schema{Type: schema.TypeString},
12231223
},
12241224

1225+
"shielded_instance_config": {
1226+
Type: schema.TypeList,
1227+
Optional: true,
1228+
ForceNew: true,
1229+
Description: "Optional. Shielded Instance Config for clusters using Compute Engine Shielded VMs.",
1230+
MaxItems: 1,
1231+
Elem: DataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfigSchema(),
1232+
},
1233+
12251234
"subnetwork": {
12261235
Type: schema.TypeString,
12271236
Optional: true,
@@ -1292,6 +1301,33 @@ func DataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigReserv
12921301
}
12931302
}
12941303

1304+
func DataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfigSchema() *schema.Resource {
1305+
return &schema.Resource{
1306+
Schema: map[string]*schema.Schema{
1307+
"enable_integrity_monitoring": {
1308+
Type: schema.TypeBool,
1309+
Optional: true,
1310+
ForceNew: true,
1311+
Description: "Optional. Defines whether instances have integrity monitoring enabled. Integrity monitoring compares the most recent boot measurements to the integrity policy baseline and returns a pair of pass/fail results depending on whether they match or not.",
1312+
},
1313+
1314+
"enable_secure_boot": {
1315+
Type: schema.TypeBool,
1316+
Optional: true,
1317+
ForceNew: true,
1318+
Description: "Optional. Defines whether the instances have Secure Boot enabled. Secure Boot helps ensure that the system only runs authentic software by verifying the digital signature of all boot components, and halting the boot process if signature verification fails.",
1319+
},
1320+
1321+
"enable_vtpm": {
1322+
Type: schema.TypeBool,
1323+
Optional: true,
1324+
ForceNew: true,
1325+
Description: "Optional. Defines whether the instance have the vTPM enabled. Virtual Trusted Platform Module protects objects like keys, certificates and enables Measured Boot by performing the measurements needed to create a known good boot baseline, called the integrity policy baseline.",
1326+
},
1327+
},
1328+
}
1329+
}
1330+
12951331
func DataprocWorkflowTemplatePlacementManagedClusterConfigInitializationActionsSchema() *schema.Resource {
12961332
return &schema.Resource{
12971333
Schema: map[string]*schema.Schema{
@@ -3162,6 +3198,7 @@ func expandDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfig
31623198
ReservationAffinity: expandDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigReservationAffinity(obj["reservation_affinity"]),
31633199
ServiceAccount: dcl.String(obj["service_account"].(string)),
31643200
ServiceAccountScopes: expandStringArray(obj["service_account_scopes"]),
3201+
ShieldedInstanceConfig: expandDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig(obj["shielded_instance_config"]),
31653202
Subnetwork: dcl.String(obj["subnetwork"].(string)),
31663203
Tags: expandStringArray(obj["tags"]),
31673204
Zone: dcl.StringOrNil(obj["zone"].(string)),
@@ -3181,6 +3218,7 @@ func flattenDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfi
31813218
"reservation_affinity": flattenDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigReservationAffinity(obj.ReservationAffinity),
31823219
"service_account": obj.ServiceAccount,
31833220
"service_account_scopes": obj.ServiceAccountScopes,
3221+
"shielded_instance_config": flattenDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig(obj.ShieldedInstanceConfig),
31843222
"subnetwork": obj.Subnetwork,
31853223
"tags": obj.Tags,
31863224
"zone": obj.Zone,
@@ -3244,6 +3282,36 @@ func flattenDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfi
32443282

32453283
return []interface{}{transformed}
32463284

3285+
}
3286+
3287+
func expandDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig(o interface{}) *dataproc.WorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig {
3288+
if o == nil {
3289+
return dataproc.EmptyWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig
3290+
}
3291+
objArr := o.([]interface{})
3292+
if len(objArr) == 0 || objArr[0] == nil {
3293+
return dataproc.EmptyWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig
3294+
}
3295+
obj := objArr[0].(map[string]interface{})
3296+
return &dataproc.WorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig{
3297+
EnableIntegrityMonitoring: dcl.Bool(obj["enable_integrity_monitoring"].(bool)),
3298+
EnableSecureBoot: dcl.Bool(obj["enable_secure_boot"].(bool)),
3299+
EnableVtpm: dcl.Bool(obj["enable_vtpm"].(bool)),
3300+
}
3301+
}
3302+
3303+
func flattenDataprocWorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig(obj *dataproc.WorkflowTemplatePlacementManagedClusterConfigGceClusterConfigShieldedInstanceConfig) interface{} {
3304+
if obj == nil || obj.Empty() {
3305+
return nil
3306+
}
3307+
transformed := map[string]interface{}{
3308+
"enable_integrity_monitoring": obj.EnableIntegrityMonitoring,
3309+
"enable_secure_boot": obj.EnableSecureBoot,
3310+
"enable_vtpm": obj.EnableVtpm,
3311+
}
3312+
3313+
return []interface{}{transformed}
3314+
32473315
}
32483316
func expandDataprocWorkflowTemplatePlacementManagedClusterConfigInitializationActionsArray(o interface{}) []dataproc.WorkflowTemplatePlacementManagedClusterConfigInitializationActions {
32493317
if o == nil {

google/resource_dataproc_workflow_template_test.go

+90
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ func TestAccDataprocWorkflowTemplate_basic(t *testing.T) {
3838
})
3939
}
4040

41+
func TestAccDataprocWorkflowTemplate_withShieldedVMs(t *testing.T) {
42+
t.Parallel()
43+
44+
context := map[string]interface{}{
45+
"random_suffix": randString(t, 10),
46+
"project": getTestProjectFromEnv(),
47+
"version": "2.0.35-debian10",
48+
}
49+
50+
vcrTest(t, resource.TestCase{
51+
PreCheck: func() { testAccPreCheck(t) },
52+
Providers: testAccProviders,
53+
CheckDestroy: funcAccTestDataprocWorkflowTemplateCheckDestroy(t),
54+
ExternalProviders: map[string]resource.ExternalProvider{
55+
"random": {},
56+
},
57+
Steps: []resource.TestStep{
58+
{
59+
Config: testAccDataprocWorkflowTemplate_withShieldedVMs(context),
60+
},
61+
{
62+
ImportState: true,
63+
ImportStateVerify: true,
64+
ResourceName: "google_dataproc_workflow_template.shielded_vms_template",
65+
},
66+
},
67+
})
68+
}
69+
4170
func testAccDataprocWorkflowTemplate_basic(context map[string]interface{}) string {
4271
return Nprintf(`
4372
resource "google_dataproc_workflow_template" "template" {
@@ -94,6 +123,67 @@ resource "google_dataproc_workflow_template" "template" {
94123
`, context)
95124
}
96125

126+
func testAccDataprocWorkflowTemplate_withShieldedVMs(context map[string]interface{}) string {
127+
return Nprintf(`
128+
resource "google_dataproc_workflow_template" "shielded_vms_template" {
129+
name = "template%{random_suffix}"
130+
location = "us-central1"
131+
placement {
132+
managed_cluster {
133+
cluster_name = "my-shielded-cluster"
134+
config {
135+
gce_cluster_config {
136+
zone = "us-central1-a"
137+
tags = ["foo", "bar"]
138+
shielded_instance_config {
139+
enable_secure_boot = true
140+
enable_vtpm = true
141+
enable_integrity_monitoring = true
142+
}
143+
}
144+
master_config {
145+
num_instances = 1
146+
machine_type = "n1-standard-1"
147+
disk_config {
148+
boot_disk_type = "pd-ssd"
149+
boot_disk_size_gb = 15
150+
}
151+
}
152+
worker_config {
153+
num_instances = 3
154+
machine_type = "n1-standard-2"
155+
disk_config {
156+
boot_disk_size_gb = 10
157+
num_local_ssds = 2
158+
}
159+
}
160+
161+
secondary_worker_config {
162+
num_instances = 2
163+
}
164+
software_config {
165+
image_version = "%{version}"
166+
}
167+
}
168+
}
169+
}
170+
jobs {
171+
step_id = "someJob"
172+
spark_job {
173+
main_class = "SomeClass"
174+
}
175+
}
176+
jobs {
177+
step_id = "otherJob"
178+
prerequisite_step_ids = ["someJob"]
179+
presto_job {
180+
query_file_uri = "someuri"
181+
}
182+
}
183+
}
184+
`, context)
185+
}
186+
97187
func funcAccTestDataprocWorkflowTemplateCheckDestroy(t *testing.T) func(s *terraform.State) error {
98188
return func(s *terraform.State) error {
99189
for name, rs := range s.RootModule().Resources {

website/docs/r/dataproc_workflow_template.html.markdown

+30
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ The `gce_cluster_config` block supports:
730730
* `service_account_scopes` -
731731
(Optional)
732732
Optional. The URIs of service account scopes to be included in Compute Engine instances. The following base set of scopes is always included: * https://www.googleapis.com/auth/cloud.useraccounts.readonly * https://www.googleapis.com/auth/devstorage.read_write * https://www.googleapis.com/auth/logging.write If no scopes are specified, the following defaults are also provided: * https://www.googleapis.com/auth/bigquery * https://www.googleapis.com/auth/bigtable.admin.table * https://www.googleapis.com/auth/bigtable.data * https://www.googleapis.com/auth/devstorage.full_control
733+
734+
* `shielded_instance_config` -
735+
(Optional)
736+
Optional. Shielded Instance Config for clusters using [Compute Engine Shielded VMs](https://cloud.google.com/security/shielded-cloud/shielded-vm). Structure [defined below](#nested_shielded_instance_config).
733737

734738
* `subnetwork` -
735739
(Optional)
@@ -762,6 +766,32 @@ The `reservation_affinity` block supports:
762766
* `values` -
763767
(Optional)
764768
Optional. Corresponds to the label values of reservation resource.
769+
770+
<a name="nested_shielded_instance_config"></a>The `shielded_instance_config` block supports:
771+
772+
```hcl
773+
cluster_config {
774+
gce_cluster_config {
775+
shielded_instance_config {
776+
enable_secure_boot = true
777+
enable_vtpm = true
778+
enable_integrity_monitoring = true
779+
}
780+
}
781+
}
782+
```
783+
784+
* `enable_secure_boot` -
785+
(Optional)
786+
Optional. Defines whether instances have [Secure Boot](https://cloud.google.com/compute/shielded-vm/docs/shielded-vm#secure-boot) enabled.
787+
788+
* `enable_vtpm` -
789+
(Optional)
790+
Optional. Defines whether instances have the [vTPM](https://cloud.google.com/compute/shielded-vm/docs/shielded-vm#vtpm) enabled.
791+
792+
* `enable_integrity_monitoring` -
793+
(Optional)
794+
Optional. Defines whether instances have [Integrity Monitoring](https://cloud.google.com/compute/shielded-vm/docs/shielded-vm#integrity-monitoring) enabled.
765795

766796
The `gke_cluster_config` block supports:
767797

0 commit comments

Comments
 (0)