Skip to content

Commit 5ffc2b9

Browse files
Add confidential compute support to google_dataproc_cluster (#12397) (#20488)
[upstream:51b6a13dd2a1ea0089b220a2e6d6f994a368fbe9] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent ba3af15 commit 5ffc2b9

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

.changelog/12397.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
dataproc: added `confidential_instance_config` field to `google_dataproc_cluster` resource
3+
```

google/services/dataproc/resource_dataproc_cluster.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ var (
6464
"cluster_config.0.gce_cluster_config.0.metadata",
6565
"cluster_config.0.gce_cluster_config.0.reservation_affinity",
6666
"cluster_config.0.gce_cluster_config.0.node_group_affinity",
67+
"cluster_config.0.gce_cluster_config.0.confidential_instance_config",
6768
}
6869

6970
schieldedInstanceConfigKeys = []string{
@@ -78,6 +79,10 @@ var (
7879
"cluster_config.0.gce_cluster_config.0.reservation_affinity.0.values",
7980
}
8081

82+
confidentialInstanceConfigKeys = []string{
83+
"cluster_config.0.gce_cluster_config.0.confidential_instance_config.0.enable_confidential_compute",
84+
}
85+
8186
masterDiskConfigKeys = diskConfigKeys("master_config")
8287
workerDiskConfigKeys = diskConfigKeys("worker_config")
8388
preemptibleWorkerDiskConfigKeys = diskConfigKeys("preemptible_worker_config")
@@ -759,6 +764,26 @@ func ResourceDataprocCluster() *schema.Resource {
759764
},
760765
},
761766
},
767+
"confidential_instance_config": {
768+
Type: schema.TypeList,
769+
Optional: true,
770+
AtLeastOneOf: gceClusterConfigKeys,
771+
Computed: true,
772+
MaxItems: 1,
773+
Description: `Confidential Instance Config for clusters using Compute Engine Confidential VMs.`,
774+
Elem: &schema.Resource{
775+
Schema: map[string]*schema.Schema{
776+
"enable_confidential_compute": {
777+
Type: schema.TypeBool,
778+
Optional: true,
779+
Default: false,
780+
AtLeastOneOf: confidentialInstanceConfigKeys,
781+
ForceNew: true,
782+
Description: `Defines whether the instance should have confidential compute enabled.`,
783+
},
784+
},
785+
},
786+
},
762787
},
763788
},
764789
},
@@ -2248,6 +2273,13 @@ func expandGceClusterConfig(d *schema.ResourceData, config *transport_tpg.Config
22482273
conf.NodeGroupAffinity.NodeGroupUri = v.(string)
22492274
}
22502275
}
2276+
if v, ok := d.GetOk("cluster_config.0.gce_cluster_config.0.confidential_instance_config"); ok {
2277+
cfgCic := v.([]interface{})[0].(map[string]interface{})
2278+
conf.ConfidentialInstanceConfig = &dataproc.ConfidentialInstanceConfig{}
2279+
if v, ok := cfgCic["enable_confidential_compute"]; ok {
2280+
conf.ConfidentialInstanceConfig.EnableConfidentialCompute = v.(bool)
2281+
}
2282+
}
22512283
return conf, nil
22522284
}
22532285

@@ -3196,6 +3228,13 @@ func flattenGceClusterConfig(d *schema.ResourceData, gcc *dataproc.GceClusterCon
31963228
},
31973229
}
31983230
}
3231+
if gcc.ConfidentialInstanceConfig != nil {
3232+
gceConfig["confidential_instance_config"] = []map[string]interface{}{
3233+
{
3234+
"enable_confidential_compute": gcc.ConfidentialInstanceConfig.EnableConfidentialCompute,
3235+
},
3236+
}
3237+
}
31993238

32003239
return []map[string]interface{}{gceConfig}
32013240
}

google/services/dataproc/resource_dataproc_cluster_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,51 @@ func TestAccDataprocCluster_withInternalIpOnlyTrueAndShieldedConfig(t *testing.T
258258
})
259259
}
260260

261+
func TestAccDataprocCluster_withConfidentialCompute(t *testing.T) {
262+
t.Parallel()
263+
264+
var cluster dataproc.Cluster
265+
rnd := acctest.RandString(t, 10)
266+
networkName := acctest.BootstrapSharedTestNetwork(t, "dataproc-cluster")
267+
subnetworkName := acctest.BootstrapSubnet(t, "dataproc-cluster", networkName)
268+
acctest.BootstrapFirewallForDataprocSharedNetwork(t, "dataproc-cluster", networkName)
269+
imageUri := "https://www.googleapis.com/compute/v1/projects/cloud-dataproc/global/images/dataproc-2-1-ubu20-20241026-165100-rc01"
270+
271+
acctest.VcrTest(t, resource.TestCase{
272+
PreCheck: func() { acctest.AccTestPreCheck(t) },
273+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
274+
CheckDestroy: testAccCheckDataprocClusterDestroy(t),
275+
Steps: []resource.TestStep{
276+
{
277+
Config: testAccDataprocCluster_withConfidentialCompute(rnd, subnetworkName, imageUri),
278+
Check: resource.ComposeTestCheckFunc(
279+
testAccCheckDataprocClusterExists(t, "google_dataproc_cluster.confidential", &cluster),
280+
281+
// Check confidential compute
282+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
283+
"cluster_config.0.gce_cluster_config.0.confidential_instance_config.0.enable_confidential_compute", "true"),
284+
285+
// Check master
286+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
287+
"cluster_config.0.master_config.0.machine_type", "n2d-standard-2"),
288+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
289+
"cluster_config.0.master_config.0.image_uri", imageUri),
290+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
291+
"cluster_config.0.master_config.0.min_cpu_platform", "AMD Rome"),
292+
293+
// Check worker
294+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
295+
"cluster_config.0.worker_config.0.machine_type", "n2d-standard-2"),
296+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
297+
"cluster_config.0.worker_config.0.image_uri", imageUri),
298+
resource.TestCheckResourceAttr("google_dataproc_cluster.confidential",
299+
"cluster_config.0.worker_config.0.min_cpu_platform", "AMD Rome"),
300+
),
301+
},
302+
},
303+
})
304+
}
305+
261306
func TestAccDataprocCluster_withMetadataAndTags(t *testing.T) {
262307
t.Parallel()
263308

@@ -1540,6 +1585,36 @@ resource "google_dataproc_cluster" "basic" {
15401585
`, rnd, rnd, rnd, rnd)
15411586
}
15421587

1588+
func testAccDataprocCluster_withConfidentialCompute(rnd, subnetworkName string, imageUri string) string {
1589+
return fmt.Sprintf(`
1590+
resource "google_dataproc_cluster" "confidential" {
1591+
name = "tf-test-dproc-%s"
1592+
region = "us-central1"
1593+
1594+
cluster_config {
1595+
gce_cluster_config {
1596+
subnetwork = "%s"
1597+
confidential_instance_config {
1598+
enable_confidential_compute = true
1599+
}
1600+
}
1601+
1602+
master_config {
1603+
machine_type = "n2d-standard-2"
1604+
image_uri = "%s"
1605+
min_cpu_platform = "AMD Rome"
1606+
}
1607+
1608+
worker_config {
1609+
machine_type = "n2d-standard-2"
1610+
image_uri = "%s"
1611+
min_cpu_platform = "AMD Rome"
1612+
}
1613+
}
1614+
}
1615+
`, rnd, subnetworkName, imageUri, imageUri)
1616+
}
1617+
15431618
func testAccDataprocCluster_withMetadataAndTags(rnd, subnetworkName string) string {
15441619
return fmt.Sprintf(`
15451620
resource "google_dataproc_cluster" "basic" {

website/docs/r/dataproc_cluster.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ resource "google_dataproc_cluster" "accelerated_cluster" {
448448
* `node_group_affinity` - (Optional) Node Group Affinity for sole-tenant clusters.
449449
* `node_group_uri` - (Required) The URI of a sole-tenant node group resource that the cluster will be created on.
450450

451+
* `confidential_instance_config` - (Optional) Confidential Instance Config for clusters using [Confidential VMs](https://cloud.google.com/dataproc/docs/concepts/configuring-clusters/confidential-compute)
452+
* `enable_confidential_compute` - (Optional) Defines whether the instance should have confidential compute enabled.
453+
451454
* `shielded_instance_config` (Optional) Shielded Instance Config for clusters using [Compute Engine Shielded VMs](https://cloud.google.com/security/shielded-cloud/shielded-vm).
452455

453456
- - -

0 commit comments

Comments
 (0)