Skip to content

Commit

Permalink
Fixing up detector defintition
Browse files Browse the repository at this point in the history
  • Loading branch information
MovieStoreGuy committed Oct 22, 2024
1 parent d1178a4 commit 97f497a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions internal/definition/detector/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewResource() *schema.Resource {
StateContext: schema.ImportStatePassthroughContext,
},
StateUpgraders: []schema.StateUpgrader{
{Type: stateV0State().CoreConfigSchema().ImpliedType(), Upgrade: stateMigrationV0, Version: 0},
{Type: v0state().CoreConfigSchema().ImpliedType(), Upgrade: v0stateMigration, Version: 0},
},
}
}
Expand Down Expand Up @@ -67,12 +67,13 @@ func resourceCreate(ctx context.Context, data *schema.ResourceData, meta any) (i
return tfext.AsErrorDiagnostics(err)
}

endpoint, err := pmeta.LoadApplicationURL(ctx, meta, AppPath, resp.Id, "edit")
if err != nil {
issues = tfext.AppendDiagnostics(issues, tfext.AsErrorDiagnostics(err)...)
}

issues = tfext.AppendDiagnostics(issues, tfext.AsErrorDiagnostics(data.Set("url", endpoint))...)
issues = tfext.AppendDiagnostics(issues,
tfext.AsErrorDiagnostics(
data.Set("url",
pmeta.LoadApplicationURL(ctx, meta, AppPath, resp.Id, "edit"),
),
)...,
)

return tfext.AppendDiagnostics(
issues,
Expand Down Expand Up @@ -136,12 +137,11 @@ func resourceUpdate(ctx context.Context, data *schema.ResourceData, meta any) (i
return tfext.AsErrorDiagnostics(err)
}

endpoint, err := pmeta.LoadApplicationURL(ctx, meta, AppPath, resp.Id, "edit")
if err != nil {
issues = tfext.AppendDiagnostics(issues, tfext.AsErrorDiagnostics(err)...)
}

issues = tfext.AppendDiagnostics(issues, tfext.AsErrorDiagnostics(data.Set("url", endpoint))...)
issues = tfext.AppendDiagnostics(issues,
tfext.AsErrorDiagnostics(
data.Set("url", pmeta.LoadApplicationURL(ctx, meta, AppPath, resp.Id, "edit")),
)...,
)

return tfext.AppendDiagnostics(
issues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
tfext "github.com/splunk-terraform/terraform-provider-signalfx/internal/tfextension"
)

func stateV0State() *schema.Resource {
func v0state() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"time_range": {Type: schema.TypeString, Optional: true},
},
}
}

func stateMigrationV0(ctx context.Context, state map[string]any, _ any) (map[string]any, error) {
func v0stateMigration(ctx context.Context, state map[string]any, _ any) (map[string]any, error) {
tflog.Debug(ctx, "Upgrading detector state", tfext.NewLogFields().JSON("state", state))

if tr, ok := state["time_range"].(string); ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestStateV0(t *testing.T) {
Optional: true,
},
},
stateV0State().Schema,
v0state().Schema,
"Must match the expected value",
)
}
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestStateMigrationV0(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

actual, err := stateMigrationV0(context.Background(), tc.state, nil)
actual, err := v0stateMigration(context.Background(), tc.state, nil)

assert.Equal(t, tc.expect, actual, "Must match the expected state")
if tc.errVal != "" {
Expand Down

0 comments on commit 97f497a

Please sign in to comment.