Skip to content

Commit 4f664d7

Browse files
toppercodesampagent
andcommitted
Stop tracking dashboard version in resource state
Amp-Thread-ID: https://ampcode.com/threads/T-019c9bc7-a165-774f-b025-2e92d6e0b9d5 Co-authored-by: Amp <amp@ampcode.com>
1 parent cd411e3 commit 4f664d7

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

axiom/resource_dashboard.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ type DashboardResourceModel struct {
4545
ID types.String `tfsdk:"id"`
4646
UID types.String `tfsdk:"uid"`
4747
Dashboard types.String `tfsdk:"dashboard"`
48-
Version types.Int64 `tfsdk:"version"`
4948
Overwrite types.Bool `tfsdk:"overwrite"`
5049
}
5150

@@ -98,10 +97,6 @@ func (r *DashboardResource) Schema(_ context.Context, _ resource.SchemaRequest,
9897
Required: true,
9998
MarkdownDescription: "The dashboard document as a JSON string (for example from `jsonencode(...)`).",
10099
},
101-
"version": schema.Int64Attribute{
102-
Computed: true,
103-
MarkdownDescription: "Monotonic dashboard version used for optimistic updates.",
104-
},
105100
"overwrite": schema.BoolAttribute{
106101
Optional: true,
107102
Computed: true,
@@ -232,8 +227,33 @@ func (r *DashboardResource) Update(ctx context.Context, req resource.UpdateReque
232227
return
233228
}
234229

235-
stateVersion := state.Version.ValueInt64()
236-
payload, uid, diags := dashboardUpsertPayloadFromModel(plan, dashboardUIDFromState(state), stateVersion, false)
230+
uidFromState := dashboardUIDFromState(state)
231+
stateVersion := int64(0)
232+
if !plan.Overwrite.IsNull() && !plan.Overwrite.IsUnknown() && !plan.Overwrite.ValueBool() {
233+
remote, err := r.client.Dashboards.GetRaw(ctx, uidFromState)
234+
if err != nil {
235+
if isNotFoundError(err) {
236+
resp.Diagnostics.AddWarning(
237+
"Dashboard Not Found",
238+
fmt.Sprintf("Dashboard with UID %s does not exist and will be recreated if still defined in the configuration.", uidFromState),
239+
)
240+
resp.State.RemoveResource(ctx)
241+
return
242+
}
243+
244+
resp.Diagnostics.AddError("Failed to update dashboard", fmt.Sprintf("Unable to read current dashboard version: %s", err))
245+
return
246+
}
247+
248+
remoteDashboard, err := decodeDashboardResource(remote)
249+
if err != nil {
250+
resp.Diagnostics.AddError("Failed to update dashboard", fmt.Sprintf("Unable to decode current dashboard response: %s", err))
251+
return
252+
}
253+
254+
stateVersion = remoteDashboard.Version
255+
}
256+
payload, uid, diags := dashboardUpsertPayloadFromModel(plan, uidFromState, stateVersion, false)
237257
resp.Diagnostics.Append(diags...)
238258
if resp.Diagnostics.HasError() {
239259
return
@@ -372,7 +392,6 @@ func flattenDashboardResource(in dashboardResourcePayload, overwrite types.Bool,
372392
ID: types.StringValue(uid),
373393
UID: types.StringValue(uid),
374394
Dashboard: types.StringValue(normalizedDashboard),
375-
Version: types.Int64Value(in.Version),
376395
Overwrite: overwrite,
377396
}, nil
378397
}

axiom/resource_dashboard_integration_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func TestAccAxiomDashboardResource_WithProvidedUID(t *testing.T) {
4343
testAccCheckAxiomResourcesExist(client, resourceName),
4444
resource.TestCheckResourceAttr(resourceName, "uid", uid),
4545
resource.TestCheckResourceAttrSet(resourceName, "id"),
46-
resource.TestCheckResourceAttrSet(resourceName, "version"),
4746
),
4847
},
4948
{
@@ -96,7 +95,6 @@ func TestAccAxiomDashboardResource_ServerGeneratedUID(t *testing.T) {
9695
testAccCheckAxiomResourcesExist(client, resourceName),
9796
resource.TestCheckResourceAttrSet(resourceName, "uid"),
9897
resource.TestCheckResourceAttrSet(resourceName, "id"),
99-
resource.TestCheckResourceAttrSet(resourceName, "version"),
10098
testAccCaptureDashboardUID(resourceName, &generatedUID),
10199
),
102100
},

axiom/resource_dashboard_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,6 @@ func TestFlattenDashboardResource(t *testing.T) {
294294
if got.UID.ValueString() != "uid-1" {
295295
t.Fatalf("expected state uid from response uid, got %q", got.UID.ValueString())
296296
}
297-
if got.Version.ValueInt64() != 5 {
298-
t.Fatalf("expected version=5, got %d", got.Version.ValueInt64())
299-
}
300297
}
301298

302299
func TestFlattenDashboardResource_MissingUID(t *testing.T) {

docs/resources/dashboard.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ description: |-
2121
### Read-Only
2222

2323
- `id` (String) Dashboard identifier (same value as `uid`).
24-
- `version` (Number) Monotonic dashboard version used for optimistic updates.
2524

2625
## Import
2726

0 commit comments

Comments
 (0)