Skip to content

Commit

Permalink
mutate vsphere_config and add host_groups (#9435) (#16896)
Browse files Browse the repository at this point in the history
* mutate vsphere_config and add host_groups

* Fixed config error

* mutate subfields of tags
[upstream:d655f7b6f811bbccaf33ada22291cd920ffe0f5c]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 4, 2024
1 parent e1f23e4 commit 0368b61
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .changelog/9435.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
gkeonprem: set `vsphere_config` field as mutable and add `host_groups` subfield in `google_gkeonprem_vmware_node_pool` resource
```
36 changes: 31 additions & 5 deletions google/services/gkeonprem/resource_gkeonprem_vmware_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,38 @@ and conflicts should be avoided.`,
},
"vsphere_config": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Specifies the vSphere config for node pool.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"datastore": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `The name of the vCenter datastore. Inherited from the user cluster.`,
},
"host_groups": {
Type: schema.TypeList,
Optional: true,
Description: `Vsphere host groups to apply to all VMs in the node pool`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tags": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Tags to apply to VMs.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"category": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `The Vsphere tag category.`,
},
"tag": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `The Vsphere tag name.`,
},
},
Expand Down Expand Up @@ -932,6 +941,8 @@ func flattenGkeonpremVmwareNodePoolConfigVsphereConfig(v interface{}, d *schema.
flattenGkeonpremVmwareNodePoolConfigVsphereConfigDatastore(original["datastore"], d, config)
transformed["tags"] =
flattenGkeonpremVmwareNodePoolConfigVsphereConfigTags(original["tags"], d, config)
transformed["host_groups"] =
flattenGkeonpremVmwareNodePoolConfigVsphereConfigHostGroups(original["hostGroups"], d, config)
return []interface{}{transformed}
}
func flattenGkeonpremVmwareNodePoolConfigVsphereConfigDatastore(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -965,6 +976,10 @@ func flattenGkeonpremVmwareNodePoolConfigVsphereConfigTagsTag(v interface{}, d *
return v
}

func flattenGkeonpremVmwareNodePoolConfigVsphereConfigHostGroups(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenGkeonpremVmwareNodePoolConfigEnableLoadBalancer(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -1292,6 +1307,13 @@ func expandGkeonpremVmwareNodePoolConfigVsphereConfig(v interface{}, d tpgresour
transformed["tags"] = transformedTags
}

transformedHostGroups, err := expandGkeonpremVmwareNodePoolConfigVsphereConfigHostGroups(original["host_groups"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedHostGroups); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["hostGroups"] = transformedHostGroups
}

return transformed, nil
}

Expand Down Expand Up @@ -1336,6 +1358,10 @@ func expandGkeonpremVmwareNodePoolConfigVsphereConfigTagsTag(v interface{}, d tp
return v, nil
}

func expandGkeonpremVmwareNodePoolConfigVsphereConfigHostGroups(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandGkeonpremVmwareNodePoolConfigEnableLoadBalancer(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ resource "google_gkeonprem_vmware_node_pool" "nodepool-full" {
effect = "NO_SCHEDULE"
}
labels = {}
vsphere_config {
datastore = "test-datastore"
tags {
category = "test-category-1"
tag = "tag-1"
}
tags {
category = "test-category-2"
tag = "tag-2"
}
host_groups = ["host1", "host2"]
}
enable_load_balancer = true
}
node_pool_autoscaling {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ func testAccGkeonpremVmwareNodePool_vmwareNodePoolUpdateStart(context map[string
value = "value"
}
labels = {}
vsphere_config {
datastore = "test-datastore"
tags {
category = "test-category-1"
tag = "tag-1"
}
tags {
category = "test-category-2"
tag = "tag-2"
}
host_groups = ["host1", "host2"]
}
enable_load_balancer = true
}
node_pool_autoscaling {
Expand Down Expand Up @@ -179,6 +191,18 @@ func testAccGkeonpremVmwareNodePool_vmwareNodePoolUpdate(context map[string]inte
value = "value-updated"
}
labels = {}
vsphere_config {
datastore = "test-datastore-update"
tags {
category = "test-category-3"
tag = "tag-3"
}
tags {
category = "test-category-4"
tag = "tag-4"
}
host_groups = ["host3", "host4"]
}
enable_load_balancer = false
}
node_pool_autoscaling {
Expand Down
30 changes: 23 additions & 7 deletions website/docs/r/gkeonprem_vmware_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ resource "google_gkeonprem_vmware_node_pool" "nodepool-full" {
effect = "NO_SCHEDULE"
}
labels = {}
vsphere_config {
datastore = "test-datastore"
tags {
category = "test-category-1"
tag = "tag-1"
}
tags {
category = "test-category-2"
tag = "tag-2"
}
host_groups = ["host1", "host2"]
}
enable_load_balancer = true
}
node_pool_autoscaling {
Expand Down Expand Up @@ -214,7 +226,7 @@ The following arguments are supported:
and conflicts should be avoided.

* `vsphere_config` -
(Output)
(Optional)
Specifies the vSphere config for node pool.
Structure is [documented below](#nested_vsphere_config).

Expand All @@ -239,26 +251,30 @@ The following arguments are supported:
Available taint effects.
Possible values are: `EFFECT_UNSPECIFIED`, `NO_SCHEDULE`, `PREFER_NO_SCHEDULE`, `NO_EXECUTE`.

<a name="nested_vsphere_config"></a>The `vsphere_config` block contains:
<a name="nested_vsphere_config"></a>The `vsphere_config` block supports:

* `datastore` -
(Output)
(Optional)
The name of the vCenter datastore. Inherited from the user cluster.

* `tags` -
(Output)
(Optional)
Tags to apply to VMs.
Structure is [documented below](#nested_tags).

* `host_groups` -
(Optional)
Vsphere host groups to apply to all VMs in the node pool


<a name="nested_tags"></a>The `tags` block contains:
<a name="nested_tags"></a>The `tags` block supports:

* `category` -
(Output)
(Optional)
The Vsphere tag category.

* `tag` -
(Output)
(Optional)
The Vsphere tag name.

- - -
Expand Down

0 comments on commit 0368b61

Please sign in to comment.