diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 508c20f54a..4bb3f0533e 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -11,6 +11,7 @@ * Added optional `cloud` argument to `databricks_current_config` data source to explicitly set the cloud type (`aws`, `azure`, `gcp`) instead of relying on host-based detection. * Added `api` field to dual account/workspace resources (`databricks_user`, `databricks_service_principal`, `databricks_group`, `databricks_group_role`, `databricks_group_member`, `databricks_user_role`, `databricks_service_principal_role`, `databricks_user_instance_profile`, `databricks_group_instance_profile`, `databricks_metastore`, `databricks_metastore_assignment`, `databricks_metastore_data_access`, `databricks_storage_credential`, `databricks_service_principal_secret`, `databricks_access_control_rule_set`) to explicitly control whether account-level or workspace-level APIs are used. This enables support for unified hosts like `api.databricks.com` where the API level cannot be inferred from the host ([#5483](https://github.com/databricks/terraform-provider-databricks/pull/5483)). +* Allow in-place renames for `databricks_credential` and `databricks_external_location` resources ([#5538](https://github.com/databricks/terraform-provider-databricks/pull/5538)). ### Bug Fixes diff --git a/catalog/resource_credential.go b/catalog/resource_credential.go index 809e7c35a4..17aca96757 100644 --- a/catalog/resource_credential.go +++ b/catalog/resource_credential.go @@ -28,7 +28,6 @@ var credentialSchema = common.StructToSchema(catalog.CredentialInfo{}, common.CustomizeSchemaPath(m, computed).SetComputed() } - common.CustomizeSchemaPath(m, "name").SetForceNew() common.CustomizeSchemaPath(m, "databricks_gcp_service_account").SetComputed() common.CustomizeSchemaPath(m, "databricks_gcp_service_account", "email").SetComputed() common.CustomizeSchemaPath(m, "databricks_gcp_service_account", "credential_id").SetComputed() @@ -143,6 +142,9 @@ func ResourceCredential() common.Resource { if !d.HasChangeExcept("owner") { return nil } + if d.HasChange("name") { + updateCredRequest.NewName = d.Get("name").(string) + } if d.HasChange("read_only") { updateCredRequest.ForceSendFields = append(updateCredRequest.ForceSendFields, "ReadOnly") } diff --git a/catalog/resource_credential_test.go b/catalog/resource_credential_test.go index 8e8a66b470..1e41af6f41 100644 --- a/catalog/resource_credential_test.go +++ b/catalog/resource_credential_test.go @@ -158,19 +158,20 @@ func TestCreateIsolatedCredential(t *testing.T) { }) } -func TestUpdateCredentialSchemaForceNew(t *testing.T) { +func TestUpdateCredentialSchema(t *testing.T) { qa.ResourceFixture{ MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) { e := w.GetMockCredentialsAPI().EXPECT() e.UpdateCredential(mock.Anything, catalog.UpdateCredentialRequest{ NameArg: "name", + NewName: "rename", AwsIamRole: &catalog.AwsIamRole{ RoleArn: "arn:aws:iam::account:role/role", }, Comment: "comment", }).Return(&catalog.CredentialInfo{ Id: "1234-5678", - Name: "name", + Name: "rename", AwsIamRole: &catalog.AwsIamRole{ RoleArn: "arn:aws:iam::account:role/role", }, @@ -186,10 +187,9 @@ func TestUpdateCredentialSchemaForceNew(t *testing.T) { Comment: "comment", }, nil) }, - RequiresNew: true, - Resource: ResourceCredential(), - Update: true, - ID: "name", + Resource: ResourceCredential(), + Update: true, + ID: "name", InstanceState: map[string]string{ "name": "name", "purpose": "SERVICE", diff --git a/catalog/resource_external_location.go b/catalog/resource_external_location.go index e5a58d2d30..0655358cf1 100644 --- a/catalog/resource_external_location.go +++ b/catalog/resource_external_location.go @@ -31,7 +31,7 @@ func ResourceExternalLocation() common.Resource { return old == "false" && new == "true" } common.CustomizeSchemaPath(m, "url").SetRequired().SetCustomSuppressDiff(ucDirectoryPathSlashOnlySuppressDiff) - common.CustomizeSchemaPath(m, "name").SetRequired().SetForceNew().SetCustomSuppressDiff(common.EqualFoldDiffSuppress) + common.CustomizeSchemaPath(m, "name").SetRequired().SetCustomSuppressDiff(common.EqualFoldDiffSuppress) common.CustomizeSchemaPath(m, "credential_name").SetRequired() common.CustomizeSchemaPath(m, "isolation_mode").SetComputed() common.CustomizeSchemaPath(m, "owner").SetComputed() @@ -130,7 +130,6 @@ func ResourceExternalLocation() common.Resource { return err } } - if !d.HasChangeExcept("owner") { return nil } @@ -140,6 +139,11 @@ func ResourceExternalLocation() common.Resource { updateExternalLocationRequest.ForceSendFields = append(updateExternalLocationRequest.ForceSendFields, value) } } + + if d.HasChange("name") { + updateExternalLocationRequest.NewName = d.Get("name").(string) + } + // ugly hack until API is fixed if updateExternalLocationRequest.FileEventQueue != nil { if updateExternalLocationRequest.FileEventQueue.ManagedAqs != nil { diff --git a/catalog/resource_external_location_test.go b/catalog/resource_external_location_test.go index 9e14315232..f3f036c705 100644 --- a/catalog/resource_external_location_test.go +++ b/catalog/resource_external_location_test.go @@ -329,9 +329,10 @@ func TestUpdateExternalLocationName(t *testing.T) { Fixtures: []qa.HTTPFixture{ { Method: "PATCH", - Resource: "/api/2.1/unity-catalog/external-locations/abc", + Resource: "/api/2.1/unity-catalog/external-locations/abc-old", ExpectedRequest: catalog.UpdateExternalLocation{ Url: "s3://foo/bar", + NewName: "abc", CredentialName: "bcd", Comment: "def", ReadOnly: false, @@ -339,7 +340,7 @@ func TestUpdateExternalLocationName(t *testing.T) { }, { Method: "GET", - Resource: "/api/2.1/unity-catalog/external-locations/abc?", + Resource: "/api/2.1/unity-catalog/external-locations/abc-old?", Response: catalog.ExternalLocationInfo{ Name: "abc", Url: "s3://foo/bar", @@ -348,10 +349,9 @@ func TestUpdateExternalLocationName(t *testing.T) { }, }, }, - Resource: ResourceExternalLocation(), - Update: true, - RequiresNew: true, - ID: "abc", + Resource: ResourceExternalLocation(), + Update: true, + ID: "abc-old", InstanceState: map[string]string{ "name": "abc-old", "url": "s3://foo/bar",