Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support account-level provider with workspace-level resources #3188

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1ad91bd
Working!
mgyucht Jan 31, 2024
eb7097b
apply to all resources & data sources
mgyucht Jan 31, 2024
148ccaa
Merge branch 'main' into account-level-provider-for-workspace-resources
mgyucht Feb 1, 2024
8cfbb7d
extra
mgyucht Feb 1, 2024
f6cd6d0
fix
mgyucht Feb 1, 2024
703109d
extra
mgyucht Feb 1, 2024
9f35f59
fix
mgyucht Feb 1, 2024
7752299
use actual go SDK
mgyucht Feb 1, 2024
ab4c591
fix
mgyucht Feb 1, 2024
4d4edd2
comment
mgyucht Feb 2, 2024
ddf747a
Do not allow workspace_id for aws policy datasources
mgyucht Feb 2, 2024
468920b
change
mgyucht Feb 2, 2024
782b210
use main for diff-schema
mgyucht Feb 2, 2024
4ef15d3
Add fake create method to customizediff test
mgyucht Feb 5, 2024
f50673e
Merge branch 'main' into account-level-provider-for-workspace-resources
mgyucht Feb 5, 2024
20f35e2
fixes
mgyucht Feb 5, 2024
f3a0e4a
work
mgyucht Feb 6, 2024
affa5a5
Merge branch 'main' into account-level-provider-for-workspace-resources
mgyucht Feb 11, 2024
106d8cc
bump go sdk
mgyucht Feb 11, 2024
74d65f2
vaildate workspace ID
mgyucht Feb 11, 2024
9af9719
set original_workspace_id
mgyucht Feb 11, 2024
fe2a7cd
work
mgyucht Feb 11, 2024
ebbc581
work
mgyucht Feb 14, 2024
a4d3ca5
Merge branch 'main' into account-level-provider-for-workspace-resources
mgyucht Feb 21, 2024
2e385e8
fix merge
mgyucht Feb 21, 2024
a5b2dda
fix
mgyucht Feb 21, 2024
5874ead
fix
mgyucht Feb 21, 2024
d373d3b
fix
mgyucht Feb 21, 2024
1267f35
fix
mgyucht Feb 21, 2024
6f95828
some cleanups
mgyucht Feb 21, 2024
327d471
more cleanup
mgyucht Feb 21, 2024
10e586f
fix tests
mgyucht Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions aws/data_aws_assume_role_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ func DataAwsAssumeRolePolicy() common.Resource {
ForceNew: true,
},
},
WorkspaceIdField: common.NoWorkspaceId,
}
}
1 change: 1 addition & 0 deletions aws/data_aws_bucket_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ func DataAwsBucketPolicy() common.Resource {
ForceNew: true,
},
},
WorkspaceIdField: common.NoWorkspaceId,
}
}
1 change: 1 addition & 0 deletions aws/data_aws_crossaccount_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ func DataAwsCrossaccountPolicy() common.Resource {
ForceNew: true,
},
},
WorkspaceIdField: common.NoWorkspaceId,
}
}
4 changes: 3 additions & 1 deletion catalog/data_catalogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func DataSourceCatalogs() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
dataSource := common.WorkspaceData(func(ctx context.Context, data *struct {
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
}, w *databricks.WorkspaceClient) error {
catalogs, err := w.Catalogs.ListAll(ctx)
Expand All @@ -20,4 +20,6 @@ func DataSourceCatalogs() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_current_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func DataSourceCurrentMetastore() common.Resource {
Id string `json:"id,omitempty" tf:"computed"`
Metastore *catalog.GetMetastoreSummaryResponse `json:"metastore_info,omitempty" tf:"computed" `
}
return common.WorkspaceData(func(ctx context.Context, data *CurrentMetastore, wc *databricks.WorkspaceClient) error {
dataSource := common.WorkspaceData(func(ctx context.Context, data *CurrentMetastore, wc *databricks.WorkspaceClient) error {
summary, err := wc.Metastores.Summary(ctx)
if err != nil {
return err
Expand All @@ -23,4 +23,6 @@ func DataSourceCurrentMetastore() common.Resource {

return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ func DataSourceMetastore() common.Resource {
Id string `json:"metastore_id"`
Metastore *catalog.MetastoreInfo `json:"metastore_info,omitempty" tf:"computed" `
}
return common.AccountData(func(ctx context.Context, data *AccountMetastoreByID, acc *databricks.AccountClient) error {
dataSource := common.AccountData(func(ctx context.Context, data *AccountMetastoreByID, acc *databricks.AccountClient) error {
metastore, err := acc.Metastores.GetByMetastoreId(ctx, data.Id)
if err != nil {
return err
}
data.Metastore = metastore.MetastoreInfo
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_metastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func DataSourceMetastores() common.Resource {
type metastoresData struct {
Ids map[string]string `json:"ids,omitempty" tf:"computed"`
}
return common.AccountData(func(ctx context.Context, data *metastoresData, acc *databricks.AccountClient) error {
dataSource := common.AccountData(func(ctx context.Context, data *metastoresData, acc *databricks.AccountClient) error {
metastores, err := acc.Metastores.ListAll(ctx)
if err != nil {
return err
Expand All @@ -28,4 +28,6 @@ func DataSourceMetastores() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.NoWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func DataSourceSchemas() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
dataSource := common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
}, w *databricks.WorkspaceClient) error {
Expand All @@ -22,4 +22,6 @@ func DataSourceSchemas() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func DataSourceShare() common.Resource {
CreatedAt int64 `json:"created_at,omitempty" tf:"computed"`
CreatedBy string `json:"created_by,omitempty" tf:"computed"`
}
return common.DataResource(ShareDetail{}, func(ctx context.Context, e any, c *common.DatabricksClient) error {
dataSource := common.DataResource(ShareDetail{}, func(ctx context.Context, e any, c *common.DatabricksClient) error {
data := e.(*ShareDetail)
sharesAPI := NewSharesAPI(ctx, c)
share, err := sharesAPI.get(data.Name)
Expand All @@ -25,4 +25,6 @@ func DataSourceShare() common.Resource {
data.CreatedBy = share.CreatedBy
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func DataSourceShares() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
dataSource := common.WorkspaceData(func(ctx context.Context, data *struct {
Shares []string `json:"shares,omitempty" tf:"computed,slice_set"`
}, w *databricks.WorkspaceClient) error {

Expand All @@ -21,4 +21,6 @@ func DataSourceShares() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func DataSourceTables() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
dataSource := common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
SchemaName string `json:"schema_name"`
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
Expand All @@ -25,4 +25,6 @@ func DataSourceTables() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
4 changes: 3 additions & 1 deletion catalog/data_views.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func DataSourceViews() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
dataSource := common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
SchemaName string `json:"schema_name"`
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
Expand All @@ -26,4 +26,6 @@ func DataSourceViews() common.Resource {
}
return nil
})
dataSource.WorkspaceIdField = common.ManagementWorkspaceId
return dataSource
}
1 change: 1 addition & 0 deletions catalog/resource_artifact_allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ func ResourceArtifactAllowlist() common.Resource {

return nil
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ func ResourceCatalog() common.Resource {
}
return w.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{Force: force, Name: d.Id()})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_catalog_workspace_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func ResourceCatalogWorkspaceBinding() common.Resource {
})
return err
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}

Expand Down
1 change: 1 addition & 0 deletions catalog/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ func ResourceConnection() common.Resource {
}
return w.Connections.DeleteByName(ctx, connName)
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_external_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,6 @@ func ResourceExternalLocation() common.Resource {
Force: force,
})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,6 @@ func ResourceGrant() common.Resource {
unityCatalogPermissionsAPI := permissions.NewUnityCatalogPermissionsAPI(ctx, c)
return replacePermissionsForPrincipal(unityCatalogPermissionsAPI, securable, name, principal, catalog.PermissionsList{})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,5 +392,6 @@ func ResourceGrants() common.Resource {
unityCatalogPermissionsAPI := permissions.NewUnityCatalogPermissionsAPI(ctx, c)
return replaceAllPermissions(unityCatalogPermissionsAPI, securable, name, catalog.PermissionsList{})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,6 @@ func ResourceMetastore() common.Resource {
return w.Metastores.Delete(ctx, catalog.DeleteMetastoreRequest{Force: force, Id: d.Id()})
})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_metastore_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ func ResourceMetastoreAssignment() common.Resource {
})
})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_metastore_data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func ResourceMetastoreDataAccess() common.Resource {
})
})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}

Expand Down
1 change: 1 addition & 0 deletions catalog/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ func ResourceProvider() common.Resource {
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
return NewProvidersAPI(ctx, c).deleteProvider(d.Id())
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
7 changes: 4 additions & 3 deletions catalog/resource_registered_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ func ResourceRegisteredModel() common.Resource {
}
return w.RegisteredModels.DeleteByFullName(ctx, d.Id())
},
StateUpgraders: []schema.StateUpgrader{},
Schema: s,
SchemaVersion: 0,
StateUpgraders: []schema.StateUpgrader{},
Schema: s,
SchemaVersion: 0,
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@ func ResourceSchema() common.Resource {
}
return w.Schemas.DeleteByFullName(ctx, name)
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,6 @@ func ResourceShare() common.Resource {
}
return w.Shares.DeleteByName(ctx, d.Id())
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_sql_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,6 @@ func ResourceSqlTable() common.Resource {
}
return ti.deleteTable()
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_storage_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,6 @@ func ResourceStorageCredential() common.Resource {
})
})
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_system_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ func ResourceSystemSchema() common.Resource {
SchemaName: catalog.DisableSchemaName(schemaName),
})
},
WorkspaceIdField: common.WorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ func ResourceTable() common.Resource {
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
return NewTablesAPI(ctx, c).deleteTable(d.Id())
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
1 change: 1 addition & 0 deletions catalog/resource_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ func ResourceVolume() common.Resource {
}
return w.Volumes.DeleteByName(ctx, d.Id())
},
WorkspaceIdField: common.ManagementWorkspaceId,
}
}
3 changes: 2 additions & 1 deletion clusters/data_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func TestClustersDataSourceErrorsOut(t *testing.T) {
RetryTimeoutSeconds: 1,
HTTPTimeoutSeconds: 1,
})
diag := DataSourceClusters().ToResource().ReadContext(context.Background(), nil, &common.DatabricksClient{
resource := DataSourceClusters().ToResource()
diag := resource.ReadContext(context.Background(), resource.TestResourceData(), &common.DatabricksClient{
DatabricksClient: client,
})
assert.NotNil(t, diag)
Expand Down
Loading
Loading