Skip to content

Commit

Permalink
[Fix] Reflect backend updates in state for databricks_app (#4337)
Browse files Browse the repository at this point in the history
## Changes
<!-- Summary of your changes that are easy to understand -->
Following #4099, updates to Databricks Apps only reflected the ones in
the plan, and not the ones coming back from the backend call to update
the app. This PR includes those changes in.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [x] `make test` run locally
- [ ] relevant change in `docs/` folder
- [x] covered with integration tests in `internal/acceptance`
- [x] using Go SDK
- [x] using TF Plugin Framework

Co-authored-by: Omer Lachish <[email protected]>
  • Loading branch information
rauchy and rauchy authored Dec 20, 2024
1 parent cc758b8 commit 4c61683
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/providers/pluginfw/products/app/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ func (a *resourceApp) Update(ctx context.Context, req resource.UpdateRequest, re
if resp.Diagnostics.HasError() {
return
}
_, err := w.Apps.Update(ctx, apps.UpdateAppRequest{App: &appGoSdk, Name: app.Name.ValueString()})
response, err := w.Apps.Update(ctx, apps.UpdateAppRequest{App: &appGoSdk, Name: app.Name.ValueString()})
if err != nil {
resp.Diagnostics.AddError("failed to update app", err.Error())
return
}

// Store the updated version of the app in state
var newApp apps_tf.App
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, appGoSdk, &newApp)...)
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, response, &newApp)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down
12 changes: 12 additions & 0 deletions internal/providers/pluginfw/products/app/resource_app_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"

"github.com/databricks/terraform-provider-databricks/internal/acceptance"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/assert"
)

const baseResources = `
Expand Down Expand Up @@ -118,14 +120,24 @@ is required`)),
}

func TestAccAppResource(t *testing.T) {
var updateTime string
acceptance.LoadWorkspaceEnv(t)
if acceptance.IsGcp(t) {
acceptance.Skipf(t)("not available on GCP")
}
acceptance.WorkspaceLevel(t, acceptance.Step{
Template: makeTemplate("My app"),
Check: func(s *terraform.State) error {
updateTime = s.RootModule().Resources["databricks_app.this"].Primary.Attributes["update_time"]
return nil
},
}, acceptance.Step{
Template: makeTemplate("My new app"),
Check: func(s *terraform.State) error {
var newUpdateTime = s.RootModule().Resources["databricks_app.this"].Primary.Attributes["update_time"]
assert.NotEqual(t, updateTime, newUpdateTime)
return nil
},
}, acceptance.Step{
ImportState: true,
ResourceName: "databricks_app.this",
Expand Down

0 comments on commit 4c61683

Please sign in to comment.