From 4c61683557b10c26677d3160fc13ffe70841c9a8 Mon Sep 17 00:00:00 2001 From: Omer Lachish <289488+rauchy@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:18:07 +0100 Subject: [PATCH] [Fix] Reflect backend updates in state for databricks_app (#4337) ## Changes 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 - [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 --- .../providers/pluginfw/products/app/resource_app.go | 4 ++-- .../pluginfw/products/app/resource_app_acc_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/providers/pluginfw/products/app/resource_app.go b/internal/providers/pluginfw/products/app/resource_app.go index 0bd570b59..180241e75 100644 --- a/internal/providers/pluginfw/products/app/resource_app.go +++ b/internal/providers/pluginfw/products/app/resource_app.go @@ -159,7 +159,7 @@ 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 @@ -167,7 +167,7 @@ func (a *resourceApp) Update(ctx context.Context, req resource.UpdateRequest, re // 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 } diff --git a/internal/providers/pluginfw/products/app/resource_app_acc_test.go b/internal/providers/pluginfw/products/app/resource_app_acc_test.go index fbbcd7838..19f37bf91 100644 --- a/internal/providers/pluginfw/products/app/resource_app_acc_test.go +++ b/internal/providers/pluginfw/products/app/resource_app_acc_test.go @@ -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 = ` @@ -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",