Skip to content

Commit 15853d5

Browse files
stefanoborieroStefano Boriero
andauthored
Force recomputation of computed values for Grafana Cloud stacks on slug update (#1269)
* Force recomputation of computed values for Grafana Cloud stacks on slug update Names of some attributes of the Grafana Cloud stack depend on the slug of the stack. While the current state of the provider does update these attributes on the resource in the state, if these attributes are referenced in an output clause, the absence of a change in the generated plan renders the change unnoticed and stale information is outputted on a first apply. By using https://pkg.go.dev/github.com/hashicorp/terraform-plugin-sdk/helper/customdiff it's possible to mark these values to be computed again if the slug changes, thus being reflected as changes in the plan and generated an up to date output. Fixes #1191 * Adjust code formatting with go fmt --------- Co-authored-by: Stefano Boriero <[email protected]>
1 parent 06964e4 commit 15853d5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

internal/resources/cloud/resource_cloud_stack.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
gapi "github.com/grafana/grafana-api-golang-client"
1616
"github.com/grafana/terraform-provider-grafana/internal/common"
1717
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1819
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1920
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2021
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -225,6 +226,23 @@ available at “https://<stack_slug>.grafana.net".`,
225226
Computed: true,
226227
},
227228
},
229+
CustomizeDiff: customdiff.All(
230+
customdiff.ComputedIf("url", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
231+
return diff.HasChange("slug")
232+
}),
233+
customdiff.ComputedIf("alertmanager_name", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
234+
return diff.HasChange("slug")
235+
}),
236+
customdiff.ComputedIf("logs_name", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
237+
return diff.HasChange("slug")
238+
}),
239+
customdiff.ComputedIf("traces_name", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
240+
return diff.HasChange("slug")
241+
}),
242+
customdiff.ComputedIf("prometheus_name", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
243+
return diff.HasChange("slug")
244+
}),
245+
),
228246
}
229247
}
230248

0 commit comments

Comments
 (0)