Skip to content

Commit

Permalink
CDPCP-13570 Fixed an issue where tags in requests were populated with…
Browse files Browse the repository at this point in the history
… the same key (#189)
  • Loading branch information
daszabo authored Dec 13, 2024
1 parent 1772bea commit 9ce827d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
9 changes: 6 additions & 3 deletions resources/datahub/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ func fromModelToAwsRequest(model awsDatahubResourceModel, ctx context.Context) *
req.Tags = make([]*datahubmodels.DatahubResourceTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datahubmodels.DatahubResourceTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down Expand Up @@ -161,10 +162,11 @@ func fromModelToGcpRequest(model gcpDatahubResourceModel, ctx context.Context) *
req.Tags = make([]*datahubmodels.GCPDatahubResourceTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datahubmodels.GCPDatahubResourceTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down Expand Up @@ -242,10 +244,11 @@ func fromModelToAzureRequest(model azureDatahubResourceModel, ctx context.Contex
req.Tags = make([]*datahubmodels.DatahubResourceTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datahubmodels.DatahubResourceTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down
14 changes: 14 additions & 0 deletions resources/datahub/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ func TestFromModelToRequestClusterDefinition(t *testing.T) {
test.CompareStrings(got.ClusterDefinition, input.ClusterDefinition.ValueString(), t)
}

func TestFromModelToRequestTags(t *testing.T) {
tags, _ := types.MapValue(types.StringType, map[string]attr.Value{
"key1": types.StringValue("value1"),
"key2": types.StringValue("value2"),
"key3": types.StringValue("value3"),
})
input := awsDatahubResourceModel{Tags: tags}
got := fromModelToAwsRequest(input, context.TODO())

test.CompareStrings(*got.Tags[0].Value, input.Tags.Elements()["key1"].(types.String).ValueString(), t)
test.CompareStrings(*got.Tags[1].Value, input.Tags.Elements()["key2"].(types.String).ValueString(), t)
test.CompareStrings(*got.Tags[2].Value, input.Tags.Elements()["key3"].(types.String).ValueString(), t)
}

func TestFromModelToGcpRequestBasicFields(t *testing.T) {
tags, _ := types.MapValue(types.StringType, map[string]attr.Value{"key": types.StringValue("value")})
image, _ := types.ObjectValue(map[string]attr.Type{
Expand Down
3 changes: 2 additions & 1 deletion resources/datalake/converter_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ func toGcpDatalakeRequest(ctx context.Context, model *gcpDatalakeResourceModel)
req.Tags = make([]*datalakemodels.DatalakeResourceGCPTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datalakemodels.DatalakeResourceGCPTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion resources/datalake/resource_aws_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ func toAwsDatalakeRequest(ctx context.Context, model *awsDatalakeResourceModel)
req.Tags = make([]*datalakemodels.DatalakeResourceTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datalakemodels.DatalakeResourceTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion resources/datalake/resource_azure_datalake.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ func toAzureDatalakeRequest(ctx context.Context, model *azureDatalakeResourceMod
req.Tags = make([]*datalakemodels.DatalakeResourceTagRequest, len(model.Tags.Elements()))
i := 0
for k, v := range model.Tags.Elements() {
key := k
val, diag := v.(basetypes.StringValuable).ToStringValue(ctx)
if !diag.HasError() {
req.Tags[i] = &datalakemodels.DatalakeResourceTagRequest{
Key: &k,
Key: &key,
Value: val.ValueStringPointer(),
}
}
Expand Down

0 comments on commit 9ce827d

Please sign in to comment.