Skip to content

Commit

Permalink
feat(google_container_node_pool): support secondary boot disks
Browse files Browse the repository at this point in the history
  • Loading branch information
elfinhe committed Apr 16, 2024
1 parent 71d5293 commit 34660ed
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mmv1/third_party/terraform/services/container/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,31 @@ func schemaNodeConfig() *schema.Schema {
},
},

"secondary_boot_disks": {
Type: schema.TypeList,
Optional: true,
MaxItems: 127,
Description: `Secondary boot disks for preloading data or container images.`,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"disk_image": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `Disk image to create the secondary boot disk from`,
},
"mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Mode for how the secondary boot disk is used.`,
ValidateFunc: validation.StringInSlice([]string{"CONTAINER_IMAGE_CACHE"}, false),
},
},
},
},

"gcfs_config": schemaGcfsConfig(true),

"gvnic": {
Expand Down Expand Up @@ -809,6 +834,14 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
}
}

if v, ok := nodeConfig["secondary_boot_disks"]; ok && len(v.([]interface{})) > 0 {
conf := v.([]interface{})[0].(map[string]interface{})
nc.SecondaryBootDisks = &container.SecondaryBootDisks{
DiskImage: conf["disk_image"].(string),
Mode: conf["mode"].(string),
}
}

if v, ok := nodeConfig["gcfs_config"]; ok && len(v.([]interface{})) > 0 {
conf := v.([]interface{})[0].(map[string]interface{})
nc.GcfsConfig = &container.GcfsConfig{
Expand Down Expand Up @@ -1213,6 +1246,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
"resource_labels": c.ResourceLabels,
"tags": c.Tags,
"preemptible": c.Preemptible,
"secondary_boot_disks": flattenSecondaryBootDisks(c.SecondaryBootDisks),
"spot": c.Spot,
"min_cpu_platform": c.MinCpuPlatform,
"shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig),
Expand Down Expand Up @@ -1335,6 +1369,17 @@ func flattenEphemeralStorageLocalSsdConfig(c *container.EphemeralStorageLocalSsd
return result
}

func flattenSecondaryBootDisks(c *container.SecondaryBootDisks) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
result = append(result, map[string]interface{}{
"disk_image": c.DiskImage,
"mode": c.Mode,
})
}
return result
}

func flattenLoggingVariant(c *container.NodePoolLoggingConfig) string {
variant := "DEFAULT"
if c != nil && c.VariantConfig != nil && c.VariantConfig.Variant != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,60 @@ resource "google_container_node_pool" "np" {
`, cluster, networkName, subnetworkName, np)
}

func TestAccContainerNodePool_secondaryBootDisks(t *testing.T) {
t.Parallel()

cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10))
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName),
},
resource.TestStep{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccContainerNodePool_secondaryBootDisks(cluster, np, networkName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
deletion_protection = false
network = "%s"
subnetwork = "%s"
}

resource "google_container_node_pool" "np" {
name = "%s"
location = "us-central1-a"
cluster = google_container_cluster.cluster.name
initial_node_count = 1

node_config {
machine_type = "n1-standard-8"
image_type = "COS_CONTAINERD"
secondary_boot_disks {
disk_image = "global/images/container_image_01"
mode = CONTAINER_IMAGE_CACHE
}
}
}
`, cluster, networkName, subnetworkName, np)
}

func TestAccContainerNodePool_gcfsConfig(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 34660ed

Please sign in to comment.