Skip to content

Commit

Permalink
CDPCP-13502 - GCP availability zones cannot be specified (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregito authored Dec 4, 2024
1 parent b6bc5ca commit 6ad4ae1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions resources/environments/converter_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func toGcpEnvironmentRequest(ctx context.Context, model *gcpEnvironmentResourceM
Region: model.Region.ValueStringPointer(),
UsePublicIP: model.UsePublicIp.ValueBoolPointer(),
WorkloadAnalytics: model.WorkloadAnalytics.ValueBool(),
AvailabilityZones: utils.FromTfStringSliceToStringSlice(model.AvailabilityZones),
}
if !model.FreeIpa.IsNull() && !model.FreeIpa.IsUnknown() {
trans, _ := FreeIpaModelToRequest(&model.FreeIpa, ctx)
Expand Down
9 changes: 9 additions & 0 deletions resources/environments/converter_gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func TestToGcpEnvironmentRequestSecurityAccess(t *testing.T) {
assert.Equal(t, testObject.SecurityAccess.SecurityGroupIdForKnox.ValueString(), result.SecurityAccess.SecurityGroupIDForKnox)
}

func TestToGcpEnvironmentRequestAvailabilityZones(t *testing.T) {
testObject := createFilledGcpEnvironmentResourceModel()

result := toGcpEnvironmentRequest(context.TODO(), testObject)

assert.NotNilf(t, result.AvailabilityZones, "If AvailabilityZones is specified, it is expected to be not nil")
assert.Equal(t, 1, len(testObject.AvailabilityZones))
}

func TestToGcpEnvironmentRequestLogStorage(t *testing.T) {
testObject := createFilledGcpEnvironmentResourceModel()

Expand Down
8 changes: 8 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ func FromListValueToStringList(tl types.List) []string {
return res
}

func FromTfStringSliceToStringSlice(tss []types.String) []string {
result := make([]string, 0)
for _, az := range tss {
result = append(result, az.ValueString())
}
return result
}

func FromSetValueToStringList(tl types.Set) []string {
if tl.IsNull() {
return []string{}
Expand Down
16 changes: 16 additions & 0 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,19 @@ func TestGetCallFailureThreshold(t *testing.T) {
})
}
}

func TestFromTfStringSliceToStringSliceIfEmpty(t *testing.T) {
assert.Equal(t, 0, len(FromTfStringSliceToStringSlice([]types.String{})))
}

func TestFromTfStringSliceToStringSliceIfNotEmpty(t *testing.T) {
val := "someValue"
input := []types.String{
types.StringValue(val),
}

result := FromTfStringSliceToStringSlice(input)

assert.Equal(t, len(input), len(result))
assert.Equal(t, val, result[0])
}

0 comments on commit 6ad4ae1

Please sign in to comment.