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

[apm_retention_filter] Fix inconsistent state problem #2482

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 11 additions & 4 deletions datadog/fwprovider/resource_datadog_apm_retention_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ func (r *ApmRetentionFilterResource) Read(ctx context.Context, request resource.
}

attributes := resp.Data.Attributes
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), *attributes.Filter.Query, attributes.GetEnabled(), string(attributes.GetFilterType()))

// state.Filter.Query.ValueString() is used instead of attributes.Filter.Query.ValueString() because
// the API might re-write the query (i.e. to convert units), but it stays symantically the same
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), state.Filter.Query.ValueString(), attributes.GetEnabled(), string(attributes.GetFilterType()))

// Save data into Terraform state
response.Diagnostics.Append(response.State.Set(ctx, &state)...)
Expand Down Expand Up @@ -160,7 +163,9 @@ func (r *ApmRetentionFilterResource) Create(ctx context.Context, request resourc
}

attributes := resp.Data.Attributes
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), *attributes.Filter.Query, attributes.GetEnabled(), string(attributes.GetFilterType()))
// state.Filter.Query.ValueString() is used instead of attributes.Filter.Query.ValueString() because
// the API might re-write the query (i.e. to convert units), but it stays symantically the same
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), state.Filter.Query.ValueString(), attributes.GetEnabled(), string(attributes.GetFilterType()))

// Save data into Terraform state
response.Diagnostics.Append(response.State.Set(ctx, &state)...)
Expand Down Expand Up @@ -195,7 +200,9 @@ func (r *ApmRetentionFilterResource) Update(ctx context.Context, request resourc
}

attributes := resp.Data.Attributes
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), *attributes.GetFilter().Query, attributes.GetEnabled(), string(attributes.GetFilterType()))
// state.Filter.Query.ValueString() is used instead of attributes.Filter.Query.ValueString() because
// the API might re-write the query (i.e. to convert units), but it stays symantically the same
r.updateState(ctx, &state, resp.Data.Id, attributes.GetName(), attributes.GetRate(), state.Filter.Query.ValueString(), attributes.GetEnabled(), string(attributes.GetFilterType()))

// Save data into Terraform state
response.Diagnostics.Append(response.State.Set(ctx, &state)...)
Expand Down Expand Up @@ -223,7 +230,7 @@ func (r *ApmRetentionFilterResource) Delete(ctx context.Context, request resourc
}
}

func (r *ApmRetentionFilterResource) updateState(ctx context.Context, state *ApmRetentionFilterModel, dataId string, name string, rate float64, query string, enabled bool, filterType string) {
func (r *ApmRetentionFilterResource) updateState(_ context.Context, state *ApmRetentionFilterModel, dataId string, name string, rate float64, query string, enabled bool, filterType string) {
state.ID = types.StringValue(dataId)
state.Name = types.StringValue(name)

Expand Down
2 changes: 1 addition & 1 deletion datadog/tests/cassettes/TestAccApmRetentionFilter.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024-01-16T15:28:02.191729-05:00
2024-07-10T14:58:10.601784+02:00
Loading
Loading