Skip to content

Commit 539c45c

Browse files
Add confidential nodes support to node pools (#8758) (#6166)
Signed-off-by: Modular Magician <[email protected]>
1 parent fcbc366 commit 539c45c

File tree

4 files changed

+145
-21
lines changed

4 files changed

+145
-21
lines changed

.changelog/8758.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `node_config.confidential_compute` field to `google_container_node_pool` resource
3+
```

google-beta/services/container/node_config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,24 @@ func schemaNodeConfig() *schema.Schema {
611611
},
612612
},
613613
},
614+
"confidential_nodes": {
615+
Type: schema.TypeList,
616+
Optional: true,
617+
Computed: true,
618+
ForceNew: true,
619+
MaxItems: 1,
620+
Description: `Configuration for the confidential nodes feature, which makes nodes run on confidential VMs. Warning: This configuration can't be changed (or added/removed) after pool creation without deleting and recreating the entire pool.`,
621+
Elem: &schema.Resource{
622+
Schema: map[string]*schema.Schema{
623+
"enabled": {
624+
Type: schema.TypeBool,
625+
Required: true,
626+
ForceNew: true,
627+
Description: `Whether Confidential Nodes feature is enabled for all nodes in this pool.`,
628+
},
629+
},
630+
},
631+
},
614632
},
615633
},
616634
}
@@ -885,6 +903,11 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
885903
if v, ok := nodeConfig["host_maintenance_policy"]; ok {
886904
nc.HostMaintenancePolicy = expandHostMaintenancePolicy(v)
887905
}
906+
907+
if v, ok := nodeConfig["confidential_nodes"]; ok {
908+
nc.ConfidentialNodes = expandConfidentialNodes(v)
909+
}
910+
888911
return nc
889912
}
890913

@@ -1000,6 +1023,17 @@ func expandHostMaintenancePolicy(v interface{}) *container.HostMaintenancePolicy
10001023
return mPolicy
10011024
}
10021025

1026+
func expandConfidentialNodes(configured interface{}) *container.ConfidentialNodes {
1027+
l := configured.([]interface{})
1028+
if len(l) == 0 || l[0] == nil {
1029+
return nil
1030+
}
1031+
config := l[0].(map[string]interface{})
1032+
return &container.ConfidentialNodes{
1033+
Enabled: config["enabled"].(bool),
1034+
}
1035+
}
1036+
10031037
func flattenNodeConfigDefaults(c *container.NodeConfigDefaults) []map[string]interface{} {
10041038
result := make([]map[string]interface{}, 0, 1)
10051039

@@ -1049,6 +1083,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} {
10491083
"workload_metadata_config": flattenWorkloadMetadataConfig(c.WorkloadMetadataConfig),
10501084
"sandbox_config": flattenSandboxConfig(c.SandboxConfig),
10511085
"host_maintenance_policy": flattenHostMaintenancePolicy(c.HostMaintenancePolicy),
1086+
"confidential_nodes": flattenConfidentialNodes(c.ConfidentialNodes),
10521087
"boot_disk_kms_key": c.BootDiskKmsKey,
10531088
"kubelet_config": flattenKubeletConfig(c.KubeletConfig),
10541089
"linux_node_config": flattenLinuxNodeConfig(c.LinuxNodeConfig),
@@ -1352,6 +1387,16 @@ func flattenLinuxNodeConfig(c *container.LinuxNodeConfig) []map[string]interface
13521387
return result
13531388
}
13541389

1390+
func flattenConfidentialNodes(c *container.ConfidentialNodes) []map[string]interface{} {
1391+
result := []map[string]interface{}{}
1392+
if c != nil {
1393+
result = append(result, map[string]interface{}{
1394+
"enabled": c.Enabled,
1395+
})
1396+
}
1397+
return result
1398+
}
1399+
13551400
func flattenSoleTenantConfig(c *container.SoleTenantConfig) []map[string]interface{} {
13561401
result := []map[string]interface{}{}
13571402
if c == nil {

google-beta/services/container/resource_container_cluster.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4766,17 +4766,6 @@ func expandBinaryAuthorization(configured interface{}, legacy_enabled bool) *con
47664766
}
47674767
}
47684768

4769-
func expandConfidentialNodes(configured interface{}) *container.ConfidentialNodes {
4770-
l := configured.([]interface{})
4771-
if len(l) == 0 || l[0] == nil {
4772-
return nil
4773-
}
4774-
config := l[0].(map[string]interface{})
4775-
return &container.ConfidentialNodes{
4776-
Enabled: config["enabled"].(bool),
4777-
}
4778-
}
4779-
47804769
func expandMasterAuth(configured interface{}) *container.MasterAuth {
47814770
l := configured.([]interface{})
47824771
if len(l) == 0 || l[0] == nil {
@@ -5299,16 +5288,6 @@ func flattenBinaryAuthorization(c *container.BinaryAuthorization) []map[string]i
52995288
return result
53005289
}
53015290

5302-
func flattenConfidentialNodes(c *container.ConfidentialNodes) []map[string]interface{} {
5303-
result := []map[string]interface{}{}
5304-
if c != nil {
5305-
result = append(result, map[string]interface{}{
5306-
"enabled": c.Enabled,
5307-
})
5308-
}
5309-
return result
5310-
}
5311-
53125291
func flattenNetworkPolicy(c *container.NetworkPolicy) []map[string]interface{} {
53135292
result := []map[string]interface{}{}
53145293
if c != nil {

google-beta/services/container/resource_container_node_pool_test.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,103 @@ resource "google_container_node_pool" "with_sole_tenant_config" {
32603260
`, cluster, np)
32613261
}
32623262

3263+
func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) {
3264+
t.Parallel()
3265+
3266+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
3267+
np := fmt.Sprintf("tf-test-cluster-nodepool-%s", acctest.RandString(t, 10))
3268+
3269+
acctest.VcrTest(t, resource.TestCase{
3270+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3271+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3272+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3273+
Steps: []resource.TestStep{
3274+
{
3275+
Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np),
3276+
},
3277+
{
3278+
ResourceName: "google_container_node_pool.np",
3279+
ImportState: true,
3280+
ImportStateVerify: true,
3281+
},
3282+
{
3283+
Config: testAccContainerNodePool_disableConfidentialNodes(clusterName, np),
3284+
},
3285+
{
3286+
ResourceName: "google_container_node_pool.np",
3287+
ImportState: true,
3288+
ImportStateVerify: true,
3289+
},
3290+
{
3291+
Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np),
3292+
},
3293+
{
3294+
ResourceName: "google_container_node_pool.np",
3295+
ImportState: true,
3296+
ImportStateVerify: true,
3297+
},
3298+
},
3299+
})
3300+
}
3301+
3302+
func testAccContainerNodePool_withConfidentialNodes(clusterName string, np string) string {
3303+
return fmt.Sprintf(`
3304+
resource "google_container_cluster" "cluster" {
3305+
name = "%s"
3306+
location = "asia-east1-c"
3307+
initial_node_count = 1
3308+
node_config {
3309+
confidential_nodes {
3310+
enabled = false
3311+
}
3312+
machine_type = "n2-standard-2"
3313+
}
3314+
}
3315+
3316+
resource "google_container_node_pool" "np" {
3317+
name = "%s"
3318+
location = "asia-east1-c"
3319+
cluster = google_container_cluster.cluster.name
3320+
initial_node_count = 1
3321+
node_config {
3322+
machine_type = "n2d-standard-2" // can't be e2 because Confidential Nodes require AMD CPUs
3323+
confidential_nodes {
3324+
enabled = true
3325+
}
3326+
}
3327+
}
3328+
`, clusterName, np)
3329+
}
3330+
3331+
func testAccContainerNodePool_disableConfidentialNodes(clusterName string, np string) string {
3332+
return fmt.Sprintf(`
3333+
resource "google_container_cluster" "cluster" {
3334+
name = "%s"
3335+
location = "asia-east1-c"
3336+
initial_node_count = 1
3337+
node_config {
3338+
confidential_nodes {
3339+
enabled = false
3340+
}
3341+
machine_type = "n2-standard-2"
3342+
}
3343+
}
3344+
3345+
resource "google_container_node_pool" "np" {
3346+
name = "%s"
3347+
location = "asia-east1-c"
3348+
cluster = google_container_cluster.cluster.name
3349+
initial_node_count = 1
3350+
node_config {
3351+
machine_type = "n2d-standard-2" // can't be e2 because Confidential Nodes require AMD CPUs
3352+
confidential_nodes {
3353+
enabled = false
3354+
}
3355+
}
3356+
}
3357+
`, clusterName, np)
3358+
}
3359+
32633360
func TestAccContainerNodePool_tpuTopology(t *testing.T) {
32643361
t.Parallel()
32653362
acctest.SkipIfVcr(t)

0 commit comments

Comments
 (0)