diff --git a/common/resource.go b/common/resource.go index 406d2f1573..130c8d317a 100644 --- a/common/resource.go +++ b/common/resource.go @@ -27,6 +27,12 @@ type Resource struct { Timeouts *schema.ResourceTimeout DeprecationMessage string Importer *schema.ResourceImporter + + // Set to true for account-level only resources, i.e. resources that can only be configured + // with an account-level provider. When false, the resource will include a workspace_id + // field that can be set when using an account-level provider to target a specific workspace + // in the account. + IsAccountLevelOnly bool } func nicerError(ctx context.Context, err error, action string) error { @@ -77,6 +83,7 @@ func (r Resource) saferCustomizeDiff() schema.CustomizeDiffFunc { err = r.CustomizeDiff(ctx, rd) if err != nil { err = nicerError(ctx, err, "customize diff for") + return } return } @@ -213,6 +220,9 @@ func (r Resource) ToResource() *schema.Resource { }, } } + if !r.IsAccountLevelOnly { + r.Schema = AddWorkspaceIdField(r.Schema) + } return resource } diff --git a/mws/data_mws_credentials.go b/mws/data_mws_credentials.go index aa757fd858..53294efcab 100755 --- a/mws/data_mws_credentials.go +++ b/mws/data_mws_credentials.go @@ -11,7 +11,7 @@ func DataSourceMwsCredentials() common.Resource { type mwsCredentialsData struct { Ids map[string]string `json:"ids,omitempty" tf:"computed"` } - return common.DataResource(mwsCredentialsData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error { + resource := common.DataResource(mwsCredentialsData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error { data := e.(*mwsCredentialsData) if c.Config.AccountID == "" { return fmt.Errorf("provider block is missing `account_id` property") @@ -26,4 +26,6 @@ func DataSourceMwsCredentials() common.Resource { } return nil }) + resource.IsAccountLevelOnly = true + return resource } diff --git a/mws/data_mws_workspaces.go b/mws/data_mws_workspaces.go index da5eabb2c5..21ae197f25 100755 --- a/mws/data_mws_workspaces.go +++ b/mws/data_mws_workspaces.go @@ -11,7 +11,7 @@ func DataSourceMwsWorkspaces() common.Resource { type mwsWorkspacesData struct { Ids map[string]int64 `json:"ids,omitempty" tf:"computed"` } - return common.DataResource(mwsWorkspacesData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error { + resource := common.DataResource(mwsWorkspacesData{}, func(ctx context.Context, e any, c *common.DatabricksClient) error { data := e.(*mwsWorkspacesData) if c.Config.AccountID == "" { return fmt.Errorf("provider block is missing `account_id` property") @@ -26,4 +26,6 @@ func DataSourceMwsWorkspaces() common.Resource { } return nil }) + resource.IsAccountLevelOnly = true + return resource } diff --git a/mws/resource_mws_credentials.go b/mws/resource_mws_credentials.go index b70a1e0ca1..b7c228f808 100644 --- a/mws/resource_mws_credentials.go +++ b/mws/resource_mws_credentials.go @@ -110,5 +110,6 @@ func ResourceMwsCredentials() common.Resource { s["account_id"].Deprecated = "`account_id` should be set as part of the Databricks Config, not in the resource." return s }), + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_customer_managed_keys.go b/mws/resource_mws_customer_managed_keys.go index 1163ef39c5..2f400c24a5 100644 --- a/mws/resource_mws_customer_managed_keys.go +++ b/mws/resource_mws_customer_managed_keys.go @@ -113,6 +113,7 @@ func ResourceMwsCustomerManagedKeys() common.Resource { Upgrade: migrateResourceCustomerManagedKeyV0, }, }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_log_delivery.go b/mws/resource_mws_log_delivery.go index 34514440fb..5026816301 100644 --- a/mws/resource_mws_log_delivery.go +++ b/mws/resource_mws_log_delivery.go @@ -119,5 +119,6 @@ func ResourceMwsLogDelivery() common.Resource { } return NewLogDeliveryAPI(ctx, c).Patch(accountID, configID, "DISABLED") }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_networks.go b/mws/resource_mws_networks.go index 56cb98bb98..8fada6c5b9 100644 --- a/mws/resource_mws_networks.go +++ b/mws/resource_mws_networks.go @@ -115,5 +115,6 @@ func ResourceMwsNetworks() common.Resource { } return NewNetworksAPI(ctx, c).Delete(accountID, networkID) }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_permission_assignment.go b/mws/resource_mws_permission_assignment.go index aa561933a5..436ca4ee5b 100644 --- a/mws/resource_mws_permission_assignment.go +++ b/mws/resource_mws_permission_assignment.go @@ -137,5 +137,6 @@ func ResourceMwsPermissionAssignment() common.Resource { } return NewPermissionAssignmentAPI(ctx, c).Remove(workspaceId, principalId) }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_private_access_settings.go b/mws/resource_mws_private_access_settings.go index 67e807dcf5..4eb6f2fc0c 100644 --- a/mws/resource_mws_private_access_settings.go +++ b/mws/resource_mws_private_access_settings.go @@ -74,5 +74,6 @@ func ResourceMwsPrivateAccessSettings() common.Resource { } return a.PrivateAccess.DeleteByPrivateAccessSettingsId(ctx, pasID) }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_storage_configurations.go b/mws/resource_mws_storage_configurations.go index 2b979cf448..1f5904cb5b 100644 --- a/mws/resource_mws_storage_configurations.go +++ b/mws/resource_mws_storage_configurations.go @@ -113,5 +113,6 @@ func ResourceMwsStorageConfigurations() common.Resource { Computed: true, }, }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_vpc_endpoint.go b/mws/resource_mws_vpc_endpoint.go index fd10d8cfaf..2983a0f47c 100644 --- a/mws/resource_mws_vpc_endpoint.go +++ b/mws/resource_mws_vpc_endpoint.go @@ -115,5 +115,6 @@ func ResourceMwsVpcEndpoint() common.Resource { } return NewVPCEndpointAPI(ctx, c).Delete(accountID, vpcEndpointID) }, + IsAccountLevelOnly: true, } } diff --git a/mws/resource_mws_workspaces.go b/mws/resource_mws_workspaces.go index 5f4d442bf0..084b8811b5 100644 --- a/mws/resource_mws_workspaces.go +++ b/mws/resource_mws_workspaces.go @@ -613,6 +613,7 @@ func ResourceMwsWorkspaces() common.Resource { Read: schema.DefaultTimeout(DefaultProvisionTimeout), Update: schema.DefaultTimeout(DefaultProvisionTimeout), }, + IsAccountLevelOnly: true, } }