Skip to content

Commit 446c4ec

Browse files
megan07modular-magician
authored andcommitted
add node config shielded instance config
Signed-off-by: Modular Magician <[email protected]>
1 parent e116744 commit 446c4ec

File tree

3 files changed

+163
-12
lines changed

3 files changed

+163
-12
lines changed

google/node_config.go

+53-12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ var schemaNodeConfig = &schema.Schema{
147147
Elem: &schema.Schema{Type: schema.TypeString},
148148
},
149149

150+
"shielded_instance_config": {
151+
Type: schema.TypeList,
152+
Optional: true,
153+
MaxItems: 1,
154+
Elem: &schema.Resource{
155+
Schema: map[string]*schema.Schema{
156+
"enable_secure_boot": {
157+
Type: schema.TypeBool,
158+
Optional: true,
159+
Default: false,
160+
},
161+
"enable_integrity_monitoring": {
162+
Type: schema.TypeBool,
163+
Optional: true,
164+
Default: true,
165+
},
166+
},
167+
},
168+
},
169+
150170
"taint": {
151171
Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.",
152172
Type: schema.TypeList,
@@ -301,6 +321,15 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig {
301321
}
302322
nc.Tags = tags
303323
}
324+
325+
if v, ok := nodeConfig["shielded_instance_config"]; ok && len(v.([]interface{})) > 0 {
326+
conf := v.([]interface{})[0].(map[string]interface{})
327+
nc.ShieldedInstanceConfig = &containerBeta.ShieldedInstanceConfig{
328+
EnableSecureBoot: conf["enable_secure_boot"].(bool),
329+
EnableIntegrityMonitoring: conf["enable_integrity_monitoring"].(bool),
330+
}
331+
}
332+
304333
// Preemptible Is Optional+Default, so it always has a value
305334
nc.Preemptible = nodeConfig["preemptible"].(bool)
306335

@@ -319,18 +348,19 @@ func flattenNodeConfig(c *containerBeta.NodeConfig) []map[string]interface{} {
319348
}
320349

321350
config = append(config, map[string]interface{}{
322-
"machine_type": c.MachineType,
323-
"disk_size_gb": c.DiskSizeGb,
324-
"disk_type": c.DiskType,
325-
"guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators),
326-
"local_ssd_count": c.LocalSsdCount,
327-
"service_account": c.ServiceAccount,
328-
"metadata": c.Metadata,
329-
"image_type": c.ImageType,
330-
"labels": c.Labels,
331-
"tags": c.Tags,
332-
"preemptible": c.Preemptible,
333-
"min_cpu_platform": c.MinCpuPlatform,
351+
"machine_type": c.MachineType,
352+
"disk_size_gb": c.DiskSizeGb,
353+
"disk_type": c.DiskType,
354+
"guest_accelerator": flattenContainerGuestAccelerators(c.Accelerators),
355+
"local_ssd_count": c.LocalSsdCount,
356+
"service_account": c.ServiceAccount,
357+
"metadata": c.Metadata,
358+
"image_type": c.ImageType,
359+
"labels": c.Labels,
360+
"tags": c.Tags,
361+
"preemptible": c.Preemptible,
362+
"min_cpu_platform": c.MinCpuPlatform,
363+
"shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig),
334364
})
335365

336366
if len(c.OauthScopes) > 0 {
@@ -351,6 +381,17 @@ func flattenContainerGuestAccelerators(c []*containerBeta.AcceleratorConfig) []m
351381
return result
352382
}
353383

384+
func flattenShieldedInstanceConfig(c *containerBeta.ShieldedInstanceConfig) []map[string]interface{} {
385+
result := []map[string]interface{}{}
386+
if c != nil {
387+
result = append(result, map[string]interface{}{
388+
"enable_secure_boot": c.EnableSecureBoot,
389+
"enable_integrity_monitoring": c.EnableIntegrityMonitoring,
390+
})
391+
}
392+
return result
393+
}
394+
354395
func taintDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
355396
if strings.HasSuffix(k, "#") {
356397
oldCount, oldErr := strconv.Atoi(old)

google/resource_container_cluster_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,29 @@ func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) {
634634
})
635635
}
636636

637+
func TestAccContainerCluster_withNodeConfigShieldedInstanceConfig(t *testing.T) {
638+
t.Parallel()
639+
640+
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
641+
642+
resource.Test(t, resource.TestCase{
643+
PreCheck: func() { testAccPreCheck(t) },
644+
Providers: testAccProviders,
645+
CheckDestroy: testAccCheckContainerClusterDestroy,
646+
Steps: []resource.TestStep{
647+
{
648+
Config: testAccContainerCluster_withNodeConfigShieldedInstanceConfig(clusterName),
649+
},
650+
{
651+
ResourceName: "google_container_cluster.with_node_config",
652+
ImportStateIdPrefix: "us-central1-f/",
653+
ImportState: true,
654+
ImportStateVerify: true,
655+
},
656+
},
657+
})
658+
}
659+
637660
func TestAccContainerCluster_network(t *testing.T) {
638661
t.Parallel()
639662

@@ -1720,6 +1743,47 @@ resource "google_container_cluster" "with_node_config_scope_alias" {
17201743
}`, acctest.RandString(10))
17211744
}
17221745

1746+
func testAccContainerCluster_withNodeConfigShieldedInstanceConfig(clusterName string) string {
1747+
return fmt.Sprintf(`
1748+
resource "google_container_cluster" "with_node_config" {
1749+
name = "%s"
1750+
zone = "us-central1-f"
1751+
initial_node_count = 1
1752+
1753+
node_config {
1754+
machine_type = "n1-standard-1"
1755+
disk_size_gb = 15
1756+
disk_type = "pd-ssd"
1757+
local_ssd_count = 1
1758+
oauth_scopes = [
1759+
"https://www.googleapis.com/auth/monitoring",
1760+
"https://www.googleapis.com/auth/compute",
1761+
"https://www.googleapis.com/auth/devstorage.read_only",
1762+
"https://www.googleapis.com/auth/logging.write"
1763+
]
1764+
service_account = "default"
1765+
metadata = {
1766+
foo = "bar"
1767+
disable-legacy-endpoints = "true"
1768+
}
1769+
labels = {
1770+
foo = "bar"
1771+
}
1772+
tags = ["foo", "bar"]
1773+
preemptible = true
1774+
min_cpu_platform = "Intel Broadwell"
1775+
1776+
// Updatable fields
1777+
image_type = "COS"
1778+
1779+
shielded_instance_config {
1780+
enable_secure_boot = true
1781+
enable_integrity_monitoring = true
1782+
}
1783+
}
1784+
}`, clusterName)
1785+
}
1786+
17231787
func testAccContainerCluster_networkRef() string {
17241788
return fmt.Sprintf(`
17251789
resource "google_compute_network" "container_network" {

google/resource_container_node_pool_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,30 @@ func TestAccContainerNodePool_EmptyGuestAccelerator(t *testing.T) {
510510
})
511511
}
512512

513+
func TestAccContainerNodePool_shieldedInstanceConfig(t *testing.T) {
514+
t.Parallel()
515+
516+
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
517+
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
518+
519+
resource.Test(t, resource.TestCase{
520+
PreCheck: func() { testAccPreCheck(t) },
521+
Providers: testAccProviders,
522+
CheckDestroy: testAccCheckContainerNodePoolDestroy,
523+
Steps: []resource.TestStep{
524+
{
525+
Config: testAccContainerNodePool_shieldedInstanceConfig(cluster, np),
526+
},
527+
{
528+
ResourceName: "google_container_node_pool.np",
529+
ImportState: true,
530+
ImportStateVerify: true,
531+
ImportStateVerifyIgnore: []string{"max_pods_per_node"},
532+
},
533+
},
534+
})
535+
}
536+
513537
func testAccCheckContainerNodePoolDestroy(s *terraform.State) error {
514538
config := testAccProvider.Meta().(*Config)
515539

@@ -1031,3 +1055,25 @@ resource "google_container_node_pool" "np" {
10311055
}
10321056
}`, cluster, np)
10331057
}
1058+
1059+
func testAccContainerNodePool_shieldedInstanceConfig(cluster, np string) string {
1060+
return fmt.Sprintf(`
1061+
resource "google_container_cluster" "cluster" {
1062+
name = "%s"
1063+
location = "us-central1-a"
1064+
initial_node_count = 3
1065+
}
1066+
1067+
resource "google_container_node_pool" "np" {
1068+
name = "%s"
1069+
location = "us-central1-a"
1070+
cluster = "${google_container_cluster.cluster.name}"
1071+
initial_node_count = 2
1072+
node_config {
1073+
shielded_instance_config {
1074+
enable_secure_boot = true
1075+
enable_integrity_monitoring = true
1076+
}
1077+
}
1078+
}`, cluster, np)
1079+
}

0 commit comments

Comments
 (0)