Skip to content

Commit

Permalink
set vcenter field mutable in gkeonprem vmware cluster (#8926) (#6418)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 29, 2023
1 parent aa9bcec commit b8053d2
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .changelog/8926.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
gkeonprem: `vcenter` fields made mutable in `google_gkeonprem_vmware_cluster`
```
217 changes: 167 additions & 50 deletions google-beta/services/gkeonprem/resource_gkeonprem_vmware_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,57 @@ Enabled by default.`,
},
},
},
"vcenter": {
Type: schema.TypeList,
Optional: true,
Description: `VmwareVCenterConfig specifies vCenter config for the user cluster.
Inherited from the admin cluster.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ca_cert_data": {
Type: schema.TypeString,
Optional: true,
Description: `Contains the vCenter CA certificate public key for SSL verification.`,
},
"cluster": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter cluster for the user cluster.`,
},
"datacenter": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter datacenter for the user cluster.`,
},
"datastore": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter datastore for the user cluster.`,
},
"folder": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter folder for the user cluster.`,
},
"resource_pool": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter resource pool for the user cluster.`,
},
"storage_policy_name": {
Type: schema.TypeString,
Optional: true,
Description: `The name of the vCenter storage policy for the user cluster.`,
},
"address": {
Type: schema.TypeString,
Computed: true,
Description: `The vCenter IP address.`,
},
},
},
},
"vm_tracking_enabled": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -830,56 +881,6 @@ indicate real problems requiring user intervention.`,
},
},
},
"vcenter": {
Type: schema.TypeList,
Computed: true,
Description: `VmwareVCenterConfig specifies vCenter config for the user cluster.
Inherited from the admin cluster.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Computed: true,
Description: `The vCenter IP address.`,
},
"ca_cert_data": {
Type: schema.TypeString,
Computed: true,
Description: `Contains the vCenter CA certificate public key for SSL verification.`,
},
"cluster": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter cluster for the user cluster.`,
},
"datacenter": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter datacenter for the user cluster.`,
},
"datastore": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter datastore for the user cluster.`,
},
"folder": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter folder for the user cluster.`,
},
"resource_pool": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter resource pool for the user cluster.`,
},
"storage_policy_name": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the vCenter storage policy for the user cluster.`,
},
},
},
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -983,6 +984,12 @@ func resourceGkeonpremVmwareClusterCreate(d *schema.ResourceData, meta interface
} else if v, ok := d.GetOkExists("upgrade_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(upgradePolicyProp)) && (ok || !reflect.DeepEqual(v, upgradePolicyProp)) {
obj["upgradePolicy"] = upgradePolicyProp
}
vcenterProp, err := expandGkeonpremVmwareClusterVcenter(d.Get("vcenter"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("vcenter"); !tpgresource.IsEmptyValue(reflect.ValueOf(vcenterProp)) && (ok || !reflect.DeepEqual(v, vcenterProp)) {
obj["vcenter"] = vcenterProp
}
annotationsProp, err := expandGkeonpremVmwareClusterEffectiveAnnotations(d.Get("effective_annotations"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1276,6 +1283,12 @@ func resourceGkeonpremVmwareClusterUpdate(d *schema.ResourceData, meta interface
} else if v, ok := d.GetOkExists("upgrade_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, upgradePolicyProp)) {
obj["upgradePolicy"] = upgradePolicyProp
}
vcenterProp, err := expandGkeonpremVmwareClusterVcenter(d.Get("vcenter"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("vcenter"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, vcenterProp)) {
obj["vcenter"] = vcenterProp
}
annotationsProp, err := expandGkeonpremVmwareClusterEffectiveAnnotations(d.Get("effective_annotations"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1343,6 +1356,10 @@ func resourceGkeonpremVmwareClusterUpdate(d *schema.ResourceData, meta interface
updateMask = append(updateMask, "upgradePolicy")
}

if d.HasChange("vcenter") {
updateMask = append(updateMask, "vcenter")
}

if d.HasChange("effective_annotations") {
updateMask = append(updateMask, "annotations")
}
Expand Down Expand Up @@ -3327,6 +3344,106 @@ func expandGkeonpremVmwareClusterUpgradePolicyControlPlaneOnly(v interface{}, d
return v, nil
}

func expandGkeonpremVmwareClusterVcenter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedResourcePool, err := expandGkeonpremVmwareClusterVcenterResourcePool(original["resource_pool"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedResourcePool); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["resourcePool"] = transformedResourcePool
}

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

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

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

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

transformedCaCertData, err := expandGkeonpremVmwareClusterVcenterCaCertData(original["ca_cert_data"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedCaCertData); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["caCertData"] = transformedCaCertData
}

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

transformedStoragePolicyName, err := expandGkeonpremVmwareClusterVcenterStoragePolicyName(original["storage_policy_name"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedStoragePolicyName); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["storagePolicyName"] = transformedStoragePolicyName
}

return transformed, nil
}

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

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

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

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

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

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

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

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

func expandGkeonpremVmwareClusterEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ resource "google_gkeonprem_vmware_cluster" "cluster-manuallb" {
konnectivity_server_node_port = 30008
}
}
vcenter {
resource_pool = "test-resource-pool"
datastore = "test-datastore"
datacenter = "test-datacenter"
cluster = "test-cluster"
folder = "test-folder"
ca_cert_data = "test-ca-cert-data"
storage_policy_name = "test-storage-policy-name"
}
dataplane_v2 {
dataplane_v2_enabled = true
windows_dataplane_v2_enabled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ func testAccGkeonpremVmwareCluster_vmwareClusterUpdateManualLbStart(context map[
konnectivity_server_node_port = 30008
}
}
vcenter {
resource_pool = "test-resource-pool"
datastore = "test-datastore"
datacenter = "test-datacenter"
cluster = "test-cluster"
folder = "test-folder"
ca_cert_data = "test-ca-cert-data"
storage_policy_name = "test-storage-policy-name"
}
dataplane_v2 {
dataplane_v2_enabled = true
windows_dataplane_v2_enabled = true
Expand Down Expand Up @@ -452,6 +461,15 @@ func testAccGkeonpremVmwareCluster_vmwareClusterUpdateManualLb(context map[strin
konnectivity_server_node_port = 30009
}
}
vcenter {
resource_pool = "test-resource-pool-updated"
datastore = "test-datastore-updated"
datacenter = "test-datacenter-updated"
cluster = "test-cluster-updated"
folder = "test-folder-updated"
ca_cert_data = "test-ca-cert-data-updated"
storage_policy_name = "test-storage-policy-name-updated"
}
dataplane_v2 {
dataplane_v2_enabled = true
windows_dataplane_v2_enabled = true
Expand Down
Loading

0 comments on commit b8053d2

Please sign in to comment.