Skip to content

Commit 6ad4ae1

Browse files
authored
CDPCP-13502 - GCP availability zones cannot be specified (#185)
1 parent b6bc5ca commit 6ad4ae1

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

resources/environments/converter_gcp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func toGcpEnvironmentRequest(ctx context.Context, model *gcpEnvironmentResourceM
3939
Region: model.Region.ValueStringPointer(),
4040
UsePublicIP: model.UsePublicIp.ValueBoolPointer(),
4141
WorkloadAnalytics: model.WorkloadAnalytics.ValueBool(),
42+
AvailabilityZones: utils.FromTfStringSliceToStringSlice(model.AvailabilityZones),
4243
}
4344
if !model.FreeIpa.IsNull() && !model.FreeIpa.IsUnknown() {
4445
trans, _ := FreeIpaModelToRequest(&model.FreeIpa, ctx)

resources/environments/converter_gcp_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ func TestToGcpEnvironmentRequestSecurityAccess(t *testing.T) {
6666
assert.Equal(t, testObject.SecurityAccess.SecurityGroupIdForKnox.ValueString(), result.SecurityAccess.SecurityGroupIDForKnox)
6767
}
6868

69+
func TestToGcpEnvironmentRequestAvailabilityZones(t *testing.T) {
70+
testObject := createFilledGcpEnvironmentResourceModel()
71+
72+
result := toGcpEnvironmentRequest(context.TODO(), testObject)
73+
74+
assert.NotNilf(t, result.AvailabilityZones, "If AvailabilityZones is specified, it is expected to be not nil")
75+
assert.Equal(t, 1, len(testObject.AvailabilityZones))
76+
}
77+
6978
func TestToGcpEnvironmentRequestLogStorage(t *testing.T) {
7079
testObject := createFilledGcpEnvironmentResourceModel()
7180

utils/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ func FromListValueToStringList(tl types.List) []string {
102102
return res
103103
}
104104

105+
func FromTfStringSliceToStringSlice(tss []types.String) []string {
106+
result := make([]string, 0)
107+
for _, az := range tss {
108+
result = append(result, az.ValueString())
109+
}
110+
return result
111+
}
112+
105113
func FromSetValueToStringList(tl types.Set) []string {
106114
if tl.IsNull() {
107115
return []string{}

utils/utils_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,19 @@ func TestGetCallFailureThreshold(t *testing.T) {
330330
})
331331
}
332332
}
333+
334+
func TestFromTfStringSliceToStringSliceIfEmpty(t *testing.T) {
335+
assert.Equal(t, 0, len(FromTfStringSliceToStringSlice([]types.String{})))
336+
}
337+
338+
func TestFromTfStringSliceToStringSliceIfNotEmpty(t *testing.T) {
339+
val := "someValue"
340+
input := []types.String{
341+
types.StringValue(val),
342+
}
343+
344+
result := FromTfStringSliceToStringSlice(input)
345+
346+
assert.Equal(t, len(input), len(result))
347+
assert.Equal(t, val, result[0])
348+
}

0 commit comments

Comments
 (0)