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

[datadog_spans_metric] Normalize tag value #2056

Merged
merged 2 commits into from
Aug 11, 2023
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
4 changes: 4 additions & 0 deletions datadog/fwprovider/resource_datadog_spans_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/planmodifiers"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
)

Expand Down Expand Up @@ -90,6 +91,9 @@ func (r *spansMetricResource) Schema(_ context.Context, _ resource.SchemaRequest
Optional: true,
Computed: true,
Description: "Eventual name of the tag that gets created. By default, the path attribute is used as the tag name.",
PlanModifiers: []planmodifier.String{
planmodifiers.NormalizeTag(),
},
},
},
},
Expand Down
32 changes: 32 additions & 0 deletions datadog/internal/planmodifiers/types_string_tag_normalizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package planmodifiers

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
)

func NormalizeTag() planmodifier.String {
return normalizeTagModifier{}
}

type normalizeTagModifier struct{}

func (m normalizeTagModifier) Description(_ context.Context) string {
return "Normalize tag value."
}

func (m normalizeTagModifier) MarkdownDescription(ctx context.Context) string {
return m.Description(ctx)
}

func (m normalizeTagModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
if req.ConfigValue.IsUnknown() || req.ConfigValue.IsNull() {
return
}

val := req.ConfigValue.ValueString()
resp.PlanValue = types.StringValue(utils.NormalizeTag(val))
}