diff --git a/resources/environments/converter_gcp.go b/resources/environments/converter_gcp.go index 07b6a3bf..1e96c642 100644 --- a/resources/environments/converter_gcp.go +++ b/resources/environments/converter_gcp.go @@ -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) diff --git a/resources/environments/converter_gcp_test.go b/resources/environments/converter_gcp_test.go index fdcc1bbe..1950b845 100644 --- a/resources/environments/converter_gcp_test.go +++ b/resources/environments/converter_gcp_test.go @@ -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() diff --git a/utils/utils.go b/utils/utils.go index 3bc88c57..8c489815 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -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{} diff --git a/utils/utils_test.go b/utils/utils_test.go index b8060f56..90f2a2b9 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -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]) +}