Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Feb 1, 2024
1 parent 7752299 commit ab4c591
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions common/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -213,6 +220,9 @@ func (r Resource) ToResource() *schema.Resource {
},
}
}
if !r.IsAccountLevelOnly {
r.Schema = AddWorkspaceIdField(r.Schema)
}
return resource
}

Expand Down
4 changes: 3 additions & 1 deletion mws/data_mws_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,4 +26,6 @@ func DataSourceMwsCredentials() common.Resource {
}
return nil
})
resource.IsAccountLevelOnly = true
return resource
}
4 changes: 3 additions & 1 deletion mws/data_mws_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -26,4 +26,6 @@ func DataSourceMwsWorkspaces() common.Resource {
}
return nil
})
resource.IsAccountLevelOnly = true
return resource
}
1 change: 1 addition & 0 deletions mws/resource_mws_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_customer_managed_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func ResourceMwsCustomerManagedKeys() common.Resource {
Upgrade: migrateResourceCustomerManagedKeyV0,
},
},
IsAccountLevelOnly: true,
}
}

Expand Down
1 change: 1 addition & 0 deletions mws/resource_mws_log_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,6 @@ func ResourceMwsLogDelivery() common.Resource {
}
return NewLogDeliveryAPI(ctx, c).Patch(accountID, configID, "DISABLED")
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ func ResourceMwsNetworks() common.Resource {
}
return NewNetworksAPI(ctx, c).Delete(accountID, networkID)
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_permission_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@ func ResourceMwsPermissionAssignment() common.Resource {
}
return NewPermissionAssignmentAPI(ctx, c).Remove(workspaceId, principalId)
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_private_access_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ func ResourceMwsPrivateAccessSettings() common.Resource {
}
return a.PrivateAccess.DeleteByPrivateAccessSettingsId(ctx, pasID)
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_storage_configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ func ResourceMwsStorageConfigurations() common.Resource {
Computed: true,
},
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_vpc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ func ResourceMwsVpcEndpoint() common.Resource {
}
return NewVPCEndpointAPI(ctx, c).Delete(accountID, vpcEndpointID)
},
IsAccountLevelOnly: true,
}
}
1 change: 1 addition & 0 deletions mws/resource_mws_workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ func ResourceMwsWorkspaces() common.Resource {
Read: schema.DefaultTimeout(DefaultProvisionTimeout),
Update: schema.DefaultTimeout(DefaultProvisionTimeout),
},
IsAccountLevelOnly: true,
}
}

Expand Down

0 comments on commit ab4c591

Please sign in to comment.