Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDPCP-13570 Fixed an issue where tags in requests were populated with… #189

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading