Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Stretch Private Cloud creation in vmwareengine #17875

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10443.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note: bug
vmwareengine: fixed stretched cluster creation in `google_vmwareengine_private_cloud`
```
132 changes: 81 additions & 51 deletions google/services/vmwareengine/resource_vmwareengine_private_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ This cannot be changed once the PrivateCloud is created.`,
},
},
},
"stretched_cluster_config": {
Type: schema.TypeList,
Optional: true,
Description: `The stretched cluster configuration for the private cloud.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"preferred_location": {
Type: schema.TypeString,
Optional: true,
Description: `Zone that will remain operational when connection between the two zones is lost.`,
},
"secondary_location": {
Type: schema.TypeString,
Optional: true,
Description: `Additional zone for a higher level of availability and load balancing.`,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -171,16 +191,6 @@ the form: projects/{project_number}/locations/{location}/vmwareEngineNetworks/{v
Optional: true,
Description: `User-provided description for this private cloud.`,
},
"preferred_zone": {
Type: schema.TypeString,
Optional: true,
Description: `The preferred single failure domain within a region.`,
},
"secondary_zone": {
Type: schema.TypeString,
Optional: true,
Description: `The secondary single failure domain within a region.`,
},
"type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -332,18 +342,6 @@ func resourceVmwareenginePrivateCloudCreate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
obj["type"] = typeProp
}
preferredZoneProp, err := expandVmwareenginePrivateCloudPreferredZone(d.Get("preferred_zone"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("preferred_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(preferredZoneProp)) && (ok || !reflect.DeepEqual(v, preferredZoneProp)) {
obj["preferredZone"] = preferredZoneProp
}
secondaryZoneProp, err := expandVmwareenginePrivateCloudSecondaryZone(d.Get("secondary_zone"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("secondary_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(secondaryZoneProp)) && (ok || !reflect.DeepEqual(v, secondaryZoneProp)) {
obj["secondaryZone"] = secondaryZoneProp
}

url, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}projects/{{project}}/locations/{{location}}/privateClouds?privateCloudId={{name}}")
if err != nil {
Expand Down Expand Up @@ -481,12 +479,6 @@ func resourceVmwareenginePrivateCloudRead(d *schema.ResourceData, meta interface
if err := d.Set("vcenter", flattenVmwareenginePrivateCloudVcenter(res["vcenter"], d, config)); err != nil {
return fmt.Errorf("Error reading PrivateCloud: %s", err)
}
if err := d.Set("preferred_zone", flattenVmwareenginePrivateCloudPreferredZone(res["preferredZone"], d, config)); err != nil {
return fmt.Errorf("Error reading PrivateCloud: %s", err)
}
if err := d.Set("secondary_zone", flattenVmwareenginePrivateCloudSecondaryZone(res["secondaryZone"], d, config)); err != nil {
return fmt.Errorf("Error reading PrivateCloud: %s", err)
}

return nil
}
Expand Down Expand Up @@ -519,18 +511,6 @@ func resourceVmwareenginePrivateCloudUpdate(d *schema.ResourceData, meta interfa
} else if v, ok := d.GetOkExists("management_cluster"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, managementClusterProp)) {
obj["managementCluster"] = managementClusterProp
}
preferredZoneProp, err := expandVmwareenginePrivateCloudPreferredZone(d.Get("preferred_zone"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("preferred_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, preferredZoneProp)) {
obj["preferredZone"] = preferredZoneProp
}
secondaryZoneProp, err := expandVmwareenginePrivateCloudSecondaryZone(d.Get("secondary_zone"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("secondary_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, secondaryZoneProp)) {
obj["secondaryZone"] = secondaryZoneProp
}

obj, err = resourceVmwareenginePrivateCloudUpdateEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -828,6 +808,8 @@ func flattenVmwareenginePrivateCloudManagementCluster(v interface{}, d *schema.R
flattenVmwareenginePrivateCloudManagementClusterClusterId(original["clusterId"], d, config)
transformed["node_type_configs"] =
flattenVmwareenginePrivateCloudManagementClusterNodeTypeConfigs(original["nodeTypeConfigs"], d, config)
transformed["stretched_cluster_config"] =
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(original["stretchedClusterConfig"], d, config)
return []interface{}{transformed}
}
func flattenVmwareenginePrivateCloudManagementClusterClusterId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
Expand Down Expand Up @@ -884,6 +866,29 @@ func flattenVmwareenginePrivateCloudManagementClusterNodeTypeConfigsCustomCoreCo
return v // let terraform core handle it otherwise
}

func flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["preferred_location"] =
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(original["preferredLocation"], d, config)
transformed["secondary_location"] =
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigSecondaryLocation(original["secondaryLocation"], d, config)
return []interface{}{transformed}
}
func flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

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

func flattenVmwareenginePrivateCloudHcx(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -989,14 +994,6 @@ func flattenVmwareenginePrivateCloudVcenterFqdn(v interface{}, d *schema.Resourc
return v
}

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

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

func expandVmwareenginePrivateCloudDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -1091,6 +1088,13 @@ func expandVmwareenginePrivateCloudManagementCluster(v interface{}, d tpgresourc
transformed["nodeTypeConfigs"] = transformedNodeTypeConfigs
}

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

return transformed, nil
}

Expand Down Expand Up @@ -1138,15 +1142,41 @@ func expandVmwareenginePrivateCloudManagementClusterNodeTypeConfigsCustomCoreCou
return v, nil
}

func expandVmwareenginePrivateCloudType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
func expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(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{})

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

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

return transformed, nil
}

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

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

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

Expand Down
23 changes: 15 additions & 8 deletions website/docs/r/vmwareengine_private_cloud.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ The following arguments are supported:
where the key is canonical identifier of the node type (corresponds to the NodeType).
Structure is [documented below](#nested_node_type_configs).

* `stretched_cluster_config` -
(Optional)
The stretched cluster configuration for the private cloud.
Structure is [documented below](#nested_stretched_cluster_config).


<a name="nested_node_type_configs"></a>The `node_type_configs` block supports:

Expand All @@ -174,6 +179,16 @@ The following arguments are supported:
If zero is provided max value from `nodeType.availableCustomCoreCounts` will be used.
This cannot be changed once the PrivateCloud is created.

<a name="nested_stretched_cluster_config"></a>The `stretched_cluster_config` block supports:

* `preferred_location` -
(Optional)
Zone that will remain operational when connection between the two zones is lost.

* `secondary_location` -
(Optional)
Additional zone for a higher level of availability and load balancing.

- - -


Expand All @@ -186,14 +201,6 @@ The following arguments are supported:
Initial type of the private cloud.
Possible values are: `STANDARD`, `TIME_LIMITED`, `STRETCHED`.

* `preferred_zone` -
(Optional)
The preferred single failure domain within a region.

* `secondary_zone` -
(Optional)
The secondary single failure domain within a region.

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

Expand Down