Skip to content

Commit f78d7a5

Browse files
Add support for shielded instance config on auto provisioned GKE nodes (#6754) (#12930)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent bdd7769 commit f78d7a5

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

.changelog/6754.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: Added support for Shielded Instance configuration for node auto-provisioning to `google_container_cluster`
3+
```

google/resource_container_cluster.go

+39
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,36 @@ func resourceContainerCluster() *schema.Resource {
395395
ForceNew: true,
396396
Description: `The Customer Managed Encryption Key used to encrypt the boot disk attached to each node in the node pool.`,
397397
},
398+
"shielded_instance_config": {
399+
Type: schema.TypeList,
400+
Optional: true,
401+
Description: `Shielded Instance options.`,
402+
MaxItems: 1,
403+
Elem: &schema.Resource{
404+
Schema: map[string]*schema.Schema{
405+
"enable_secure_boot": {
406+
Type: schema.TypeBool,
407+
Optional: true,
408+
Default: false,
409+
Description: `Defines whether the instance has Secure Boot enabled.`,
410+
AtLeastOneOf: []string{
411+
"cluster_autoscaling.0.auto_provisioning_defaults.0.shielded_instance_config.0.enable_secure_boot",
412+
"cluster_autoscaling.0.auto_provisioning_defaults.0.shielded_instance_config.0.enable_integrity_monitoring",
413+
},
414+
},
415+
"enable_integrity_monitoring": {
416+
Type: schema.TypeBool,
417+
Optional: true,
418+
Default: true,
419+
Description: `Defines whether the instance has integrity monitoring enabled.`,
420+
AtLeastOneOf: []string{
421+
"cluster_autoscaling.0.auto_provisioning_defaults.0.shielded_instance_config.0.enable_secure_boot",
422+
"cluster_autoscaling.0.auto_provisioning_defaults.0.shielded_instance_config.0.enable_integrity_monitoring",
423+
},
424+
},
425+
},
426+
},
427+
},
398428
},
399429
},
400430
},
@@ -3180,6 +3210,14 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
31803210
BootDiskKmsKey: config["boot_disk_kms_key"].(string),
31813211
}
31823212

3213+
if v, ok := config["shielded_instance_config"]; ok && len(v.([]interface{})) > 0 {
3214+
conf := v.([]interface{})[0].(map[string]interface{})
3215+
npd.ShieldedInstanceConfig = &container.ShieldedInstanceConfig{
3216+
EnableSecureBoot: conf["enable_secure_boot"].(bool),
3217+
EnableIntegrityMonitoring: conf["enable_integrity_monitoring"].(bool),
3218+
}
3219+
}
3220+
31833221
return npd
31843222
}
31853223

@@ -3944,6 +3982,7 @@ func flattenAutoProvisioningDefaults(a *container.AutoprovisioningNodePoolDefaul
39443982
r["disk_type"] = a.DiskType
39453983
r["image_type"] = a.ImageType
39463984
r["boot_disk_kms_key"] = a.BootDiskKmsKey
3985+
r["shielded_instance_config"] = flattenShieldedInstanceConfig(a.ShieldedInstanceConfig)
39473986

39483987
return []map[string]interface{}{r}
39493988
}

google/resource_container_cluster_test.go

+53
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,29 @@ func TestAccContainerCluster_nodeAutoprovisioningDefaultsBootDiskKmsKey(t *testi
21842184
})
21852185
}
21862186

2187+
func TestAccContainerCluster_nodeAutoprovisioningDefaultsShieldedInstance(t *testing.T) {
2188+
t.Parallel()
2189+
2190+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
2191+
2192+
vcrTest(t, resource.TestCase{
2193+
PreCheck: func() { testAccPreCheck(t) },
2194+
Providers: testAccProviders,
2195+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2196+
Steps: []resource.TestStep{
2197+
{
2198+
Config: testAccContainerCluster_autoprovisioningDefaultsShieldedInstance(clusterName),
2199+
},
2200+
{
2201+
ResourceName: "google_container_cluster.nap_shielded_instance",
2202+
ImportState: true,
2203+
ImportStateVerify: true,
2204+
ImportStateVerifyIgnore: []string{"min_master_version"},
2205+
},
2206+
},
2207+
})
2208+
}
2209+
21872210
func TestAccContainerCluster_errorCleanDanglingCluster(t *testing.T) {
21882211
t.Parallel()
21892212

@@ -4054,6 +4077,36 @@ resource "google_container_cluster" "nap_boot_disk_kms_key" {
40544077
`, project, clusterName, kmsKeyName)
40554078
}
40564079

4080+
func testAccContainerCluster_autoprovisioningDefaultsShieldedInstance(cluster string) string {
4081+
return fmt.Sprintf(`
4082+
data "google_container_engine_versions" "central1a" {
4083+
location = "us-central1-a"
4084+
}
4085+
resource "google_container_cluster" "nap_shielded_instance" {
4086+
name = "%s"
4087+
location = "us-central1-a"
4088+
initial_node_count = 1
4089+
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
4090+
cluster_autoscaling {
4091+
enabled = true
4092+
resource_limits {
4093+
resource_type = "cpu"
4094+
maximum = 2
4095+
}
4096+
resource_limits {
4097+
resource_type = "memory"
4098+
maximum = 2048
4099+
}
4100+
auto_provisioning_defaults {
4101+
shielded_instance_config {
4102+
enable_integrity_monitoring = true
4103+
enable_secure_boot = true
4104+
}
4105+
}
4106+
}
4107+
}`, cluster)
4108+
}
4109+
40574110
func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string {
40584111
return fmt.Sprintf(`
40594112
resource "google_container_cluster" "with_node_pool" {

website/docs/r/container_cluster.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ as "Intel Haswell" or "Intel Sandy Bridge".
517517

518518
* `image_type` - (Optional) The default image type used by NAP once a new node pool is being created. Please note that according to the [official documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/node-auto-provisioning#default-image-type) the value must be one of the [COS_CONTAINERD, COS, UBUNTU_CONTAINERD, UBUNTU]. __NOTE__ : COS AND UBUNTU are deprecated as of `GKE 1.24`
519519

520+
* `shielded_instance_config` - (Optional) Shielded Instance options. Structure is [documented below](#nested_shielded_instance_config).
521+
520522
<a name="nested_authenticator_groups_config"></a>The `authenticator_groups_config` block supports:
521523

522524
* `security_group` - (Required) The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format `[email protected]`.

0 commit comments

Comments
 (0)