Skip to content

Commit 28e14fe

Browse files
Fix Stretch Private Cloud creation in vmwareengine (#10443) (#17875)
[upstream:71d5293f31bbbbd98a7e073050e4f52e092fa964] Signed-off-by: Modular Magician <[email protected]>
1 parent d27b66c commit 28e14fe

File tree

3 files changed

+99
-59
lines changed

3 files changed

+99
-59
lines changed

.changelog/10443.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: bug
2+
vmwareengine: fixed stretched cluster creation in `google_vmwareengine_private_cloud`
3+
```

google/services/vmwareengine/resource_vmwareengine_private_cloud.go

+81-51
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ This cannot be changed once the PrivateCloud is created.`,
113113
},
114114
},
115115
},
116+
"stretched_cluster_config": {
117+
Type: schema.TypeList,
118+
Optional: true,
119+
Description: `The stretched cluster configuration for the private cloud.`,
120+
MaxItems: 1,
121+
Elem: &schema.Resource{
122+
Schema: map[string]*schema.Schema{
123+
"preferred_location": {
124+
Type: schema.TypeString,
125+
Optional: true,
126+
Description: `Zone that will remain operational when connection between the two zones is lost.`,
127+
},
128+
"secondary_location": {
129+
Type: schema.TypeString,
130+
Optional: true,
131+
Description: `Additional zone for a higher level of availability and load balancing.`,
132+
},
133+
},
134+
},
135+
},
116136
},
117137
},
118138
},
@@ -171,16 +191,6 @@ the form: projects/{project_number}/locations/{location}/vmwareEngineNetworks/{v
171191
Optional: true,
172192
Description: `User-provided description for this private cloud.`,
173193
},
174-
"preferred_zone": {
175-
Type: schema.TypeString,
176-
Optional: true,
177-
Description: `The preferred single failure domain within a region.`,
178-
},
179-
"secondary_zone": {
180-
Type: schema.TypeString,
181-
Optional: true,
182-
Description: `The secondary single failure domain within a region.`,
183-
},
184194
"type": {
185195
Type: schema.TypeString,
186196
Optional: true,
@@ -332,18 +342,6 @@ func resourceVmwareenginePrivateCloudCreate(d *schema.ResourceData, meta interfa
332342
} else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) {
333343
obj["type"] = typeProp
334344
}
335-
preferredZoneProp, err := expandVmwareenginePrivateCloudPreferredZone(d.Get("preferred_zone"), d, config)
336-
if err != nil {
337-
return err
338-
} else if v, ok := d.GetOkExists("preferred_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(preferredZoneProp)) && (ok || !reflect.DeepEqual(v, preferredZoneProp)) {
339-
obj["preferredZone"] = preferredZoneProp
340-
}
341-
secondaryZoneProp, err := expandVmwareenginePrivateCloudSecondaryZone(d.Get("secondary_zone"), d, config)
342-
if err != nil {
343-
return err
344-
} else if v, ok := d.GetOkExists("secondary_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(secondaryZoneProp)) && (ok || !reflect.DeepEqual(v, secondaryZoneProp)) {
345-
obj["secondaryZone"] = secondaryZoneProp
346-
}
347345

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

491483
return nil
492484
}
@@ -519,18 +511,6 @@ func resourceVmwareenginePrivateCloudUpdate(d *schema.ResourceData, meta interfa
519511
} else if v, ok := d.GetOkExists("management_cluster"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, managementClusterProp)) {
520512
obj["managementCluster"] = managementClusterProp
521513
}
522-
preferredZoneProp, err := expandVmwareenginePrivateCloudPreferredZone(d.Get("preferred_zone"), d, config)
523-
if err != nil {
524-
return err
525-
} else if v, ok := d.GetOkExists("preferred_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, preferredZoneProp)) {
526-
obj["preferredZone"] = preferredZoneProp
527-
}
528-
secondaryZoneProp, err := expandVmwareenginePrivateCloudSecondaryZone(d.Get("secondary_zone"), d, config)
529-
if err != nil {
530-
return err
531-
} else if v, ok := d.GetOkExists("secondary_zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, secondaryZoneProp)) {
532-
obj["secondaryZone"] = secondaryZoneProp
533-
}
534514

535515
obj, err = resourceVmwareenginePrivateCloudUpdateEncoder(d, meta, obj)
536516
if err != nil {
@@ -828,6 +808,8 @@ func flattenVmwareenginePrivateCloudManagementCluster(v interface{}, d *schema.R
828808
flattenVmwareenginePrivateCloudManagementClusterClusterId(original["clusterId"], d, config)
829809
transformed["node_type_configs"] =
830810
flattenVmwareenginePrivateCloudManagementClusterNodeTypeConfigs(original["nodeTypeConfigs"], d, config)
811+
transformed["stretched_cluster_config"] =
812+
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(original["stretchedClusterConfig"], d, config)
831813
return []interface{}{transformed}
832814
}
833815
func flattenVmwareenginePrivateCloudManagementClusterClusterId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -884,6 +866,29 @@ func flattenVmwareenginePrivateCloudManagementClusterNodeTypeConfigsCustomCoreCo
884866
return v // let terraform core handle it otherwise
885867
}
886868

869+
func flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
870+
if v == nil {
871+
return nil
872+
}
873+
original := v.(map[string]interface{})
874+
if len(original) == 0 {
875+
return nil
876+
}
877+
transformed := make(map[string]interface{})
878+
transformed["preferred_location"] =
879+
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(original["preferredLocation"], d, config)
880+
transformed["secondary_location"] =
881+
flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigSecondaryLocation(original["secondaryLocation"], d, config)
882+
return []interface{}{transformed}
883+
}
884+
func flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
885+
return v
886+
}
887+
888+
func flattenVmwareenginePrivateCloudManagementClusterStretchedClusterConfigSecondaryLocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
889+
return v
890+
}
891+
887892
func flattenVmwareenginePrivateCloudHcx(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
888893
if v == nil {
889894
return nil
@@ -989,14 +994,6 @@ func flattenVmwareenginePrivateCloudVcenterFqdn(v interface{}, d *schema.Resourc
989994
return v
990995
}
991996

992-
func flattenVmwareenginePrivateCloudPreferredZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
993-
return v
994-
}
995-
996-
func flattenVmwareenginePrivateCloudSecondaryZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
997-
return v
998-
}
999-
1000997
func expandVmwareenginePrivateCloudDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1001998
return v, nil
1002999
}
@@ -1091,6 +1088,13 @@ func expandVmwareenginePrivateCloudManagementCluster(v interface{}, d tpgresourc
10911088
transformed["nodeTypeConfigs"] = transformedNodeTypeConfigs
10921089
}
10931090

1091+
transformedStretchedClusterConfig, err := expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(original["stretched_cluster_config"], d, config)
1092+
if err != nil {
1093+
return nil, err
1094+
} else if val := reflect.ValueOf(transformedStretchedClusterConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1095+
transformed["stretchedClusterConfig"] = transformedStretchedClusterConfig
1096+
}
1097+
10941098
return transformed, nil
10951099
}
10961100

@@ -1138,15 +1142,41 @@ func expandVmwareenginePrivateCloudManagementClusterNodeTypeConfigsCustomCoreCou
11381142
return v, nil
11391143
}
11401144

1141-
func expandVmwareenginePrivateCloudType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1145+
func expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1146+
l := v.([]interface{})
1147+
if len(l) == 0 || l[0] == nil {
1148+
return nil, nil
1149+
}
1150+
raw := l[0]
1151+
original := raw.(map[string]interface{})
1152+
transformed := make(map[string]interface{})
1153+
1154+
transformedPreferredLocation, err := expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(original["preferred_location"], d, config)
1155+
if err != nil {
1156+
return nil, err
1157+
} else if val := reflect.ValueOf(transformedPreferredLocation); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1158+
transformed["preferredLocation"] = transformedPreferredLocation
1159+
}
1160+
1161+
transformedSecondaryLocation, err := expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfigSecondaryLocation(original["secondary_location"], d, config)
1162+
if err != nil {
1163+
return nil, err
1164+
} else if val := reflect.ValueOf(transformedSecondaryLocation); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1165+
transformed["secondaryLocation"] = transformedSecondaryLocation
1166+
}
1167+
1168+
return transformed, nil
1169+
}
1170+
1171+
func expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfigPreferredLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
11421172
return v, nil
11431173
}
11441174

1145-
func expandVmwareenginePrivateCloudPreferredZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1175+
func expandVmwareenginePrivateCloudManagementClusterStretchedClusterConfigSecondaryLocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
11461176
return v, nil
11471177
}
11481178

1149-
func expandVmwareenginePrivateCloudSecondaryZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1179+
func expandVmwareenginePrivateCloudType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
11501180
return v, nil
11511181
}
11521182

website/docs/r/vmwareengine_private_cloud.html.markdown

+15-8
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ The following arguments are supported:
158158
where the key is canonical identifier of the node type (corresponds to the NodeType).
159159
Structure is [documented below](#nested_node_type_configs).
160160

161+
* `stretched_cluster_config` -
162+
(Optional)
163+
The stretched cluster configuration for the private cloud.
164+
Structure is [documented below](#nested_stretched_cluster_config).
165+
161166

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

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

182+
<a name="nested_stretched_cluster_config"></a>The `stretched_cluster_config` block supports:
183+
184+
* `preferred_location` -
185+
(Optional)
186+
Zone that will remain operational when connection between the two zones is lost.
187+
188+
* `secondary_location` -
189+
(Optional)
190+
Additional zone for a higher level of availability and load balancing.
191+
177192
- - -
178193

179194

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

189-
* `preferred_zone` -
190-
(Optional)
191-
The preferred single failure domain within a region.
192-
193-
* `secondary_zone` -
194-
(Optional)
195-
The secondary single failure domain within a region.
196-
197204
* `project` - (Optional) The ID of the project in which the resource belongs.
198205
If it is not provided, the provider project is used.
199206

0 commit comments

Comments
 (0)