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

[WIP] Account level provider for workspace resources stack #3194

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions access/resource_ip_access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ipAccessListUpdateRequest struct {
}

// ResourceIPAccessList manages IP access lists
func ResourceIPAccessList() *schema.Resource {
func ResourceIPAccessList() common.Resource {
s := common.StructToSchema(ipAccessListUpdateRequest{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
// nolint
s["list_type"].ValidateFunc = validation.StringInSlice([]string{"ALLOW", "BLOCK"}, false)
Expand Down Expand Up @@ -73,5 +73,5 @@ func ResourceIPAccessList() *schema.Resource {
}
return w.IpAccessLists.DeleteByIpAccessListId(ctx, d.Id())
},
}.ToResource()
}
}
4 changes: 2 additions & 2 deletions access/resource_permission_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func mustInt64(s string) int64 {
// ResourcePermissionAssignment performs of users to a workspace
// from a workspace context, though it requires additional set
// data resource for "workspace account scim", whicl will be added later.
func ResourcePermissionAssignment() *schema.Resource {
func ResourcePermissionAssignment() common.Resource {
type entity struct {
PrincipalId int64 `json:"principal_id"`
Permissions []string `json:"permissions" tf:"slice_as_set"`
Expand Down Expand Up @@ -113,5 +113,5 @@ func ResourcePermissionAssignment() *schema.Resource {
Delete: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
return NewPermissionAssignmentAPI(ctx, c).Remove(d.Id())
},
}.ToResource()
}
}
4 changes: 2 additions & 2 deletions access/resource_sql_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func tableAclForLoad(ctx context.Context, d *schema.ResourceData,
}

// ResourceSqlPermissions manages table ACLs
func ResourceSqlPermissions() *schema.Resource {
func ResourceSqlPermissions() common.Resource {
s := common.StructToSchema(SqlPermissions{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
alof := []string{"database", "table", "view", "catalog", "any_file", "anonymous_function"}
for _, field := range alof {
Expand Down Expand Up @@ -376,5 +376,5 @@ func ResourceSqlPermissions() *schema.Resource {
}
return ta.revoke()
},
}.ToResource()
}
}
10 changes: 5 additions & 5 deletions aws/data_aws_assume_role_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -27,9 +27,9 @@ type awsIamPolicyStatement struct {
}

// DataAwsAssumeRolePolicy ...
func DataAwsAssumeRolePolicy() *schema.Resource {
return &schema.Resource{
ReadContext: func(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
func DataAwsAssumeRolePolicy() common.Resource {
return common.Resource{
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
externalID := d.Get("external_id").(string)
policy := awsIamPolicy{
Version: "2012-10-17",
Expand Down Expand Up @@ -57,7 +57,7 @@ func DataAwsAssumeRolePolicy() *schema.Resource {
}
policyJSON, err := json.MarshalIndent(policy, "", " ")
if err != nil {
return diag.FromErr(err)
return err
}
d.SetId(externalID)
// nolint
Expand Down
10 changes: 5 additions & 5 deletions aws/data_aws_bucket_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

// DataAwsBucketPolicy ...
func DataAwsBucketPolicy() *schema.Resource {
return &schema.Resource{
ReadContext: func(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
func DataAwsBucketPolicy() common.Resource {
return common.Resource{
Read: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
bucket := d.Get("bucket").(string)
policy := awsIamPolicy{
Version: "2012-10-17",
Expand Down Expand Up @@ -52,7 +52,7 @@ func DataAwsBucketPolicy() *schema.Resource {
}
policyJSON, err := json.MarshalIndent(policy, "", " ")
if err != nil {
return diag.FromErr(err)
return err
}
d.SetId(bucket)
// nolint
Expand Down
10 changes: 5 additions & 5 deletions aws/data_aws_crossaccount_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// DataAwsCrossaccountPolicy defines the cross-account policy
func DataAwsCrossaccountPolicy() *schema.Resource {
return &schema.Resource{
ReadContext: func(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
func DataAwsCrossaccountPolicy() common.Resource {
return common.Resource{
Read: func(ctx context.Context, d *schema.ResourceData, m *common.DatabricksClient) error {
policy := awsIamPolicy{
Version: "2012-10-17",
Statements: []*awsIamPolicyStatement{
Expand Down Expand Up @@ -126,7 +126,7 @@ func DataAwsCrossaccountPolicy() *schema.Resource {
}
policyJSON, err := json.MarshalIndent(policy, "", " ")
if err != nil {
return diag.FromErr(err)
return err
}
d.SetId("cross-account")
// nolint
Expand Down
3 changes: 1 addition & 2 deletions aws/data_instance_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceInstanceProfiles() *schema.Resource {
func DataSourceInstanceProfiles() common.Resource {
type instanceProfileData struct {
Name string `json:"name,omitempty" tf:"computed"`
Arn string `json:"arn,omitempty" tf:"computed"`
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_group_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// ResourceGroupInstanceProfile defines group role resource
func ResourceGroupInstanceProfile() *schema.Resource {
func ResourceGroupInstanceProfile() common.Resource {
r := common.NewPairID("group_id", "instance_profile_id").Schema(func(
m map[string]*schema.Schema) map[string]*schema.Schema {
m["instance_profile_id"].ValidateDiagFunc = ValidArn
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (a InstanceProfilesAPI) Synchronized(arn string, testCallback func() bool)
}

// ResourceInstanceProfile manages Instance Profile ARN binding
func ResourceInstanceProfile() *schema.Resource {
func ResourceInstanceProfile() common.Resource {
instanceProfileSchema := common.StructToSchema(InstanceProfileInfo{},
func(m map[string]*schema.Schema) map[string]*schema.Schema {
m["instance_profile_arn"].ValidateDiagFunc = ValidArn
Expand Down Expand Up @@ -181,7 +181,7 @@ func ResourceInstanceProfile() *schema.Resource {
common.DataToStructPointer(d, instanceProfileSchema, &profile)
return NewInstanceProfilesAPI(ctx, c).Update(profile)
},
}.ToResource()
}
}

// ValidArn validate if it's valid instance profile or role ARN
Expand Down
4 changes: 1 addition & 3 deletions aws/resource_service_principal_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/scim"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// ResourceServicePrincipalRole binds service principal and instance profile
func ResourceServicePrincipalRole() *schema.Resource {
func ResourceServicePrincipalRole() common.Resource {
r := common.NewPairID("service_principal_id", "role").BindResource(common.BindResource{
CreateContext: func(ctx context.Context, servicePrincipalID, role string, c *common.DatabricksClient) error {
return scim.NewServicePrincipalsAPI(ctx, c).Patch(servicePrincipalID, scim.PatchRequest("add", "roles", role))
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_user_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// ResourceUserInstanceProfile binds user and instance profile
func ResourceUserInstanceProfile() *schema.Resource {
func ResourceUserInstanceProfile() common.Resource {
r := common.NewPairID("user_id", "instance_profile_id").Schema(func(
m map[string]*schema.Schema) map[string]*schema.Schema {
m["instance_profile_id"].ValidateDiagFunc = ValidArn
Expand Down
3 changes: 1 addition & 2 deletions aws/resource_user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/scim"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func ResourceUserRole() *schema.Resource {
func ResourceUserRole() common.Resource {
return common.NewPairID("user_id", "role").BindResource(common.BindResource{
CreateContext: func(ctx context.Context, userID, role string, c *common.DatabricksClient) error {
return scim.NewUsersAPI(ctx, c).Patch(userID, scim.PatchRequest("add", "roles", role))
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_catalogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceCatalogs() *schema.Resource {
func DataSourceCatalogs() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
}, w *databricks.WorkspaceClient) error {
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_current_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceCurrentMetastore() *schema.Resource {
func DataSourceCurrentMetastore() common.Resource {
type CurrentMetastore struct {
Id string `json:"id,omitempty" tf:"computed"`
Metastore *catalog.GetMetastoreSummaryResponse `json:"metastore_info,omitempty" tf:"computed" `
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceMetastore() *schema.Resource {
func DataSourceMetastore() common.Resource {
type AccountMetastoreByID struct {
Id string `json:"metastore_id"`
Metastore *catalog.MetastoreInfo `json:"metastore_info,omitempty" tf:"computed" `
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_metastores.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceMetastores() *schema.Resource {
func DataSourceMetastores() common.Resource {
type metastoresData struct {
Ids map[string]string `json:"ids,omitempty" tf:"computed"`
}
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceSchemas() *schema.Resource {
func DataSourceSchemas() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
Ids []string `json:"ids,omitempty" tf:"computed,slice_set"`
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"

"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceShare() *schema.Resource {
func DataSourceShare() common.Resource {
type ShareDetail struct {
Name string `json:"name,omitempty" tf:"computed"`
Objects []SharedDataObject `json:"objects,omitempty" tf:"computed,slice_set,alias:object"`
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceShares() *schema.Resource {
func DataSourceShares() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
Shares []string `json:"shares,omitempty" tf:"computed,slice_set"`
}, w *databricks.WorkspaceClient) error {
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceTables() *schema.Resource {
func DataSourceTables() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
SchemaName string `json:"schema_name"`
Expand Down
3 changes: 1 addition & 2 deletions catalog/data_views.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import (
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/terraform-provider-databricks/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceViews() *schema.Resource {
func DataSourceViews() common.Resource {
return common.WorkspaceData(func(ctx context.Context, data *struct {
CatalogName string `json:"catalog_name"`
SchemaName string `json:"schema_name"`
Expand Down
4 changes: 2 additions & 2 deletions catalog/resource_artifact_allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ArtifactAllowlistInfo struct {
MetastoreId string `json:"metastore_id,omitempty" tf:"computed"`
}

func ResourceArtifactAllowlist() *schema.Resource {
func ResourceArtifactAllowlist() common.Resource {
allowlistSchema := common.StructToSchema(ArtifactAllowlistInfo{}, common.NoCustomize)
p := common.NewPairID("metastore_id", "artifact_type")

Expand Down Expand Up @@ -107,5 +107,5 @@ func ResourceArtifactAllowlist() *schema.Resource {

return nil
},
}.ToResource()
}
}
4 changes: 2 additions & 2 deletions catalog/resource_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CatalogInfo struct {
MetastoreID string `json:"metastore_id,omitempty" tf:"computed"`
}

func ResourceCatalog() *schema.Resource {
func ResourceCatalog() common.Resource {
catalogSchema := common.StructToSchema(CatalogInfo{},
func(m map[string]*schema.Schema) map[string]*schema.Schema {
m["force_destroy"] = &schema.Schema{
Expand Down Expand Up @@ -219,5 +219,5 @@ func ResourceCatalog() *schema.Resource {
}
return w.Catalogs.Delete(ctx, catalog.DeleteCatalogRequest{Force: force, Name: d.Id()})
},
}.ToResource()
}
}
4 changes: 2 additions & 2 deletions catalog/resource_catalog_workspace_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var getSecurableName = func(d *schema.ResourceData) string {
return securableName.(string)
}

func ResourceCatalogWorkspaceBinding() *schema.Resource {
func ResourceCatalogWorkspaceBinding() common.Resource {
workspaceBindingSchema := common.StructToSchema(catalog.WorkspaceBinding{},
func(m map[string]*schema.Schema) map[string]*schema.Schema {
m["catalog_name"] = &schema.Schema{
Expand Down Expand Up @@ -109,7 +109,7 @@ func ResourceCatalogWorkspaceBinding() *schema.Resource {
})
return err
},
}.ToResource()
}
}

// migrate to v1 state, as catalog_name is moved to securable_name
Expand Down
4 changes: 2 additions & 2 deletions catalog/resource_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ConnectionInfo struct {

var sensitiveOptions = []string{"user", "password", "personalAccessToken", "access_token", "client_secret", "OAuthPvtKey", "GoogleServiceAccountKeyJson"}

func ResourceConnection() *schema.Resource {
func ResourceConnection() common.Resource {
s := common.StructToSchema(ConnectionInfo{},
common.NoCustomize)
pi := common.NewPairID("metastore_id", "name").Schema(
Expand Down Expand Up @@ -156,5 +156,5 @@ func ResourceConnection() *schema.Resource {
}
return w.Connections.DeleteByNameArg(ctx, connName)
},
}.ToResource()
}
}
4 changes: 2 additions & 2 deletions catalog/resource_external_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ExternalLocationInfo struct {
EncDetails *catalog.EncryptionDetails `json:"encryption_details,omitempty"`
}

func ResourceExternalLocation() *schema.Resource {
func ResourceExternalLocation() common.Resource {
s := common.StructToSchema(ExternalLocationInfo{},
func(m map[string]*schema.Schema) map[string]*schema.Schema {
m["force_destroy"] = &schema.Schema{
Expand Down Expand Up @@ -141,5 +141,5 @@ func ResourceExternalLocation() *schema.Resource {
Force: force,
})
},
}.ToResource()
}
}
Loading
Loading