Skip to content

Commit

Permalink
Merge pull request #357 from Qovery/feature
Browse files Browse the repository at this point in the history
fix segfault in cluster features
  • Loading branch information
erebe committed Feb 19, 2024
2 parents 6aa034b + b87c7cb commit 27bd4e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/pkg/errors v0.9.1
github.com/qovery/qovery-client-go v0.0.0-20240212165349-98d0b37a2c8e
github.com/qovery/qovery-client-go v0.0.0-20240215160333-8424923c00e9
github.com/schollz/progressbar/v3 v3.13.0
github.com/sethvargo/go-envconfig v0.9.0
github.com/stretchr/testify v1.8.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ github.com/qovery/qovery-client-go v0.0.0-20240208152258-b2701d4efe5d h1:E2zqZzn
github.com/qovery/qovery-client-go v0.0.0-20240208152258-b2701d4efe5d/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20240212165349-98d0b37a2c8e h1:G8r1BQvv9EHmSmwqcHDAmCQaCyyNuNSqvwYavL/uU5E=
github.com/qovery/qovery-client-go v0.0.0-20240212165349-98d0b37a2c8e/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20240215160333-8424923c00e9 h1:kbN+bPGCiDWCzvqjzhk1/g89nbe/FoFJbBJyqYBktl4=
github.com/qovery/qovery-client-go v0.0.0-20240215160333-8424923c00e9/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
63 changes: 36 additions & 27 deletions qovery/resource_cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,8 @@ func fromQoveryClusterFeatures(ff []qovery.ClusterFeature) types.Object {
attributes[featureKeyStaticIP] = FromBoolPointer(f.GetValue().Bool)
attributeTypes[featureKeyStaticIP] = types.BoolType
case featureIdExistingVpc:
// tf has a default value for it, but the api does not return this feature , as exiting vpc super seed it
// So set the default value to match what tf expect and not break existing clients
attributes[featureKeyVpcSubnet] = FromStringPointer(&clusterFeatureVpcSubnetDefault)
attributeTypes[featureKeyVpcSubnet] = types.StringType

v := f.GetValue().ClusterFeatureAwsExistingVpc

attrTypes := make(map[string]attr.Type)
attrTypes["aws_vpc_eks_id"] = types.StringType
attrTypes["eks_subnets_zone_a_ids"] = types.ListType{ElemType: types.StringType}
Expand All @@ -211,6 +207,17 @@ func fromQoveryClusterFeatures(ff []qovery.ClusterFeature) types.Object {
attrTypes["elasticache_subnets_zone_b_ids"] = types.ListType{ElemType: types.StringType}
attrTypes["elasticache_subnets_zone_c_ids"] = types.ListType{ElemType: types.StringType}

if v == nil {
terraformObjectValue := types.ObjectNull(attrTypes)
attributes[featureKeyExistingVpc] = terraformObjectValue
attributeTypes[featureKeyExistingVpc] = terraformObjectValue.Type(context.Background())
continue
}

// tf has a default value for it, but the api does not return this feature , as exiting vpc super seed it
// So set the default value to match what tf expect and not break existing clients
attributes[featureKeyVpcSubnet] = FromStringPointer(&clusterFeatureVpcSubnetDefault)
attributeTypes[featureKeyVpcSubnet] = types.StringType
attrVals := make(map[string]attr.Value)
attrVals["aws_vpc_eks_id"] = FromStringPointer(&v.AwsVpcEksId)
attrVals["eks_subnets_zone_a_ids"] = FromStringArray(v.EksSubnetsZoneAIds)
Expand Down Expand Up @@ -290,29 +297,31 @@ func toQoveryClusterFeatures(f types.Object, mode string) []qovery.ClusterReques

if _, ok := f.Attributes()[featureKeyExistingVpc]; ok {
v := f.Attributes()[featureKeyExistingVpc].(types.Object)
feature := qovery.ClusterFeatureAwsExistingVpc{
AwsVpcEksId: ToString(v.Attributes()["aws_vpc_eks_id"].(types.String)),
EksSubnetsZoneAIds: ToStringArray(v.Attributes()["eks_subnets_zone_a_ids"].(types.List)),
EksSubnetsZoneBIds: ToStringArray(v.Attributes()["eks_subnets_zone_b_ids"].(types.List)),
EksSubnetsZoneCIds: ToStringArray(v.Attributes()["eks_subnets_zone_c_ids"].(types.List)),
RdsSubnetsZoneAIds: ToStringArray(v.Attributes()["rds_subnets_zone_a_ids"].(types.List)),
RdsSubnetsZoneBIds: ToStringArray(v.Attributes()["rds_subnets_zone_b_ids"].(types.List)),
RdsSubnetsZoneCIds: ToStringArray(v.Attributes()["rds_subnets_zone_c_ids"].(types.List)),
DocumentdbSubnetsZoneAIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_a_ids"].(types.List)),
DocumentdbSubnetsZoneBIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_b_ids"].(types.List)),
DocumentdbSubnetsZoneCIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_c_ids"].(types.List)),
ElasticacheSubnetsZoneAIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_a_ids"].(types.List)),
ElasticacheSubnetsZoneBIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_b_ids"].(types.List)),
ElasticacheSubnetsZoneCIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_c_ids"].(types.List)),
if !v.IsNull() {
feature := qovery.ClusterFeatureAwsExistingVpc{
AwsVpcEksId: ToString(v.Attributes()["aws_vpc_eks_id"].(types.String)),
EksSubnetsZoneAIds: ToStringArray(v.Attributes()["eks_subnets_zone_a_ids"].(types.List)),
EksSubnetsZoneBIds: ToStringArray(v.Attributes()["eks_subnets_zone_b_ids"].(types.List)),
EksSubnetsZoneCIds: ToStringArray(v.Attributes()["eks_subnets_zone_c_ids"].(types.List)),
RdsSubnetsZoneAIds: ToStringArray(v.Attributes()["rds_subnets_zone_a_ids"].(types.List)),
RdsSubnetsZoneBIds: ToStringArray(v.Attributes()["rds_subnets_zone_b_ids"].(types.List)),
RdsSubnetsZoneCIds: ToStringArray(v.Attributes()["rds_subnets_zone_c_ids"].(types.List)),
DocumentdbSubnetsZoneAIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_a_ids"].(types.List)),
DocumentdbSubnetsZoneBIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_b_ids"].(types.List)),
DocumentdbSubnetsZoneCIds: ToStringArray(v.Attributes()["documentdb_subnets_zone_c_ids"].(types.List)),
ElasticacheSubnetsZoneAIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_a_ids"].(types.List)),
ElasticacheSubnetsZoneBIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_b_ids"].(types.List)),
ElasticacheSubnetsZoneCIds: ToStringArray(v.Attributes()["elasticache_subnets_zone_c_ids"].(types.List)),
}
value := qovery.NewNullableClusterFeatureValue(&qovery.ClusterFeatureValue{
ClusterFeatureAwsExistingVpc: &feature,
})

features = append(features, qovery.ClusterRequestFeaturesInner{
Id: StringAsPointer(featureIdExistingVpc),
Value: *value,
})
}
value := qovery.NewNullableClusterFeatureValue(&qovery.ClusterFeatureValue{
ClusterFeatureAwsExistingVpc: &feature,
})

features = append(features, qovery.ClusterRequestFeaturesInner{
Id: StringAsPointer(featureIdExistingVpc),
Value: *value,
})
}

return features
Expand Down

0 comments on commit 27bd4e6

Please sign in to comment.