Skip to content

Commit 3539158

Browse files
Adding 'management' attribute to the google_container_cluster resource (#6794) (#12987)
* Adding 'management' attribute to the google_container_cluster resource * Addressing minor review comments * Fixing typo * Removing unintended spaces Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 57fdba5 commit 3539158

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

.changelog/6794.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: Adding management attribute to the google_container_cluster resource
3+
```

google/resource_container_cluster.go

+99
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,48 @@ func resourceContainerCluster() *schema.Resource {
517517
},
518518
},
519519
},
520+
"management": {
521+
Type: schema.TypeList,
522+
Optional: true,
523+
Computed: true,
524+
MaxItems: 1,
525+
Description: `NodeManagement configuration for this NodePool.`,
526+
Elem: &schema.Resource{
527+
Schema: map[string]*schema.Schema{
528+
"auto_upgrade": {
529+
Type: schema.TypeBool,
530+
Optional: true,
531+
Computed: true,
532+
Description: `Specifies whether node auto-upgrade is enabled for the node pool. If enabled, node auto-upgrade helps keep the nodes in your node pool up to date with the latest release version of Kubernetes.`,
533+
},
534+
"auto_repair": {
535+
Type: schema.TypeBool,
536+
Optional: true,
537+
Computed: true,
538+
Description: `Specifies whether the node auto-repair is enabled for the node pool. If enabled, the nodes in this node pool will be monitored and, if they fail health checks too many times, an automatic repair action will be triggered.`,
539+
},
540+
"upgrade_options": {
541+
Type: schema.TypeList,
542+
Computed: true,
543+
Description: `Specifies the Auto Upgrade knobs for the node pool.`,
544+
Elem: &schema.Resource{
545+
Schema: map[string]*schema.Schema{
546+
"auto_upgrade_start_time": {
547+
Type: schema.TypeString,
548+
Computed: true,
549+
Description: `This field is set when upgrades are about to commence with the approximate start time for the upgrades, in RFC3339 text format.`,
550+
},
551+
"description": {
552+
Type: schema.TypeString,
553+
Computed: true,
554+
Description: `This field is set when upgrades are about to commence with the description of the upgrade.`,
555+
},
556+
},
557+
},
558+
},
559+
},
560+
},
561+
},
520562
},
521563
},
522564
},
@@ -3301,6 +3343,7 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
33013343
ImageType: config["image_type"].(string),
33023344
BootDiskKmsKey: config["boot_disk_kms_key"].(string),
33033345
UpgradeSettings: expandUpgradeSettings(config["upgrade_settings"]),
3346+
Management: expandManagement(config["management"]),
33043347
}
33053348

33063349
if v, ok := config["shielded_instance_config"]; ok && len(v.([]interface{})) > 0 {
@@ -3321,6 +3364,37 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
33213364
return npd
33223365
}
33233366

3367+
func expandManagement(configured interface{}) *container.NodeManagement {
3368+
l, ok := configured.([]interface{})
3369+
if !ok || l == nil || len(l) == 0 || l[0] == nil {
3370+
return &container.NodeManagement{}
3371+
}
3372+
config := l[0].(map[string]interface{})
3373+
3374+
mng := &container.NodeManagement{
3375+
AutoUpgrade: config["auto_upgrade"].(bool),
3376+
AutoRepair: config["auto_repair"].(bool),
3377+
UpgradeOptions: expandUpgradeOptions(config["upgrade_options"]),
3378+
}
3379+
3380+
return mng
3381+
}
3382+
3383+
func expandUpgradeOptions(configured interface{}) *container.AutoUpgradeOptions {
3384+
l, ok := configured.([]interface{})
3385+
if !ok || l == nil || len(l) == 0 || l[0] == nil {
3386+
return &container.AutoUpgradeOptions{}
3387+
}
3388+
config := l[0].(map[string]interface{})
3389+
3390+
upgradeOptions := &container.AutoUpgradeOptions{
3391+
AutoUpgradeStartTime: config["auto_upgrade_start_time"].(string),
3392+
Description: config["description"].(string),
3393+
}
3394+
3395+
return upgradeOptions
3396+
}
3397+
33243398
func expandUpgradeSettings(configured interface{}) *container.UpgradeSettings {
33253399
l, ok := configured.([]interface{})
33263400
if !ok || l == nil || len(l) == 0 || l[0] == nil {
@@ -4133,6 +4207,31 @@ func flattenAutoProvisioningDefaults(a *container.AutoprovisioningNodePoolDefaul
41334207
r["boot_disk_kms_key"] = a.BootDiskKmsKey
41344208
r["shielded_instance_config"] = flattenShieldedInstanceConfig(a.ShieldedInstanceConfig)
41354209
r["upgrade_settings"] = flattenUpgradeSettings(a.UpgradeSettings)
4210+
r["management"] = flattenManagement(a.Management)
4211+
4212+
return []map[string]interface{}{r}
4213+
}
4214+
4215+
func flattenManagement(a *container.NodeManagement) []map[string]interface{} {
4216+
if a == nil {
4217+
return nil
4218+
}
4219+
r := make(map[string]interface{})
4220+
r["auto_upgrade"] = a.AutoUpgrade
4221+
r["auto_repair"] = a.AutoRepair
4222+
r["upgrade_options"] = flattenUpgradeOptions(a.UpgradeOptions)
4223+
4224+
return []map[string]interface{}{r}
4225+
}
4226+
4227+
func flattenUpgradeOptions(a *container.AutoUpgradeOptions) []map[string]interface{} {
4228+
if a == nil {
4229+
return nil
4230+
}
4231+
4232+
r := make(map[string]interface{})
4233+
r["auto_upgrade_start_time"] = a.AutoUpgradeStartTime
4234+
r["description"] = a.Description
41364235

41374236
return []map[string]interface{}{r}
41384237
}

google/resource_container_cluster_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,38 @@ func TestAccContainerCluster_nodeAutoprovisioningDefaultsShieldedInstance(t *tes
22262226
})
22272227
}
22282228

2229+
func TestAccContainerCluster_autoprovisioningDefaultsManagement(t *testing.T) {
2230+
t.Parallel()
2231+
2232+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
2233+
2234+
vcrTest(t, resource.TestCase{
2235+
PreCheck: func() { testAccPreCheck(t) },
2236+
Providers: testAccProviders,
2237+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2238+
Steps: []resource.TestStep{
2239+
{
2240+
Config: testAccContainerCluster_autoprovisioningDefaultsManagement(clusterName, false, false),
2241+
},
2242+
{
2243+
ResourceName: "google_container_cluster.with_autoprovisioning_management",
2244+
ImportState: true,
2245+
ImportStateVerify: true,
2246+
ImportStateVerifyIgnore: []string{"min_master_version"},
2247+
},
2248+
{
2249+
Config: testAccContainerCluster_autoprovisioningDefaultsManagement(clusterName, true, true),
2250+
},
2251+
{
2252+
ResourceName: "google_container_cluster.with_autoprovisioning_management",
2253+
ImportState: true,
2254+
ImportStateVerify: true,
2255+
ImportStateVerifyIgnore: []string{"min_master_version"},
2256+
},
2257+
},
2258+
})
2259+
}
2260+
22292261
func TestAccContainerCluster_autoprovisioningDefaultsUpgradeSettings(t *testing.T) {
22302262
t.Parallel()
22312263

@@ -3767,6 +3799,37 @@ resource "google_container_cluster" "with_net_ref_by_name" {
37673799
`, network, cluster, cluster)
37683800
}
37693801

3802+
func testAccContainerCluster_autoprovisioningDefaultsManagement(clusterName string, autoUpgrade, autoRepair bool) string {
3803+
return fmt.Sprintf(`
3804+
resource "google_container_cluster" "with_autoprovisioning_management" {
3805+
name = "%s"
3806+
location = "us-central1-f"
3807+
initial_node_count = 1
3808+
3809+
cluster_autoscaling {
3810+
enabled = true
3811+
3812+
resource_limits {
3813+
resource_type = "cpu"
3814+
maximum = 2
3815+
}
3816+
3817+
resource_limits {
3818+
resource_type = "memory"
3819+
maximum = 2048
3820+
}
3821+
3822+
auto_provisioning_defaults {
3823+
management {
3824+
auto_upgrade = %t
3825+
auto_repair = %t
3826+
}
3827+
}
3828+
}
3829+
}
3830+
`, clusterName, autoUpgrade, autoRepair)
3831+
}
3832+
37703833
func testAccContainerCluster_backendRef(cluster string) string {
37713834
return fmt.Sprintf(`
37723835
resource "google_compute_backend_service" "my-backend-service" {

website/docs/r/container_cluster.html.markdown

+12
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ as "Intel Haswell" or "Intel Sandy Bridge".
519519

520520
* `shielded_instance_config` - (Optional) Shielded Instance options. Structure is [documented below](#nested_shielded_instance_config).
521521

522+
* `management` - (Optional) NodeManagement configuration for this NodePool. Structure is [documented below](#nested_management).
523+
524+
<a name="nested_management"></a>The `management` block supports:
525+
526+
* `auto_upgrade` - (Optional) Specifies whether node auto-upgrade is enabled for the node pool. If enabled, node auto-upgrade helps keep the nodes in your node pool up to date with the latest release version of Kubernetes.
527+
528+
* `auto_repair` - (Optional) Specifies whether the node auto-repair is enabled for the node pool. If enabled, the nodes in this node pool will be monitored and, if they fail health checks too many times, an automatic repair action will be triggered.
529+
530+
This block also contains several computed attributes, documented below.
531+
522532
* `upgrade_settings` - (Optional) Specifies the upgrade settings for NAP created node pools. Structure is [documented below](#nested_upgrade_settings).
523533

524534
<a name="nested_upgrade_settings"></a>The `upgrade_settings` block supports:
@@ -1158,6 +1168,8 @@ exported:
11581168
notation (e.g. `1.2.3.4/29`). Service addresses are typically put in the last
11591169
`/16` from the container CIDR.
11601170

1171+
* `cluster_autoscaling.0.auto_provisioning_defaults.0.management.0.upgrade_options` - Specifies the [Auto Upgrade knobs](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/NodeManagement#AutoUpgradeOptions) for the node pool.
1172+
11611173
## Timeouts
11621174

11631175
This resource provides the following

0 commit comments

Comments
 (0)