diff --git a/.gitignore b/.gitignore index fea74b3377..87d1af1516 100644 --- a/.gitignore +++ b/.gitignore @@ -340,4 +340,6 @@ tf.log scripts/tt -.metals \ No newline at end of file +.metals + +provider/completeness.md \ No newline at end of file diff --git a/README.md b/README.md index 5e64b448a0..0aa381cee1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ | [databricks_dbfs_file](docs/resources/dbfs_file.md) | [databricks_dbfs_file_paths](docs/data-sources/dbfs_file_paths.md) data | [databricks_dbfs_file](docs/data-sources/dbfs_file.md) data +| [databricks_directory](docs/resources/directory.md) | [databricks_external_location](docs/resources/external_location.md) +| [databricks_git_credential](docs/resources/git_credential.md) | [databricks_global_init_script](docs/resources/global_init_script.md) | [databricks_grants](docs/resources/grants.md) | [databricks_group](docs/resources/group.md) @@ -31,17 +33,22 @@ | [databricks_instance_profile](docs/resources/instance_profile.md) | [databricks_ip_access_list](docs/resources/ip_access_list.md) | [databricks_job](docs/resources/job.md) +| [databricks_jobs](docs/data-sources/jobs.md) | [databricks_library](docs/resources/library.md) | [databricks_metastore](docs/resources/metastore.md) | [databricks_metastore_assignment](docs/resources/metastore_assignment.md) | [databricks_metastore_data_access](docs/resources/metastore_data_access.md) | [databricks_mlflow_model](docs/resources/mlflow_model.md) | [databricks_mlflow_experiment](docs/resources/mlflow_experiment.md) +| [databricks_mlflow_webhook](docs/resources/mlflow_webhook.md) +| [databricks_mount](docs/resources/mount.md) | [databricks_mws_credentials](docs/resources/mws_credentials.md) | [databricks_mws_customer_managed_keys](docs/resources/mws_customer_managed_keys.md) | [databricks_mws_log_delivery](docs/resources/mws_log_delivery.md) | [databricks_mws_networks](docs/resources/mws_networks.md) +| [databricks_mws_private_access_settings](docs/resources/mws_private_access_settings.md) | [databricks_mws_storage_configurations](docs/resources/mws_storage_configurations.md) +| [databricks_mws_vpc_endpoint](docs/resources/mws_vpc_endpoint.md) | [databricks_mws_workspaces](docs/resources/mws_workspaces.md) | [databricks_node_type](docs/data-sources/node_type.md) data | [databricks_notebook](docs/resources/notebook.md) @@ -56,6 +63,8 @@ | [databricks_secret](docs/resources/secret.md) | [databricks_secret_acl](docs/resources/secret_acl.md) | [databricks_secret_scope](docs/resources/secret_scope.md) +| [databricks_service_principal](docs/resources/service_principal.md) +| [databricks_service_principal_role](docs/resources/service_principal_role.md) | [databricks_spark_version](docs/data-sources/spark_version.md) data | [databricks_sql_dashboard](docs/resources/sql_dashboard.md) | [databricks_sql_endpoint](docs/resources/sql_endpoint.md) @@ -69,8 +78,11 @@ | [databricks_tables](docs/data-sources/table.md) data | [databricks_token](docs/resources/token.md) | [databricks_user](docs/resources/user.md) +| [databricks_user_role](docs/resources/user_role.md) | [databricks_user_instance_profile](docs/resources/user_instance_profile.md) +| [databricks_views](docs/data-sources/views.md) data | [databricks_workspace_conf](docs/resources/workspace_conf.md) +| [databricks_zones](docs/data-sources/zones.md) | [Contributing and Development Guidelines](CONTRIBUTING.md) [![build](https://github.com/databrickslabs/terraform-provider-databricks/workflows/build/badge.svg?branch=master)](https://github.com/databrickslabs/terraform-provider-databricks/actions?query=workflow%3Abuild+branch%3Amaster) [![codecov](https://codecov.io/gh/databrickslabs/terraform-provider-databricks/branch/master/graph/badge.svg)](https://codecov.io/gh/databrickslabs/terraform-provider-databricks) ![lines](https://img.shields.io/tokei/lines/github/databrickslabs/terraform-provider-databricks) [![downloads](https://img.shields.io/github/downloads/databrickslabs/terraform-provider-databricks/total.svg)](https://hanadigital.github.io/grev/?user=databrickslabs&repo=terraform-provider-databricks) diff --git a/access/resource_ipaccesslist.go b/access/resource_ip_access_list.go similarity index 100% rename from access/resource_ipaccesslist.go rename to access/resource_ip_access_list.go diff --git a/access/resource_ipaccesslist_test.go b/access/resource_ip_access_list_test.go similarity index 100% rename from access/resource_ipaccesslist_test.go rename to access/resource_ip_access_list_test.go diff --git a/aws/data_aws_assume_role_policy.go b/aws/data_aws_assume_role_policy.go new file mode 100644 index 0000000000..f604325ffc --- /dev/null +++ b/aws/data_aws_assume_role_policy.go @@ -0,0 +1,91 @@ +package aws + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +type awsIamPolicy struct { + Version string `json:"Version,omitempty"` + ID string `json:"Id,omitempty"` + Statements []*awsIamPolicyStatement `json:"Statement"` +} + +type awsIamPolicyStatement struct { + Sid string `json:"Sid,omitempty"` + Effect string `json:"Effect,omitempty"` + Actions interface{} `json:"Action,omitempty"` + NotActions interface{} `json:"NotAction,omitempty"` + Resources interface{} `json:"Resource,omitempty"` + NotResources interface{} `json:"NotResource,omitempty"` + Principal map[string]string `json:"Principal,omitempty"` + Condition map[string]map[string]string `json:"Condition,omitempty"` +} + + +// DataAwsAssumeRolePolicy ... +func DataAwsAssumeRolePolicy() *schema.Resource { + return &schema.Resource{ + ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + externalID := d.Get("external_id").(string) + policy := awsIamPolicy{ + Version: "2012-10-17", + Statements: []*awsIamPolicyStatement{ + { + Effect: "Allow", + Actions: "sts:AssumeRole", + Condition: map[string]map[string]string{ + "StringEquals": { + "sts:ExternalId": externalID, + }, + }, + Principal: map[string]string{ + "AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)), + }, + }, + }, + } + if v, ok := d.GetOk("for_log_delivery"); ok { + if v.(bool) { + // this is production UsageDelivery IAM role, that is considered a constant + logDeliveryARN := "arn:aws:iam::414351767826:role/SaasUsageDeliveryRole-prod-IAMRole-3PLHICCRR1TK" + policy.Statements[0].Principal["AWS"] = logDeliveryARN + } + } + policyJSON, err := json.MarshalIndent(policy, "", " ") + if err != nil { + return diag.FromErr(err) + } + d.SetId(externalID) + // nolint + d.Set("json", string(policyJSON)) + return nil + }, + Schema: map[string]*schema.Schema{ + "databricks_account_id": { + Type: schema.TypeString, + Default: "414351767826", + Optional: true, + }, + "for_log_delivery": { + Type: schema.TypeBool, + Description: "Grant AssumeRole to Databricks SaasUsageDeliveryRole instead of root account", + Optional: true, + Default: false, + }, + "external_id": { + Type: schema.TypeString, + Required: true, + }, + "json": { + Type: schema.TypeString, + Computed: true, + ForceNew: true, + }, + }, + } +} diff --git a/aws/data_aws_assume_role_policy_test.go b/aws/data_aws_assume_role_policy_test.go new file mode 100644 index 0000000000..be7d124a1c --- /dev/null +++ b/aws/data_aws_assume_role_policy_test.go @@ -0,0 +1,21 @@ +package aws + +import ( + "testing" + + "github.com/databrickslabs/terraform-provider-databricks/qa" + "github.com/stretchr/testify/assert" +) + +func TestDataAwsAssumeRolePolicy(t *testing.T) { + d, err := qa.ResourceFixture{ + Read: true, + Resource: DataAwsAssumeRolePolicy(), + NonWritable: true, + ID: ".", + HCL: `external_id = "abc"`, + }.Apply(t) + assert.NoError(t, err) + j := d.Get("json") + assert.Lenf(t, j, 299, "Strange length for policy: %s", j) +} \ No newline at end of file diff --git a/aws/data_aws_bucket_policy.go b/aws/data_aws_bucket_policy.go new file mode 100644 index 0000000000..8dd1aebbcc --- /dev/null +++ b/aws/data_aws_bucket_policy.go @@ -0,0 +1,78 @@ +package aws + +import ( + "context" + "encoding/json" + "fmt" + "regexp" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "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 interface{}) diag.Diagnostics { + bucket := d.Get("bucket").(string) + policy := awsIamPolicy{ + Version: "2012-10-17", + Statements: []*awsIamPolicyStatement{ + { + Effect: "Allow", + Actions: []string{ + "s3:GetObject", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:DeleteObject", + "s3:ListBucket", + "s3:GetBucketLocation", + }, + Resources: []string{ + fmt.Sprintf("arn:aws:s3:::%s/*", bucket), + fmt.Sprintf("arn:aws:s3:::%s", bucket), + }, + Principal: map[string]string{ + "AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)), + }, + }, + }, + } + if v, ok := d.GetOk("full_access_role"); ok { + policy.Statements[0].Principal["AWS"] = v.(string) + } + policyJSON, err := json.MarshalIndent(policy, "", " ") + if err != nil { + return diag.FromErr(err) + } + d.SetId(bucket) + // nolint + d.Set("json", string(policyJSON)) + return nil + }, + Schema: map[string]*schema.Schema{ + "databricks_account_id": { + Type: schema.TypeString, + Default: "414351767826", + Optional: true, + }, + "full_access_role": { + Type: schema.TypeString, + Optional: true, + }, + "bucket": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile(`^[0-9a-zA-Z_-]+$`), + "must contain only alphanumeric, underscore, and hyphen characters"), + }, + "json": { + Type: schema.TypeString, + Computed: true, + ForceNew: true, + }, + }, + } +} diff --git a/aws/data_aws_bucket_policy_test.go b/aws/data_aws_bucket_policy_test.go new file mode 100644 index 0000000000..ebd3b91c37 --- /dev/null +++ b/aws/data_aws_bucket_policy_test.go @@ -0,0 +1,39 @@ +package aws + +import ( + "testing" + + "github.com/databrickslabs/terraform-provider-databricks/qa" + "github.com/stretchr/testify/assert" +) + +func TestDataAwsBucketPolicy(t *testing.T) { + d, err := qa.ResourceFixture{ + Read: true, + Resource: DataAwsBucketPolicy(), + NonWritable: true, + ID: ".", + HCL: ` + bucket = "abc" + `, + }.Apply(t) + assert.NoError(t, err) + j := d.Get("json") + assert.Lenf(t, j, 440, "Strange length for policy: %s", j) +} + +func TestDataAwsBucketPolicy_FullAccessRole(t *testing.T) { + d, err := qa.ResourceFixture{ + Read: true, + Resource: DataAwsBucketPolicy(), + NonWritable: true, + ID: ".", + HCL: ` + bucket = "abc" + full_access_role = "bcd" + `, + }.Apply(t) + assert.NoError(t, err) + j := d.Get("json") + assert.Lenf(t, j, 413, "Strange length for policy: %s", j) +} diff --git a/aws/data_aws_crossaccount_policy.go b/aws/data_aws_crossaccount_policy.go new file mode 100644 index 0000000000..74d6fc7e27 --- /dev/null +++ b/aws/data_aws_crossaccount_policy.go @@ -0,0 +1,135 @@ +package aws + +import ( + "context" + "encoding/json" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "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 interface{}) diag.Diagnostics { + policy := awsIamPolicy{ + Version: "2012-10-17", + Statements: []*awsIamPolicyStatement{ + { + Effect: "Allow", + Actions: []string{ + "ec2:AssociateDhcpOptions", + "ec2:AssociateIamInstanceProfile", + "ec2:AssociateRouteTable", + "ec2:AttachInternetGateway", + "ec2:AttachVolume", + "ec2:AuthorizeSecurityGroupEgress", + "ec2:AuthorizeSecurityGroupIngress", + "ec2:CancelSpotInstanceRequests", + "ec2:CreateDhcpOptions", + "ec2:CreateInternetGateway", + "ec2:CreateKeyPair", + "ec2:CreateRoute", + "ec2:CreateSecurityGroup", + "ec2:CreateSubnet", + "ec2:CreateTags", + "ec2:CreateVolume", + "ec2:CreateVpc", + "ec2:DeleteInternetGateway", + "ec2:DeleteKeyPair", + "ec2:DeleteRoute", + "ec2:DeleteRouteTable", + "ec2:DeleteSecurityGroup", + "ec2:DeleteSubnet", + "ec2:DeleteTags", + "ec2:DeleteVolume", + "ec2:DeleteVpc", + "ec2:DescribeAvailabilityZones", + "ec2:DescribeNetworkAcls", + "ec2:DescribeInternetGateways", + "ec2:DescribeVpcAttribute", + "ec2:DescribeIamInstanceProfileAssociations", + "ec2:DescribeInstanceStatus", + "ec2:DescribeInstances", + "ec2:DescribePrefixLists", + "ec2:DescribeReservedInstancesOfferings", + "ec2:DescribeRouteTables", + "ec2:DescribeSecurityGroups", + "ec2:DescribeSpotInstanceRequests", + "ec2:DescribeSpotPriceHistory", + "ec2:DescribeSubnets", + "ec2:DescribeVolumes", + "ec2:DescribeVpcs", + "ec2:DetachInternetGateway", + "ec2:DisassociateIamInstanceProfile", + "ec2:ModifyVpcAttribute", + "ec2:ReplaceIamInstanceProfileAssociation", + "ec2:RequestSpotInstances", + "ec2:RevokeSecurityGroupEgress", + "ec2:RevokeSecurityGroupIngress", + "ec2:RunInstances", + "ec2:TerminateInstances", + "ec2:CreatePlacementGroup", + "ec2:DeletePlacementGroup", + "ec2:DescribePlacementGroups", + "ec2:AllocateAddress", + "ec2:CreateNatGateway", + "ec2:CreateRouteTable", + "ec2:CreateVpcEndpoint", + "ec2:DeleteDhcpOptions", + "ec2:DeleteNatGateway", + "ec2:DeleteVpcEndpoints", + "ec2:DescribeNatGateways", + "ec2:DisassociateRouteTable", + "ec2:ReleaseAddress", + "ec2:DetachVolume", + }, + Resources: "*", + }, + { + Effect: "Allow", + Actions: []string{ + "iam:CreateServiceLinkedRole", + "iam:PutRolePolicy", + }, + Resources: "arn:aws:iam::*:role/aws-service-role/spot.amazonaws.com/AWSServiceRoleForEC2Spot", + Condition: map[string]map[string]string{ + "StringLike": { + "iam:AWSServiceName": "spot.amazonaws.com", + }, + }, + }, + }, + } + if passRoleARNs, ok := d.GetOk("pass_roles"); ok { + policy.Statements = append(policy.Statements, &awsIamPolicyStatement{ + Effect: "Allow", + Actions: "iam:PassRole", + Resources: passRoleARNs, + }) + } + policyJSON, err := json.MarshalIndent(policy, "", " ") + if err != nil { + return diag.FromErr(err) + } + d.SetId("cross-account") + // nolint + d.Set("json", string(policyJSON)) + return nil + }, + Schema: map[string]*schema.Schema{ + "pass_roles": { + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Optional: true, + }, + "json": { + Type: schema.TypeString, + Computed: true, + ForceNew: true, + }, + }, + } +} diff --git a/aws/data_aws_crossaccount_policy_test.go b/aws/data_aws_crossaccount_policy_test.go new file mode 100644 index 0000000000..53ddb01734 --- /dev/null +++ b/aws/data_aws_crossaccount_policy_test.go @@ -0,0 +1,33 @@ +package aws + +import ( + "testing" + + "github.com/databrickslabs/terraform-provider-databricks/qa" + "github.com/stretchr/testify/assert" +) + +func TestDataAwsCrossAccountPolicy(t *testing.T) { + d, err := qa.ResourceFixture{ + Read: true, + Resource: DataAwsCrossaccountPolicy(), + NonWritable: true, + ID: ".", + }.Apply(t) + assert.NoError(t, err) + j := d.Get("json") + assert.Lenf(t, j, 2759, "Strange length for policy: %s", j) +} + +func TestDataAwsCrossAccountPolicy_WithPassRoles(t *testing.T) { + d, err := qa.ResourceFixture{ + Read: true, + Resource: DataAwsCrossaccountPolicy(), + NonWritable: true, + HCL: `pass_roles = ["a", "b", "c"]`, + ID: ".", + }.Apply(t) + assert.NoError(t, err) + j := d.Get("json") + assert.Lenf(t, j, 2895, "Strange length for policy: %s", j) +} diff --git a/aws/data_aws_policies.go b/aws/data_aws_policies.go deleted file mode 100644 index 270616eeaf..0000000000 --- a/aws/data_aws_policies.go +++ /dev/null @@ -1,284 +0,0 @@ -package aws - -import ( - "context" - "encoding/json" - "fmt" - "regexp" - - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" -) - -type awsIamPolicy struct { - Version string `json:"Version,omitempty"` - ID string `json:"Id,omitempty"` - Statements []*awsIamPolicyStatement `json:"Statement"` -} - -type awsIamPolicyStatement struct { - Sid string `json:"Sid,omitempty"` - Effect string `json:"Effect,omitempty"` - Actions interface{} `json:"Action,omitempty"` - NotActions interface{} `json:"NotAction,omitempty"` - Resources interface{} `json:"Resource,omitempty"` - NotResources interface{} `json:"NotResource,omitempty"` - Principal map[string]string `json:"Principal,omitempty"` - Condition map[string]map[string]string `json:"Condition,omitempty"` -} - -// DataAwsCrossAccountPolicy ... -func DataAwsCrossAccountPolicy() *schema.Resource { - return &schema.Resource{ - ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - policy := awsIamPolicy{ - Version: "2012-10-17", - Statements: []*awsIamPolicyStatement{ - { - Effect: "Allow", - Actions: []string{ - "ec2:AssociateDhcpOptions", - "ec2:AssociateIamInstanceProfile", - "ec2:AssociateRouteTable", - "ec2:AttachInternetGateway", - "ec2:AttachVolume", - "ec2:AuthorizeSecurityGroupEgress", - "ec2:AuthorizeSecurityGroupIngress", - "ec2:CancelSpotInstanceRequests", - "ec2:CreateDhcpOptions", - "ec2:CreateInternetGateway", - "ec2:CreateKeyPair", - "ec2:CreateRoute", - "ec2:CreateSecurityGroup", - "ec2:CreateSubnet", - "ec2:CreateTags", - "ec2:CreateVolume", - "ec2:CreateVpc", - "ec2:DeleteInternetGateway", - "ec2:DeleteKeyPair", - "ec2:DeleteRoute", - "ec2:DeleteRouteTable", - "ec2:DeleteSecurityGroup", - "ec2:DeleteSubnet", - "ec2:DeleteTags", - "ec2:DeleteVolume", - "ec2:DeleteVpc", - "ec2:DescribeAvailabilityZones", - "ec2:DescribeNetworkAcls", - "ec2:DescribeInternetGateways", - "ec2:DescribeVpcAttribute", - "ec2:DescribeIamInstanceProfileAssociations", - "ec2:DescribeInstanceStatus", - "ec2:DescribeInstances", - "ec2:DescribePrefixLists", - "ec2:DescribeReservedInstancesOfferings", - "ec2:DescribeRouteTables", - "ec2:DescribeSecurityGroups", - "ec2:DescribeSpotInstanceRequests", - "ec2:DescribeSpotPriceHistory", - "ec2:DescribeSubnets", - "ec2:DescribeVolumes", - "ec2:DescribeVpcs", - "ec2:DetachInternetGateway", - "ec2:DisassociateIamInstanceProfile", - "ec2:ModifyVpcAttribute", - "ec2:ReplaceIamInstanceProfileAssociation", - "ec2:RequestSpotInstances", - "ec2:RevokeSecurityGroupEgress", - "ec2:RevokeSecurityGroupIngress", - "ec2:RunInstances", - "ec2:TerminateInstances", - "ec2:CreatePlacementGroup", - "ec2:DeletePlacementGroup", - "ec2:DescribePlacementGroups", - "ec2:AllocateAddress", - "ec2:CreateNatGateway", - "ec2:CreateRouteTable", - "ec2:CreateVpcEndpoint", - "ec2:DeleteDhcpOptions", - "ec2:DeleteNatGateway", - "ec2:DeleteVpcEndpoints", - "ec2:DescribeNatGateways", - "ec2:DisassociateRouteTable", - "ec2:ReleaseAddress", - "ec2:DetachVolume", - }, - Resources: "*", - }, - { - Effect: "Allow", - Actions: []string{ - "iam:CreateServiceLinkedRole", - "iam:PutRolePolicy", - }, - Resources: "arn:aws:iam::*:role/aws-service-role/spot.amazonaws.com/AWSServiceRoleForEC2Spot", - Condition: map[string]map[string]string{ - "StringLike": { - "iam:AWSServiceName": "spot.amazonaws.com", - }, - }, - }, - }, - } - if passRoleARNs, ok := d.GetOk("pass_roles"); ok { - policy.Statements = append(policy.Statements, &awsIamPolicyStatement{ - Effect: "Allow", - Actions: "iam:PassRole", - Resources: passRoleARNs, - }) - } - policyJSON, err := json.MarshalIndent(policy, "", " ") - if err != nil { - return diag.FromErr(err) - } - d.SetId("cross-account") - // nolint - d.Set("json", string(policyJSON)) - return nil - }, - Schema: map[string]*schema.Schema{ - "pass_roles": { - Type: schema.TypeList, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Optional: true, - }, - "json": { - Type: schema.TypeString, - Computed: true, - ForceNew: true, - }, - }, - } -} - -// DataAwsAssumeRolePolicy ... -func DataAwsAssumeRolePolicy() *schema.Resource { - return &schema.Resource{ - ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - externalID := d.Get("external_id").(string) - policy := awsIamPolicy{ - Version: "2012-10-17", - Statements: []*awsIamPolicyStatement{ - { - Effect: "Allow", - Actions: "sts:AssumeRole", - Condition: map[string]map[string]string{ - "StringEquals": { - "sts:ExternalId": externalID, - }, - }, - Principal: map[string]string{ - "AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)), - }, - }, - }, - } - if v, ok := d.GetOk("for_log_delivery"); ok { - if v.(bool) { - // this is production UsageDelivery IAM role, that is considered a constant - logDeliveryARN := "arn:aws:iam::414351767826:role/SaasUsageDeliveryRole-prod-IAMRole-3PLHICCRR1TK" - policy.Statements[0].Principal["AWS"] = logDeliveryARN - } - } - policyJSON, err := json.MarshalIndent(policy, "", " ") - if err != nil { - return diag.FromErr(err) - } - d.SetId(externalID) - // nolint - d.Set("json", string(policyJSON)) - return nil - }, - Schema: map[string]*schema.Schema{ - "databricks_account_id": { - Type: schema.TypeString, - Default: "414351767826", - Optional: true, - }, - "for_log_delivery": { - Type: schema.TypeBool, - Description: "Grant AssumeRole to Databricks SaasUsageDeliveryRole instead of root account", - Optional: true, - Default: false, - }, - "external_id": { - Type: schema.TypeString, - Required: true, - }, - "json": { - Type: schema.TypeString, - Computed: true, - ForceNew: true, - }, - }, - } -} - -// DataAwsBucketPolicy ... -func DataAwsBucketPolicy() *schema.Resource { - return &schema.Resource{ - ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - bucket := d.Get("bucket").(string) - policy := awsIamPolicy{ - Version: "2012-10-17", - Statements: []*awsIamPolicyStatement{ - { - Effect: "Allow", - Actions: []string{ - "s3:GetObject", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:DeleteObject", - "s3:ListBucket", - "s3:GetBucketLocation", - }, - Resources: []string{ - fmt.Sprintf("arn:aws:s3:::%s/*", bucket), - fmt.Sprintf("arn:aws:s3:::%s", bucket), - }, - Principal: map[string]string{ - "AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)), - }, - }, - }, - } - if v, ok := d.GetOk("full_access_role"); ok { - policy.Statements[0].Principal["AWS"] = v.(string) - } - policyJSON, err := json.MarshalIndent(policy, "", " ") - if err != nil { - return diag.FromErr(err) - } - d.SetId(bucket) - // nolint - d.Set("json", string(policyJSON)) - return nil - }, - Schema: map[string]*schema.Schema{ - "databricks_account_id": { - Type: schema.TypeString, - Default: "414351767826", - Optional: true, - }, - "full_access_role": { - Type: schema.TypeString, - Optional: true, - }, - "bucket": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringMatch( - regexp.MustCompile(`^[0-9a-zA-Z_-]+$`), - "must contain only alphanumeric, underscore, and hyphen characters"), - }, - "json": { - Type: schema.TypeString, - Computed: true, - ForceNew: true, - }, - }, - } -} diff --git a/aws/data_aws_policies_test.go b/aws/data_aws_policies_test.go deleted file mode 100644 index abaa590ea2..0000000000 --- a/aws/data_aws_policies_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package aws - -import ( - "testing" - - "github.com/databrickslabs/terraform-provider-databricks/qa" - "github.com/stretchr/testify/assert" -) - -func TestDataAwsCrossAccountPolicy(t *testing.T) { - d, err := qa.ResourceFixture{ - Read: true, - Resource: DataAwsCrossAccountPolicy(), - NonWritable: true, - ID: ".", - }.Apply(t) - assert.NoError(t, err) - j := d.Get("json") - assert.Lenf(t, j, 2759, "Strange length for policy: %s", j) -} - -func TestDataAwsCrossAccountPolicy_WithPassRoles(t *testing.T) { - d, err := qa.ResourceFixture{ - Read: true, - Resource: DataAwsCrossAccountPolicy(), - NonWritable: true, - HCL: `pass_roles = ["a", "b", "c"]`, - ID: ".", - }.Apply(t) - assert.NoError(t, err) - j := d.Get("json") - assert.Lenf(t, j, 2895, "Strange length for policy: %s", j) -} - -func TestDataAwsAssumeRolePolicy(t *testing.T) { - d, err := qa.ResourceFixture{ - Read: true, - Resource: DataAwsAssumeRolePolicy(), - NonWritable: true, - ID: ".", - HCL: `external_id = "abc"`, - }.Apply(t) - assert.NoError(t, err) - j := d.Get("json") - assert.Lenf(t, j, 299, "Strange length for policy: %s", j) -} - -func TestDataAwsBucketPolicy(t *testing.T) { - d, err := qa.ResourceFixture{ - Read: true, - Resource: DataAwsBucketPolicy(), - NonWritable: true, - ID: ".", - HCL: ` - bucket = "abc" - `, - }.Apply(t) - assert.NoError(t, err) - j := d.Get("json") - assert.Lenf(t, j, 440, "Strange length for policy: %s", j) -} - -func TestDataAwsBucketPolicy_FullAccessRole(t *testing.T) { - d, err := qa.ResourceFixture{ - Read: true, - Resource: DataAwsBucketPolicy(), - NonWritable: true, - ID: ".", - HCL: ` - bucket = "abc" - full_access_role = "bcd" - `, - }.Apply(t) - assert.NoError(t, err) - j := d.Get("json") - assert.Lenf(t, j, 413, "Strange length for policy: %s", j) -} diff --git a/catalog/resource_metastore_data_access.go b/catalog/resource_metastore_data_access.go index 2eda41c40b..f093cd233b 100644 --- a/catalog/resource_metastore_data_access.go +++ b/catalog/resource_metastore_data_access.go @@ -56,7 +56,7 @@ func (a DataAccessConfigurationsAPI) Delete(metastoreID, dacID string) error { return a.client.Delete(a.context, path, nil) } -func ResourceDataAccessConfiguration() *schema.Resource { +func ResourceMetastoreDataAccess() *schema.Resource { s := common.StructToSchema(DataAccessConfiguration{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { m["metastore_id"] = &schema.Schema{ diff --git a/catalog/resource_metastore_data_access_test.go b/catalog/resource_metastore_data_access_test.go index 71cf50486b..69aa933503 100644 --- a/catalog/resource_metastore_data_access_test.go +++ b/catalog/resource_metastore_data_access_test.go @@ -7,7 +7,7 @@ import ( ) func TestDacCornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceDataAccessConfiguration(), + qa.ResourceCornerCases(t, ResourceMetastoreDataAccess(), qa.CornerCaseID("a|b")) } @@ -53,7 +53,7 @@ func TestCreateDac(t *testing.T) { }, }, Create: true, - Resource: ResourceDataAccessConfiguration(), + Resource: ResourceMetastoreDataAccess(), HCL: ` metastore_id = "abc" name = "bcd" @@ -107,7 +107,7 @@ func TestCreateDacWithAzMI(t *testing.T) { }, }, Create: true, - Resource: ResourceDataAccessConfiguration(), + Resource: ResourceMetastoreDataAccess(), HCL: ` metastore_id = "abc" name = "bcd" diff --git a/catalog/resource_storage_credentials.go b/catalog/resource_storage_credential.go similarity index 97% rename from catalog/resource_storage_credentials.go rename to catalog/resource_storage_credential.go index 50cb37c409..5089ac2671 100644 --- a/catalog/resource_storage_credentials.go +++ b/catalog/resource_storage_credential.go @@ -48,7 +48,8 @@ func ResourceStorageCredential() *schema.Resource { m["azure_managed_identity"].AtLeastOneOf = alof return m }) - update := updateFunctionFactory("/unity-catalog/storage-credentials", []string{"owner", "comment", "aws_iam_role", "azure_service_principal"}) + update := updateFunctionFactory("/unity-catalog/storage-credentials", []string{ + "owner", "comment", "aws_iam_role", "azure_service_principal"}) return common.Resource{ Schema: s, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { diff --git a/catalog/resource_storage_credentials_test.go b/catalog/resource_storage_credential_test.go similarity index 100% rename from catalog/resource_storage_credentials_test.go rename to catalog/resource_storage_credential_test.go diff --git a/catalog/resource_table.go b/catalog/resource_table.go index 563caeabaa..5048c681f8 100644 --- a/catalog/resource_table.go +++ b/catalog/resource_table.go @@ -80,7 +80,9 @@ func ResourceTable() *schema.Resource { func(m map[string]*schema.Schema) map[string]*schema.Schema { return m }) - update := updateFunctionFactory("/unity-catalog/tables", []string{"owner", "name", "data_source_format", "columns", "storage_location", "view_definition", "comment", "properties"}) + update := updateFunctionFactory("/unity-catalog/tables", []string{ + "owner", "name", "data_source_format", "columns", "storage_location", + "view_definition", "comment", "properties"}) return common.Resource{ Schema: tableSchema, Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { diff --git a/mlflow/acceptance/experiment_test.go b/mlflow/acceptance/mlflow_experiment_test.go similarity index 100% rename from mlflow/acceptance/experiment_test.go rename to mlflow/acceptance/mlflow_experiment_test.go diff --git a/mlflow/acceptance/model_test.go b/mlflow/acceptance/mlflow_model_test.go similarity index 100% rename from mlflow/acceptance/model_test.go rename to mlflow/acceptance/mlflow_model_test.go diff --git a/mlflow/resource_experiment.go b/mlflow/resource_mlflow_experiment.go similarity index 98% rename from mlflow/resource_experiment.go rename to mlflow/resource_mlflow_experiment.go index b6f0e54db5..adad5098a6 100644 --- a/mlflow/resource_experiment.go +++ b/mlflow/resource_mlflow_experiment.go @@ -67,7 +67,7 @@ func (a ExperimentsAPI) Delete(id string) error { }, nil) } -func ResourceMLFlowExperiment() *schema.Resource { +func ResourceMlflowExperiment() *schema.Resource { s := common.StructToSchema( Experiment{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/mlflow/resource_experiment_test.go b/mlflow/resource_mlflow_experiment_test.go similarity index 93% rename from mlflow/resource_experiment_test.go rename to mlflow/resource_mlflow_experiment_test.go index 5f971b1fac..ab481a8742 100644 --- a/mlflow/resource_experiment_test.go +++ b/mlflow/resource_mlflow_experiment_test.go @@ -32,7 +32,7 @@ func TestExperimentCreate(t *testing.T) { }, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Create: true, HCL: ` name = "xyz" @@ -57,7 +57,7 @@ func TestExperimentCreatePostError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Create: true, HCL: ` name = "xyz" @@ -87,7 +87,7 @@ func TestExperimentCreateGetError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Create: true, HCL: ` name = "xyz" @@ -110,7 +110,7 @@ func TestExperimentRead(t *testing.T) { }, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Read: true, ID: re.ExperimentId, }.Apply(t) @@ -133,7 +133,7 @@ func TestExperimentReadGetError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Read: true, ID: re.ExperimentId, }.Apply(t) @@ -161,7 +161,7 @@ func TestExperimentUpdate(t *testing.T) { Response: resPost, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Update: true, ID: resPost.ExperimentId, HCL: ` @@ -188,7 +188,7 @@ func TestExperimentUpdatePostError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Update: true, ID: resPost.ExperimentId, HCL: ` @@ -211,7 +211,7 @@ func TestExperimentDelete(t *testing.T) { ExpectedRequest: r, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Delete: true, ID: r["experiment_id"], HCL: ` @@ -236,7 +236,7 @@ func TestExperimentDeleteError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowExperiment(), + Resource: ResourceMlflowExperiment(), Delete: true, ID: r["experiment_id"], HCL: ` diff --git a/mlflow/resource_model.go b/mlflow/resource_mlflow_model.go similarity index 98% rename from mlflow/resource_model.go rename to mlflow/resource_mlflow_model.go index dbef61cf88..551e631b6c 100644 --- a/mlflow/resource_model.go +++ b/mlflow/resource_mlflow_model.go @@ -77,7 +77,7 @@ func (a ModelsAPI) Delete(name string) error { }) } -func ResourceMLFlowModel() *schema.Resource { +func ResourceMlflowModel() *schema.Resource { s := common.StructToSchema( Model{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/mlflow/resource_model_test.go b/mlflow/resource_mlflow_model_test.go similarity index 94% rename from mlflow/resource_model_test.go rename to mlflow/resource_mlflow_model_test.go index 03f4e8ec11..9b00efc17b 100644 --- a/mlflow/resource_model_test.go +++ b/mlflow/resource_mlflow_model_test.go @@ -34,7 +34,7 @@ func TestModelCreate(t *testing.T) { }, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Create: true, HCL: ` name = "xyz" @@ -66,7 +66,7 @@ func TestModelCreatePostError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Create: true, HCL: ` name = "xyz" @@ -95,7 +95,7 @@ func TestModelRead(t *testing.T) { }, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Read: true, ID: "xyz", }.Apply(t) @@ -116,7 +116,7 @@ func TestModelReadGetError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Read: true, ID: "xyz", }.Apply(t) @@ -144,7 +144,7 @@ func TestModelUpdate(t *testing.T) { }, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Update: true, RequiresNew: true, ID: "xyz", @@ -176,7 +176,7 @@ func TestModelUpdatePatchError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Update: true, RequiresNew: true, ID: "xyz", @@ -203,7 +203,7 @@ func TestModelDelete(t *testing.T) { }, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Delete: true, ID: "xyz", HCL: ` @@ -227,7 +227,7 @@ func TestModelDeleteError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowModel(), + Resource: ResourceMlflowModel(), Delete: true, ID: "xyz", HCL: ` diff --git a/mlflow/resource_webhook.go b/mlflow/resource_mlflow_webhook.go similarity index 99% rename from mlflow/resource_webhook.go rename to mlflow/resource_mlflow_webhook.go index 505649a12e..3daa401187 100644 --- a/mlflow/resource_webhook.go +++ b/mlflow/resource_mlflow_webhook.go @@ -84,7 +84,7 @@ func (a WebhooksAPI) Delete(ID string) error { }) } -func ResourceMLFlowWebhook() *schema.Resource { +func ResourceMlflowWebhook() *schema.Resource { s := common.StructToSchema( Webhook{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/mlflow/resource_webhook_test.go b/mlflow/resource_mlflow_webhook_test.go similarity index 94% rename from mlflow/resource_webhook_test.go rename to mlflow/resource_mlflow_webhook_test.go index dbf507b2e9..5994309fba 100644 --- a/mlflow/resource_webhook_test.go +++ b/mlflow/resource_mlflow_webhook_test.go @@ -60,7 +60,7 @@ func TestWebookCreateJobSpec(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Create: true, HCL: testWhHCL, }.ApplyAndExpectData(t, map[string]interface{}{"id": testWhID, "status": "ACTIVE"}) @@ -113,7 +113,7 @@ func TestWebookCreateUrlSpec(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Create: true, HCL: ` events = ["TRANSITION_REQUEST_CREATED"] @@ -140,7 +140,7 @@ func TestWebookCreateError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Create: true, HCL: testWhHCL, }.ExpectError(t, "error creating a webhook: ") @@ -148,7 +148,7 @@ func TestWebookCreateError(t *testing.T) { func TestWebookCreateErrorNoUrlOrJobSpec(t *testing.T) { qa.ResourceFixture{ - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Create: true, HCL: ` events = ["TRANSITION_REQUEST_CREATED"] @@ -169,7 +169,7 @@ func TestWebookRead(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Read: true, ID: testWhID, }.ApplyAndExpectData(t, map[string]interface{}{"id": testWhID}) @@ -186,7 +186,7 @@ func TestWebookReadError(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Read: true, ID: "123456", }.ExpectError(t, "Webhook with ID 123456 isn't found") @@ -204,7 +204,7 @@ func TestWebookReadErrorBadResponse(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Read: true, ID: "123456", }.ExpectError(t, "error reading list of webhooks: ") @@ -229,7 +229,7 @@ func TestWebookUpdate(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Update: true, RequiresNew: false, ID: testWhID, @@ -258,7 +258,7 @@ func TestWebookDelete(t *testing.T) { }, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Delete: true, ID: testWhID, HCL: testWhHCL, @@ -277,7 +277,7 @@ func TestWebookDeleteError(t *testing.T) { Status: 400, }, }, - Resource: ResourceMLFlowWebhook(), + Resource: ResourceMlflowWebhook(), Delete: true, ID: testWhID, HCL: testWhHCL, diff --git a/mws/acceptance/credentials_test.go b/mws/acceptance/mws_credentials_test.go similarity index 100% rename from mws/acceptance/credentials_test.go rename to mws/acceptance/mws_credentials_test.go diff --git a/mws/acceptance/cmk_test.go b/mws/acceptance/mws_customer_managed_keys_test.go similarity index 100% rename from mws/acceptance/cmk_test.go rename to mws/acceptance/mws_customer_managed_keys_test.go diff --git a/mws/acceptance/log_delivery_test.go b/mws/acceptance/mws_log_delivery_test.go similarity index 100% rename from mws/acceptance/log_delivery_test.go rename to mws/acceptance/mws_log_delivery_test.go diff --git a/mws/acceptance/network_test.go b/mws/acceptance/mws_networks_test.go similarity index 100% rename from mws/acceptance/network_test.go rename to mws/acceptance/mws_networks_test.go diff --git a/mws/acceptance/private_access_settings_test.go b/mws/acceptance/mws_private_access_settings_test.go similarity index 100% rename from mws/acceptance/private_access_settings_test.go rename to mws/acceptance/mws_private_access_settings_test.go diff --git a/mws/acceptance/storage_test.go b/mws/acceptance/mws_storage_configurations_test.go similarity index 100% rename from mws/acceptance/storage_test.go rename to mws/acceptance/mws_storage_configurations_test.go diff --git a/mws/acceptance/vpc_endpoint_test.go b/mws/acceptance/mws_vpc_endpoint_test.go similarity index 100% rename from mws/acceptance/vpc_endpoint_test.go rename to mws/acceptance/mws_vpc_endpoint_test.go diff --git a/mws/acceptance/workspace_test.go b/mws/acceptance/mws_workspaces_test.go similarity index 100% rename from mws/acceptance/workspace_test.go rename to mws/acceptance/mws_workspaces_test.go diff --git a/mws/resource_credentials.go b/mws/resource_mws_credentials.go similarity index 98% rename from mws/resource_credentials.go rename to mws/resource_mws_credentials.go index 72e573b6d5..e98e783882 100644 --- a/mws/resource_credentials.go +++ b/mws/resource_mws_credentials.go @@ -59,8 +59,7 @@ func (a CredentialsAPI) List(mwsAcctID string) ([]Credentials, error) { return mwsCredsList, err } -// ResourceCredentials ... -func ResourceCredentials() *schema.Resource { +func ResourceMwsCredentials() *schema.Resource { p := common.NewPairSeparatedID("account_id", "credentials_id", "/") return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { diff --git a/mws/resource_credentials_test.go b/mws/resource_mws_credentials_test.go similarity index 95% rename from mws/resource_credentials_test.go rename to mws/resource_mws_credentials_test.go index ea8f57a043..30994e2691 100644 --- a/mws/resource_credentials_test.go +++ b/mws/resource_mws_credentials_test.go @@ -67,7 +67,7 @@ func TestResourceCredentialsCreate(t *testing.T) { }, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), State: map[string]interface{}{ "account_id": "abc", "credentials_name": "Cross-account ARN", @@ -92,7 +92,7 @@ func TestResourceCredentialsCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), State: map[string]interface{}{ "account_id": "abc", "credentials_name": "Cross-account ARN", @@ -121,7 +121,7 @@ func TestResourceCredentialsRead(t *testing.T) { }, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), Read: true, ID: "abc/cid", }.Apply(t) @@ -147,7 +147,7 @@ func TestResourceCredentialsRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), Read: true, Removed: true, ID: "abc/cid", @@ -167,7 +167,7 @@ func TestResourceCredentialsRead_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), Read: true, ID: "abc/cid", }.Apply(t) @@ -183,7 +183,7 @@ func TestResourceCredentialsDelete(t *testing.T) { Resource: "/api/2.0/accounts/abc/credentials/cid", }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), Delete: true, ID: "abc/cid", }.Apply(t) @@ -204,7 +204,7 @@ func TestResourceCredentialsDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceCredentials(), + Resource: ResourceMwsCredentials(), Delete: true, ID: "abc/cid", }.Apply(t) diff --git a/mws/resource_customer_managed_key.go b/mws/resource_mws_customer_managed_keys.go similarity index 98% rename from mws/resource_customer_managed_key.go rename to mws/resource_mws_customer_managed_keys.go index d958e73b81..be961c2963 100644 --- a/mws/resource_customer_managed_key.go +++ b/mws/resource_mws_customer_managed_keys.go @@ -64,8 +64,7 @@ func (a CustomerManagedKeysAPI) List(accountID string) (kl []CustomerManagedKey, return } -// ResourceCustomerManagedKey ... -func ResourceCustomerManagedKey() *schema.Resource { +func ResourceMwsCustomerManagedKeys() *schema.Resource { s := common.StructToSchema(CustomerManagedKey{}, nil) p := common.NewPairSeparatedID("account_id", "customer_managed_key_id", "/") return common.Resource{ diff --git a/mws/resource_customer_managed_key_test.go b/mws/resource_mws_customer_managed_keys_test.go similarity index 96% rename from mws/resource_customer_managed_key_test.go rename to mws/resource_mws_customer_managed_keys_test.go index 6f0f469a59..ef17081e86 100644 --- a/mws/resource_customer_managed_key_test.go +++ b/mws/resource_mws_customer_managed_keys_test.go @@ -79,7 +79,7 @@ func TestResourceCustomerManagedKeyCreate(t *testing.T) { }, }, }, - Resource: ResourceCustomerManagedKey(), + Resource: ResourceMwsCustomerManagedKeys(), HCL: ` account_id = "abc" @@ -133,7 +133,7 @@ func TestResourceCustomerManagedKeyCreate_Error(t *testing.T) { }, }, }, - Resource: ResourceCustomerManagedKey(), + Resource: ResourceMwsCustomerManagedKeys(), HCL: ` account_id = "abc" @@ -167,7 +167,7 @@ func TestResourceCustomerManagedKeyRead(t *testing.T) { }, }, }, - Resource: ResourceCustomerManagedKey(), + Resource: ResourceMwsCustomerManagedKeys(), HCL: ` account_id = "abc" @@ -202,7 +202,7 @@ func TestResourceCustomerManagedKeyRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceCustomerManagedKey(), + Resource: ResourceMwsCustomerManagedKeys(), HCL: ` account_id = "abc" @@ -227,7 +227,7 @@ func TestResourceCustomerManagedKeyDelete(t *testing.T) { Status: 200, }, }, - Resource: ResourceCustomerManagedKey(), + Resource: ResourceMwsCustomerManagedKeys(), HCL: ` account_id = "abc" diff --git a/mws/resource_log_delivery.go b/mws/resource_mws_log_delivery.go similarity index 98% rename from mws/resource_log_delivery.go rename to mws/resource_mws_log_delivery.go index 24b8845be8..71d1286329 100644 --- a/mws/resource_log_delivery.go +++ b/mws/resource_mws_log_delivery.go @@ -66,8 +66,7 @@ func (a LogDeliveryAPI) Disable(accountID, configID string) error { }) } -// ResourceLogDelivery .. -func ResourceLogDelivery() *schema.Resource { +func ResourceMwsLogDelivery() *schema.Resource { p := common.NewPairID("account_id", "config_id") s := common.StructToSchema(LogDeliveryConfiguration{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/mws/resource_log_delivery_test.go b/mws/resource_mws_log_delivery_test.go similarity index 96% rename from mws/resource_log_delivery_test.go rename to mws/resource_mws_log_delivery_test.go index 3a36763832..2b16f4b867 100644 --- a/mws/resource_log_delivery_test.go +++ b/mws/resource_mws_log_delivery_test.go @@ -99,7 +99,7 @@ func TestResourceLogDeliveryCreate(t *testing.T) { }, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), HCL: ` account_id = "abc" credentials_id = "bcd" @@ -130,7 +130,7 @@ func TestResourceLogDeliveryCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), HCL: ` account_id = "abc" credentials_id = "bcd" @@ -170,7 +170,7 @@ func TestResourceLogDeliveryRead(t *testing.T) { }, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), Read: true, New: true, ID: "abc|nid", @@ -194,7 +194,7 @@ func TestResourceLogDeliveryRead_NotFound(t *testing.T) { }, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), Read: true, Removed: true, ID: "abc|nid", @@ -214,7 +214,7 @@ func TestResourceLogDeliveryRead_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), Read: true, ID: "abc|nid", }.Apply(t) @@ -233,7 +233,7 @@ func TestResourceLogDeliveryDelete(t *testing.T) { }, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), Delete: true, ID: "abc|nid", }.Apply(t) @@ -254,7 +254,7 @@ func TestResourceLogDeliveryDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceLogDelivery(), + Resource: ResourceMwsLogDelivery(), Delete: true, ID: "abc|nid", }.Apply(t) diff --git a/mws/resource_network.go b/mws/resource_mws_networks.go similarity index 98% rename from mws/resource_network.go rename to mws/resource_mws_networks.go index f1095a5653..7ade69ac93 100644 --- a/mws/resource_network.go +++ b/mws/resource_mws_networks.go @@ -67,8 +67,7 @@ func (a NetworksAPI) List(mwsAcctID string) ([]Network, error) { return mwsNetworkList, err } -// ResourceNetwork ... -func ResourceNetwork() *schema.Resource { +func ResourceMwsNetworks() *schema.Resource { s := common.StructToSchema(Network{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { s["account_id"].Sensitive = true // nolint diff --git a/mws/resource_network_test.go b/mws/resource_mws_networks_test.go similarity index 96% rename from mws/resource_network_test.go rename to mws/resource_mws_networks_test.go index d9be3a7cbd..e98dbf74d6 100644 --- a/mws/resource_network_test.go +++ b/mws/resource_mws_networks_test.go @@ -72,7 +72,7 @@ func TestResourceNetworkCreate(t *testing.T) { }, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), HCL: ` account_id = "abc" network_name = "Open Workers" @@ -99,7 +99,7 @@ func TestResourceNetworkCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), State: map[string]interface{}{ "account_id": "abc", "network_name": "Open Workers", @@ -129,7 +129,7 @@ func TestResourceNetworkRead(t *testing.T) { }, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), Read: true, New: true, ID: "abc/nid", @@ -156,7 +156,7 @@ func TestResourceNetworkRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), Read: true, Removed: true, ID: "abc/nid", @@ -176,7 +176,7 @@ func TestResourceNetworkRead_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), Read: true, ID: "abc/nid", }.Apply(t) @@ -212,7 +212,7 @@ func TestResourceNetworkDelete(t *testing.T) { Status: 404, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), Delete: true, ID: "abc/nid", }.Apply(t) @@ -233,7 +233,7 @@ func TestResourceNetworkDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceNetwork(), + Resource: ResourceMwsNetworks(), Delete: true, ID: "abc/nid", }.Apply(t) diff --git a/mws/resource_mws_pas.go b/mws/resource_mws_private_access_settings.go similarity index 97% rename from mws/resource_mws_pas.go rename to mws/resource_mws_private_access_settings.go index ed05eb7916..8ec5ca1531 100644 --- a/mws/resource_mws_pas.go +++ b/mws/resource_mws_private_access_settings.go @@ -57,8 +57,7 @@ func (a PrivateAccessSettingsAPI) List(mwsAcctID string) ([]PrivateAccessSetting return pasList, err } -// ResourcePrivateAccessSettings ... -func ResourcePrivateAccessSettings() *schema.Resource { +func ResourceMwsPrivateAccessSettings() *schema.Resource { s := common.StructToSchema(PrivateAccessSettings{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { // nolint s["private_access_settings_name"].ValidateFunc = validation.StringLenBetween(4, 256) diff --git a/mws/resource_mws_pas_test.go b/mws/resource_mws_private_access_settings_test.go similarity index 94% rename from mws/resource_mws_pas_test.go rename to mws/resource_mws_private_access_settings_test.go index 36b3427d2c..7a28daec5a 100644 --- a/mws/resource_mws_pas_test.go +++ b/mws/resource_mws_private_access_settings_test.go @@ -70,7 +70,7 @@ func TestResourcePASCreate(t *testing.T) { }, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), HCL: ` account_id = "abc" private_access_settings_name = "pas_name" @@ -95,7 +95,7 @@ func TestResourcePASCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), State: map[string]interface{}{ "account_id": "abc", "private_access_settings_name": "pas_name", @@ -120,7 +120,7 @@ func TestResourcePASRead(t *testing.T) { }, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Read: true, New: true, ID: "abc/pas_id", @@ -146,7 +146,7 @@ func TestResourcePAStRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Read: true, Removed: true, ID: "abc/pas_id", @@ -166,7 +166,7 @@ func TestResourcePAS_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Read: true, ID: "abc/pas_id", }.Apply(t) @@ -202,7 +202,7 @@ func TestResourcePAS_Update(t *testing.T) { }, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Update: true, ID: "abc/pas_id", HCL: ` @@ -243,7 +243,7 @@ func TestResourcePASDelete(t *testing.T) { Status: 404, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Delete: true, ID: "abc/pas_id", }.Apply(t) @@ -264,7 +264,7 @@ func TestResourcePASDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourcePrivateAccessSettings(), + Resource: ResourceMwsPrivateAccessSettings(), Delete: true, ID: "abc/pas_id", }.Apply(t) diff --git a/mws/resource_storage.go b/mws/resource_mws_storage_configurations.go similarity index 98% rename from mws/resource_storage.go rename to mws/resource_mws_storage_configurations.go index f771296c88..a98c1d9aea 100644 --- a/mws/resource_storage.go +++ b/mws/resource_mws_storage_configurations.go @@ -55,8 +55,7 @@ func (a StorageConfigurationsAPI) List(mwsAcctID string) ([]StorageConfiguration return mwsStorageConfigurationsList, err } -// ResourceStorageConfiguration ... -func ResourceStorageConfiguration() *schema.Resource { +func ResourceMwsStorageConfigurations() *schema.Resource { p := common.NewPairSeparatedID("account_id", "storage_configuration_id", "/") return common.Resource{ Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error { diff --git a/mws/resource_storage_test.go b/mws/resource_mws_storage_configurations_test.go similarity index 94% rename from mws/resource_storage_test.go rename to mws/resource_mws_storage_configurations_test.go index 6ecead512a..3bbbf64504 100644 --- a/mws/resource_storage_test.go +++ b/mws/resource_mws_storage_configurations_test.go @@ -61,7 +61,7 @@ func TestResourceStorageConfigurationCreate(t *testing.T) { }, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), State: map[string]interface{}{ "account_id": "abc", "bucket_name": "bucket", @@ -86,7 +86,7 @@ func TestResourceStorageConfigurationCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), State: map[string]interface{}{ "account_id": "abc", "bucket_name": "bucket", @@ -113,7 +113,7 @@ func TestResourceStorageConfigurationRead(t *testing.T) { }, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), Read: true, ID: "abc/scid", }.Apply(t) @@ -138,7 +138,7 @@ func TestResourceStorageConfigurationRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), Read: true, Removed: true, ID: "abc/scid", @@ -158,7 +158,7 @@ func TestResourceStorageConfigurationRead_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), Read: true, ID: "abc/scid", }.Apply(t) @@ -174,7 +174,7 @@ func TestResourceStorageConfigurationDelete(t *testing.T) { Resource: "/api/2.0/accounts/abc/storage-configurations/scid", }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), Delete: true, ID: "abc/scid", }.Apply(t) @@ -195,7 +195,7 @@ func TestResourceStorageConfigurationDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceStorageConfiguration(), + Resource: ResourceMwsStorageConfigurations(), Delete: true, ID: "abc/scid", }.Apply(t) diff --git a/mws/resource_mws_vpc_endpoint.go b/mws/resource_mws_vpc_endpoint.go index afeaad5d9e..9877268201 100644 --- a/mws/resource_mws_vpc_endpoint.go +++ b/mws/resource_mws_vpc_endpoint.go @@ -72,8 +72,7 @@ func (a VPCEndpointAPI) List(mwsAcctID string) ([]VPCEndpoint, error) { return mwsVPCEndpointList, err } -// ResourceVPCEndpoint ... -func ResourceVPCEndpoint() *schema.Resource { +func ResourceMwsVpcEndpoint() *schema.Resource { s := common.StructToSchema(VPCEndpoint{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { // nolint s["vpc_endpoint_name"].ValidateFunc = validation.StringLenBetween(4, 256) diff --git a/mws/resource_mws_vpc_endpoint_test.go b/mws/resource_mws_vpc_endpoint_test.go index d6abcc96a1..42b11df6b2 100644 --- a/mws/resource_mws_vpc_endpoint_test.go +++ b/mws/resource_mws_vpc_endpoint_test.go @@ -75,7 +75,7 @@ func TestResourceVPCEndpointCreate(t *testing.T) { }, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), HCL: ` account_id = "abc" vpc_endpoint_name = "ve_name" @@ -101,7 +101,7 @@ func TestResourceVPCEndpointCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), State: map[string]interface{}{ "account_id": "abc", "vpc_endpoint_name": "ve_name", @@ -128,7 +128,7 @@ func TestResourceVPCEndpointRead(t *testing.T) { }, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), Read: true, New: true, ID: "abc/veid", @@ -154,7 +154,7 @@ func TestResourceVPCEndpointRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), Read: true, Removed: true, ID: "abc/veid", @@ -174,7 +174,7 @@ func TestResourceVPCEndpoint_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), Read: true, ID: "abc/veid", }.Apply(t) @@ -209,7 +209,7 @@ func TestResourceVPCEndpointDelete(t *testing.T) { Status: 404, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), Delete: true, ID: "abc/veid", }.Apply(t) @@ -230,7 +230,7 @@ func TestResourceVPCEndpointDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceVPCEndpoint(), + Resource: ResourceMwsVpcEndpoint(), Delete: true, ID: "abc/veid", }.Apply(t) diff --git a/mws/resource_workspace.go b/mws/resource_mws_workspaces.go similarity index 99% rename from mws/resource_workspace.go rename to mws/resource_mws_workspaces.go index baacaee879..dde757f93f 100644 --- a/mws/resource_workspace.go +++ b/mws/resource_mws_workspaces.go @@ -416,8 +416,8 @@ func UpdateTokenIfNeeded(workspacesAPI WorkspacesAPI, return nil } -// ResourceWorkspace manages E2 workspaces -func ResourceWorkspace() *schema.Resource { +// ResourceMwsWorkspaces manages E2 workspaces +func ResourceMwsWorkspaces() *schema.Resource { workspaceSchema := common.StructToSchema(Workspace{}, func(s map[string]*schema.Schema) map[string]*schema.Schema { for name, fieldSchema := range s { diff --git a/mws/resource_workspace_test.go b/mws/resource_mws_workspaces_test.go similarity index 98% rename from mws/resource_workspace_test.go rename to mws/resource_mws_workspaces_test.go index ed483efae5..c7f3757988 100644 --- a/mws/resource_workspace_test.go +++ b/mws/resource_mws_workspaces_test.go @@ -94,7 +94,7 @@ func TestResourceWorkspaceCreate(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), State: map[string]interface{}{ "account_id": "abc", "aws_region": "us-east-1", @@ -162,7 +162,7 @@ func TestResourceWorkspaceCreateGcp(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), HCL: ` account_id = "abc" workspace_name = "labdata" @@ -234,7 +234,7 @@ func TestResourceWorkspaceCreateWithIsNoPublicIPEnabledFalse(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), State: map[string]interface{}{ "account_id": "abc", "aws_region": "us-east-1", @@ -294,7 +294,7 @@ func TestResourceWorkspaceCreateLegacyConfig(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), State: map[string]interface{}{ "account_id": "abc", "aws_region": "us-east-1", @@ -334,7 +334,7 @@ func TestResourceWorkspaceCreate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), State: map[string]interface{}{ "account_id": "abc", "aws_region": "us-east-1", @@ -375,7 +375,7 @@ func TestResourceWorkspaceRead(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Read: true, New: true, ID: "abc/1234", @@ -440,7 +440,7 @@ func TestResourceWorkspaceRead_Issue382(t *testing.T) { "network_id": "fgh", "storage_configuration_id": "ghi", }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Read: true, New: true, ID: "abc/1234", @@ -464,7 +464,7 @@ func TestResourceWorkspaceRead_NotFound(t *testing.T) { Status: 404, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Read: true, Removed: true, ID: "abc/1234", @@ -484,7 +484,7 @@ func TestResourceWorkspaceRead_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Read: true, ID: "abc/1234", }.Apply(t) @@ -523,7 +523,7 @@ func TestResourceWorkspaceUpdate(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), InstanceState: map[string]string{ "account_id": "abc", "aws_region": "us-east-1", @@ -559,7 +559,7 @@ func TestResourceWorkspaceUpdate(t *testing.T) { func TestResourceWorkspaceUpdate_NotAllowed(t *testing.T) { qa.ResourceFixture{ - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), InstanceState: map[string]string{ "account_id": "abc", "aws_region": "us-east-1", @@ -622,7 +622,7 @@ func TestResourceWorkspaceUpdateLegacyConfig(t *testing.T) { }, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), InstanceState: map[string]string{ "account_id": "abc", "aws_region": "us-east-1", @@ -666,7 +666,7 @@ func TestResourceWorkspaceUpdate_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), State: map[string]interface{}{ "account_id": "abc", "aws_region": "us-east-1", @@ -711,7 +711,7 @@ func TestResourceWorkspaceDelete(t *testing.T) { Status: 404, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Delete: true, ID: "abc/1234", }.Apply(t) @@ -732,7 +732,7 @@ func TestResourceWorkspaceDelete_Error(t *testing.T) { Status: 400, }, }, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), Delete: true, ID: "abc/1234", }.Apply(t) @@ -984,7 +984,7 @@ func updateWorkspaceTokenFixture(t *testing.T, fixtures []qa.HTTPFixture, state state["is_no_public_ip_enabled"] = "false" qa.ResourceFixture{ Fixtures: accountsAPI, - Resource: ResourceWorkspace(), + Resource: ResourceMwsWorkspaces(), InstanceState: state, Update: true, ID: "a", @@ -1090,7 +1090,7 @@ func TestEnsureTokenExists(t *testing.T) { }, }, }, func(ctx context.Context, client *common.DatabricksClient) { - r := ResourceWorkspace() + r := ResourceMwsWorkspaces() d := r.TestResourceData() d.Set("workspace_url", client.Host) d.Set("token", []interface{}{ @@ -1120,7 +1120,7 @@ func TestEnsureTokenExists_NoRecreate(t *testing.T) { }, }, }, func(ctx context.Context, client *common.DatabricksClient) { - r := ResourceWorkspace() + r := ResourceMwsWorkspaces() d := r.TestResourceData() d.Set("workspace_url", client.Host) d.Set("token", []interface{}{ @@ -1139,7 +1139,7 @@ func TestEnsureTokenExists_NoRecreate(t *testing.T) { func TestWorkspaceTokenWrongAuthCornerCase(t *testing.T) { defer common.CleanupEnvironment()() client := &common.DatabricksClient{} - r := ResourceWorkspace() + r := ResourceMwsWorkspaces() d := r.TestResourceData() d.Set("workspace_url", client.Host) d.Set("token", []interface{}{ @@ -1175,7 +1175,7 @@ func TestWorkspaceTokenHttpCornerCases(t *testing.T) { }, }, func(ctx context.Context, client *common.DatabricksClient) { wsApi := NewWorkspacesAPI(context.Background(), client) - r := ResourceWorkspace() + r := ResourceMwsWorkspaces() d := r.TestResourceData() d.Set("workspace_url", client.Host) d.Set("token", []interface{}{ diff --git a/provider/coverage_test.go b/provider/coverage_test.go new file mode 100644 index 0000000000..52030cb640 --- /dev/null +++ b/provider/coverage_test.go @@ -0,0 +1,363 @@ +package provider + +import ( + "fmt" + "io" + "io/fs" + "log" + "os" + "path" + "regexp" + "sort" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/stretchr/testify/assert" +) + +type CoverageReport struct { + Resources []ResourceCoverage +} + +type ResourceCoverage struct { + Name string + Data bool + Docs bool + Readme bool + AccTest bool + AccFile bool + ResFile bool + ResTest bool + Fields []FieldCoverage +} + +func (rc ResourceCoverage) Prefixless() string { + return strings.TrimPrefix(rc.Name, "databricks_") +} + +func (rc ResourceCoverage) DocLocation() string { + if rc.Data { + return path.Join("../docs/data-sources", rc.Prefixless()+".md") + } + return path.Join("../docs/resources", rc.Prefixless()+".md") +} + +func (rc ResourceCoverage) ResourceFilename() string { + if rc.Data { + return fmt.Sprintf("data_%s.go", rc.Prefixless()) + } + return fmt.Sprintf("resource_%s.go", rc.Prefixless()) +} + +func (rc ResourceCoverage) ResourceFn() string { + return strings.ReplaceAll( + strings.Title( + strings.ReplaceAll( + rc.Prefixless(), "_", " ")), " ", "") +} + +func (rc ResourceCoverage) TestFilename() string { + if rc.Data { + return fmt.Sprintf("data_%s_test.go", rc.Prefixless()) + } + return fmt.Sprintf("resource_%s_test.go", rc.Prefixless()) +} + +func (rc ResourceCoverage) AccFilename() string { + return fmt.Sprintf("acceptance/%s_test.go", rc.Prefixless()) +} + +func (rc ResourceCoverage) coverage(cb func(FieldCoverage) bool, green, yellow int) string { + var x float32 + for _, v := range rc.Fields { + if cb(v) { + x++ + } + } + coverage := int(100 * x / float32(len(rc.Fields))) + coverageStr := fmt.Sprintf("(%d%%)", coverage) + if coverage > green { + return fmt.Sprintf("✅ %6s", coverageStr) + } + if coverage > yellow { + return fmt.Sprintf("👎 %6s", coverageStr) + } + return fmt.Sprintf("❌ %6s", coverageStr) +} + +func (rc ResourceCoverage) DocCoverage() string { + return rc.coverage(func(fc FieldCoverage) bool { + return fc.Docs + }, 80, 50) +} + +func (rc ResourceCoverage) AccCoverage() string { + return rc.coverage(func(fc FieldCoverage) bool { + return fc.AccTest + }, 40, 20) +} + +func (rc ResourceCoverage) UnitCoverage() string { + return rc.coverage(func(fc FieldCoverage) bool { + return fc.UnitTest + }, 40, 20) +} + +type FieldCoverage struct { + Name string + Docs bool + AccTest bool + UnitTest bool +} + +func (fc FieldCoverage) EverythingCovered() bool { + return fc.Docs && fc.AccTest && fc.UnitTest +} + +func newResourceCoverage(files FileSet, name string, s map[string]*schema.Schema, data bool) ResourceCoverage { + r := ResourceCoverage{ + Name: name, + Data: data, + Readme: files.Exists("../README.md", name), + AccTest: files.Exists(`acceptance/.*_test.go`, fmt.Sprintf(`"%s"`, name)), + } + r.Docs = fileExists(r.DocLocation()) + // acceptance test file with a correct name + r.AccFile = files.Exists(r.AccFilename(), r.Name) + // resource file with a correct name + r.ResFile = files.Exists(r.ResourceFilename(), r.ResourceFn()) + // resource unit test file with a correct name + r.ResTest = files.Exists(r.TestFilename(), r.ResourceFn()) + r.Fields = fields(r, s, files) + sort.Slice(r.Fields, func(i, j int) bool { + return r.Fields[i].Name < r.Fields[j].Name + }) + return r +} + +func TestCoverageReport(t *testing.T) { + if _, ok := os.LookupEnv("VSCODE_PID"); !ok { + t.Skip("Cleaning up tests only from IDE") + } + files, err := recursiveChildren("..") + assert.NoError(t, err) + + p := DatabricksProvider() + var cr CoverageReport + var longestResourceName, longestFieldName int + + for k, v := range p.ResourcesMap { + if len(k) > longestResourceName { + longestResourceName = len(k) + } + r := newResourceCoverage(files, k, v.Schema, false) + cr.Resources = append(cr.Resources, r) + } + for k, v := range p.DataSourcesMap { + if len(k) > longestResourceName { + longestResourceName = len(k) + } + r := newResourceCoverage(files, k, v.Schema, true) + cr.Resources = append(cr.Resources, r) + } + sort.Slice(cr.Resources, func(i, j int) bool { + return cr.Resources[i].Name < cr.Resources[j].Name + }) + report, err := os.OpenFile("completeness.md", os.O_CREATE|os.O_WRONLY, 0755) + assert.NoError(t, err) + defer report.Close() + + report.WriteString("| Resource | Readme | Docs | Acceptance Test | Acceptance File | Resource File | Unit test |\n") + report.WriteString("| --- | --- | --- | --- | --- | --- | --- |\n") + resSummaryFormat := "| %" + fmt.Sprint(longestResourceName) + "s | %s | %s | %s | %s | %s | %s |\n" + for _, r := range cr.Resources { + for _, field := range r.Fields { + if len(field.Name) > longestFieldName { + longestFieldName = len(field.Name) + } + } + name := r.Name + if r.Data { + name = "* " + name + } + report.WriteString(fmt.Sprintf(resSummaryFormat, name, + checkbox(r.Readme), + r.DocCoverage(), + r.AccCoverage(), + checkbox(r.AccFile), + checkbox(r.ResFile), + r.UnitCoverage(), + )) + } + report.WriteString("\n\n| Resource | Field | Docs | Acceptance Test | Unit Test |\n") + report.WriteString("| --- | --- | --- | --- | --- |\n") + fieldSummaryFormat := "| %" + fmt.Sprint(longestResourceName) + "s | %" + + fmt.Sprint(longestFieldName) + "s | %s | %s | %s |\n" + for _, r := range cr.Resources { + for _, field := range r.Fields { + if field.EverythingCovered() { + continue + } + report.WriteString(fmt.Sprintf(fieldSummaryFormat, + r.Name, + field.Name, + checkbox(field.Docs), + checkbox(field.AccTest), + checkbox(field.UnitTest), + )) + } + } +} + +func fields(r ResourceCoverage, s map[string]*schema.Schema, files FileSet) (fields []FieldCoverage) { + type pathWrapper struct { + r *schema.Resource + path []string + } + queue := []pathWrapper{ + { + r: &schema.Resource{Schema: s}, + }, + } + doc := File{Absolute: r.DocLocation()} + + noisyDuplicates := map[string]bool{ + "new_cluster": true, + "task": true, + } + for { + head := queue[0] + queue = queue[1:] + for field, v := range head.r.Schema { + if noisyDuplicates[field] { + continue + } + path := append(head.path, field) + if nested, ok := v.Elem.(*schema.Resource); ok { + queue = append(queue, pathWrapper{ + r: nested, + path: path, + }) + } + fc := FieldCoverage{ + Name: strings.Join(path, "."), + } + if v.Computed { + fc.Name += " (computed)" + } + if r.Docs { + fc.Docs = doc.MustMatch(field) + } + if r.AccTest { + fc.AccTest = files.Exists(`acceptance/.*_test.go`, field) + } + if r.ResTest { + fc.UnitTest = files.Exists(r.TestFilename(), field) + } + fields = append(fields, fc) + } + if len(queue) == 0 { + break + } + } + return fields +} + +func checkbox(b bool) string { + if b { + return "✅" + } + return "❌" +} + +func fileExists(name string) bool { + _, err := os.Stat(name) + return err == nil +} + +type FileSet []File + +func (fi FileSet) Exists(pathRegex, needleRegex string) bool { + path := regexp.MustCompile(pathRegex) + needle := regexp.MustCompile(needleRegex) + for _, v := range fi { + if !path.MatchString(v.Absolute) { + continue + } + if v.Match(needle) { + return true + } + } + return false +} + +type File struct { + fs.DirEntry + Absolute string +} + +func (fi File) MustMatch(needle string) bool { + return fi.Match(regexp.MustCompile(needle)) +} + +func (fi File) Match(needle *regexp.Regexp) bool { + raw, err := fi.Raw() + if err != nil { + log.Printf("[ERROR] read %s: %s", fi.Absolute, err) + return false + } + return needle.Match(raw) +} + +func (fi File) Raw() ([]byte, error) { + f, err := os.Open(fi.Absolute) + if err != nil { + return nil, err + } + return io.ReadAll(f) +} + +func recursiveChildren(dir string) (found FileSet, err error) { + queue, err := readDir(dir) + if err != nil { + return nil, err + } + for len(queue) > 0 { + current := queue[0] + queue = queue[1:] + if !current.IsDir() { + found = append(found, current) + continue + } + if current.Name() == "vendor" { + continue + } + if current.Name() == "scripts" { + continue + } + children, err := readDir(current.Absolute) + if err != nil { + return nil, err + } + queue = append(queue, children...) + } + return found, nil +} + +func readDir(dir string) (queue []File, err error) { + f, err := os.Open(dir) + if err != nil { + return + } + defer f.Close() + dirs, err := f.ReadDir(-1) + if err != nil { + return + } + for _, v := range dirs { + absolute := path.Join(dir, v.Name()) + queue = append(queue, File{v, absolute}) + } + return +} diff --git a/provider/provider.go b/provider/provider.go index fc68e4ad47..260ec13fc7 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -36,14 +36,14 @@ import ( func DatabricksProvider() *schema.Provider { p := &schema.Provider{ DataSourcesMap: map[string]*schema.Resource{ // must be in alphabetical order - "databricks_aws_crossaccount_policy": aws.DataAwsCrossAccountPolicy(), + "databricks_aws_crossaccount_policy": aws.DataAwsCrossaccountPolicy(), "databricks_aws_assume_role_policy": aws.DataAwsAssumeRolePolicy(), "databricks_aws_bucket_policy": aws.DataAwsBucketPolicy(), "databricks_clusters": clusters.DataSourceClusters(), "databricks_catalogs": catalog.DataSourceCatalogs(), "databricks_current_user": scim.DataSourceCurrentUser(), - "databricks_dbfs_file": storage.DataSourceDBFSFile(), - "databricks_dbfs_file_paths": storage.DataSourceDBFSFilePaths(), + "databricks_dbfs_file": storage.DataSourceDbfsFile(), + "databricks_dbfs_file_paths": storage.DataSourceDbfsFilePaths(), "databricks_group": scim.DataSourceGroup(), "databricks_jobs": jobs.DataSourceJobs(), "databricks_node_type": clusters.DataSourceNodeType(), @@ -66,7 +66,7 @@ func DatabricksProvider() *schema.Provider { "databricks_catalog": catalog.ResourceCatalog(), "databricks_cluster": clusters.ResourceCluster(), "databricks_cluster_policy": policies.ResourceClusterPolicy(), - "databricks_dbfs_file": storage.ResourceDBFSFile(), + "databricks_dbfs_file": storage.ResourceDbfsFile(), "databricks_directory": workspace.ResourceDirectory(), "databricks_external_location": catalog.ResourceExternalLocation(), "databricks_git_credential": repos.ResourceGitCredential(), @@ -82,19 +82,19 @@ func DatabricksProvider() *schema.Provider { "databricks_library": clusters.ResourceLibrary(), "databricks_metastore": catalog.ResourceMetastore(), "databricks_metastore_assignment": catalog.ResourceMetastoreAssignment(), - "databricks_metastore_data_access": catalog.ResourceDataAccessConfiguration(), - "databricks_mlflow_experiment": mlflow.ResourceMLFlowExperiment(), - "databricks_mlflow_model": mlflow.ResourceMLFlowModel(), - "databricks_mlflow_webhook": mlflow.ResourceMLFlowWebhook(), + "databricks_metastore_data_access": catalog.ResourceMetastoreDataAccess(), + "databricks_mlflow_experiment": mlflow.ResourceMlflowExperiment(), + "databricks_mlflow_model": mlflow.ResourceMlflowModel(), + "databricks_mlflow_webhook": mlflow.ResourceMlflowWebhook(), "databricks_mount": storage.ResourceMount(), - "databricks_mws_customer_managed_keys": mws.ResourceCustomerManagedKey(), - "databricks_mws_credentials": mws.ResourceCredentials(), - "databricks_mws_log_delivery": mws.ResourceLogDelivery(), - "databricks_mws_networks": mws.ResourceNetwork(), - "databricks_mws_private_access_settings": mws.ResourcePrivateAccessSettings(), - "databricks_mws_storage_configurations": mws.ResourceStorageConfiguration(), - "databricks_mws_vpc_endpoint": mws.ResourceVPCEndpoint(), - "databricks_mws_workspaces": mws.ResourceWorkspace(), + "databricks_mws_customer_managed_keys": mws.ResourceMwsCustomerManagedKeys(), + "databricks_mws_credentials": mws.ResourceMwsCredentials(), + "databricks_mws_log_delivery": mws.ResourceMwsLogDelivery(), + "databricks_mws_networks": mws.ResourceMwsNetworks(), + "databricks_mws_private_access_settings": mws.ResourceMwsPrivateAccessSettings(), + "databricks_mws_storage_configurations": mws.ResourceMwsStorageConfigurations(), + "databricks_mws_vpc_endpoint": mws.ResourceMwsVpcEndpoint(), + "databricks_mws_workspaces": mws.ResourceMwsWorkspaces(), "databricks_notebook": workspace.ResourceNotebook(), "databricks_obo_token": tokens.ResourceOboToken(), "databricks_permissions": permissions.ResourcePermissions(), @@ -106,13 +106,13 @@ func DatabricksProvider() *schema.Provider { "databricks_secret_acl": secrets.ResourceSecretACL(), "databricks_service_principal": scim.ResourceServicePrincipal(), "databricks_service_principal_role": aws.ResourceServicePrincipalRole(), - "databricks_sql_dashboard": sql.ResourceDashboard(), - "databricks_sql_endpoint": sql.ResourceSQLEndpoint(), - "databricks_sql_global_config": sql.ResourceSQLGlobalConfig(), + "databricks_sql_dashboard": sql.ResourceSqlDashboard(), + "databricks_sql_endpoint": sql.ResourceSqlEndpoint(), + "databricks_sql_global_config": sql.ResourceSqlGlobalConfig(), "databricks_sql_permissions": access.ResourceSqlPermissions(), - "databricks_sql_query": sql.ResourceQuery(), - "databricks_sql_visualization": sql.ResourceVisualization(), - "databricks_sql_widget": sql.ResourceWidget(), + "databricks_sql_query": sql.ResourceSqlQuery(), + "databricks_sql_visualization": sql.ResourceSqlVisualization(), + "databricks_sql_widget": sql.ResourceSqlWidget(), "databricks_storage_credential": catalog.ResourceStorageCredential(), "databricks_table": catalog.ResourceTable(), "databricks_token": tokens.ResourceToken(), diff --git a/scim/acceptance/resource_group_member_test.go b/scim/acceptance/group_member_test.go similarity index 100% rename from scim/acceptance/resource_group_member_test.go rename to scim/acceptance/group_member_test.go diff --git a/scim/acceptance/resource_service_principal_test.go b/scim/acceptance/service_principal_test.go similarity index 100% rename from scim/acceptance/resource_service_principal_test.go rename to scim/acceptance/service_principal_test.go diff --git a/scim/acceptance/resource_user_test.go b/scim/acceptance/user_test.go similarity index 100% rename from scim/acceptance/resource_user_test.go rename to scim/acceptance/user_test.go diff --git a/sql/acceptance/dashboard_test.go b/sql/acceptance/sql_dashboard_test.go similarity index 100% rename from sql/acceptance/dashboard_test.go rename to sql/acceptance/sql_dashboard_test.go diff --git a/sql/acceptance/query_test.go b/sql/acceptance/sql_query_test.go similarity index 100% rename from sql/acceptance/query_test.go rename to sql/acceptance/sql_query_test.go diff --git a/sql/resource_dashboard.go b/sql/resource_sql_dashboard.go similarity index 98% rename from sql/resource_dashboard.go rename to sql/resource_sql_dashboard.go index 895bad6baa..f3b5c8d58d 100644 --- a/sql/resource_dashboard.go +++ b/sql/resource_sql_dashboard.go @@ -83,8 +83,7 @@ func (a DashboardAPI) Delete(dashboardID string) error { return a.client.Delete(a.context, fmt.Sprintf("/preview/sql/dashboards/%s", dashboardID), nil) } -// ResourceDashboard ... -func ResourceDashboard() *schema.Resource { +func ResourceSqlDashboard() *schema.Resource { s := common.StructToSchema( DashboardEntity{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/sql/resource_dashboard_test.go b/sql/resource_sql_dashboard_test.go similarity index 93% rename from sql/resource_dashboard_test.go rename to sql/resource_sql_dashboard_test.go index c37a9c01c9..b2112aa22f 100644 --- a/sql/resource_dashboard_test.go +++ b/sql/resource_sql_dashboard_test.go @@ -34,7 +34,7 @@ func TestDashboardCreate(t *testing.T) { }, }, }, - Resource: ResourceDashboard(), + Resource: ResourceSqlDashboard(), Create: true, State: map[string]interface{}{ "name": "Dashboard name", @@ -60,7 +60,7 @@ func TestDashboardRead(t *testing.T) { }, }, }, - Resource: ResourceDashboard(), + Resource: ResourceSqlDashboard(), Read: true, ID: "xyz", }.Apply(t) @@ -91,7 +91,7 @@ func TestDashboardUpdate(t *testing.T) { }, }, }, - Resource: ResourceDashboard(), + Resource: ResourceSqlDashboard(), Update: true, ID: "xyz", State: map[string]interface{}{ @@ -112,7 +112,7 @@ func TestDashboardDelete(t *testing.T) { Resource: "/api/2.0/preview/sql/dashboards/xyz", }, }, - Resource: ResourceDashboard(), + Resource: ResourceSqlDashboard(), Delete: true, ID: "xyz", }.Apply(t) @@ -122,5 +122,5 @@ func TestDashboardDelete(t *testing.T) { } func TestResourceDashboardCornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceDashboard()) + qa.ResourceCornerCases(t, ResourceSqlDashboard()) } diff --git a/sql/resource_sql_endpoint.go b/sql/resource_sql_endpoint.go index 733a2bad22..1d9b19d599 100644 --- a/sql/resource_sql_endpoint.go +++ b/sql/resource_sql_endpoint.go @@ -191,8 +191,7 @@ func (a SQLEndpointsAPI) Delete(endpointID string) error { map[string]interface{}{}) } -// ResourceSQLEndpoint ... -func ResourceSQLEndpoint() *schema.Resource { +func ResourceSqlEndpoint() *schema.Resource { s := common.StructToSchema(SQLEndpoint{}, func( m map[string]*schema.Schema) map[string]*schema.Schema { m["auto_stop_mins"].Required = false diff --git a/sql/resource_sql_endpoint_test.go b/sql/resource_sql_endpoint_test.go index b78f95a556..ea9c4a193b 100644 --- a/sql/resource_sql_endpoint_test.go +++ b/sql/resource_sql_endpoint_test.go @@ -100,7 +100,7 @@ func TestResourceSQLEndpointCreate(t *testing.T) { }, dataSourceListHTTPFixture, }, - Resource: ResourceSQLEndpoint(), + Resource: ResourceSqlEndpoint(), Create: true, HCL: ` name = "foo" @@ -125,7 +125,7 @@ func TestResourceSQLEndpointCreate_ErrorDisabled(t *testing.T) { }, }, }, - Resource: ResourceSQLEndpoint(), + Resource: ResourceSqlEndpoint(), Create: true, HCL: ` name = "foo" @@ -150,7 +150,7 @@ func TestResourceSQLEndpointRead(t *testing.T) { }, dataSourceListHTTPFixture, }, - Resource: ResourceSQLEndpoint(), + Resource: ResourceSqlEndpoint(), ID: "abc", Read: true, HCL: ` @@ -194,7 +194,7 @@ func TestResourceSQLEndpointUpdate(t *testing.T) { }, dataSourceListHTTPFixture, }, - Resource: ResourceSQLEndpoint(), + Resource: ResourceSqlEndpoint(), ID: "abc", Update: true, HCL: ` @@ -215,7 +215,7 @@ func TestResourceSQLEndpointDelete(t *testing.T) { Resource: "/api/2.0/sql/endpoints/abc", }, }, - Resource: ResourceSQLEndpoint(), + Resource: ResourceSqlEndpoint(), ID: "abc", Delete: true, }.Apply(t) @@ -224,7 +224,7 @@ func TestResourceSQLEndpointDelete(t *testing.T) { } func TestResourceSQLEndpoint_CornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceSQLEndpoint()) + qa.ResourceCornerCases(t, ResourceSqlEndpoint()) } func TestSQLEnpointAPI(t *testing.T) { diff --git a/sql/resource_sql_global_config.go b/sql/resource_sql_global_config.go index aec871e2dc..4278f04841 100644 --- a/sql/resource_sql_global_config.go +++ b/sql/resource_sql_global_config.go @@ -97,7 +97,7 @@ func (a globalConfigAPI) Get() (GlobalConfig, error) { return gc, nil } -func ResourceSQLGlobalConfig() *schema.Resource { +func ResourceSqlGlobalConfig() *schema.Resource { s := common.StructToSchema(GlobalConfig{}, func( m map[string]*schema.Schema) map[string]*schema.Schema { return m diff --git a/sql/resource_sql_global_config_test.go b/sql/resource_sql_global_config_test.go index 79523f44ab..5d607561d9 100644 --- a/sql/resource_sql_global_config_test.go +++ b/sql/resource_sql_global_config_test.go @@ -30,7 +30,7 @@ func TestResourceSQLGlobalConfigCreateDefault(t *testing.T) { }, }, }, - Resource: ResourceSQLGlobalConfig(), + Resource: ResourceSqlGlobalConfig(), Create: true, HCL: ` `, @@ -61,7 +61,7 @@ func TestResourceSQLGlobalConfigDelete(t *testing.T) { }, }, }, - Resource: ResourceSQLGlobalConfig(), + Resource: ResourceSqlGlobalConfig(), Delete: true, ID: "global", HCL: ` @@ -104,7 +104,7 @@ func TestResourceSQLGlobalConfigCreateWithData(t *testing.T) { }, }, }, - Resource: ResourceSQLGlobalConfig(), + Resource: ResourceSqlGlobalConfig(), Create: true, State: map[string]interface{}{ "security_policy": "PASSTHROUGH", @@ -124,7 +124,7 @@ func TestResourceSQLGlobalConfigCreateWithData(t *testing.T) { func TestResourceSQLGlobalConfigCreateError(t *testing.T) { _, err := qa.ResourceFixture{ - Resource: ResourceSQLGlobalConfig(), + Resource: ResourceSqlGlobalConfig(), Create: true, Azure: true, State: map[string]interface{}{ diff --git a/sql/resource_query.go b/sql/resource_sql_query.go similarity index 99% rename from sql/resource_query.go rename to sql/resource_sql_query.go index f6d7a05f74..0f2f65f31b 100644 --- a/sql/resource_query.go +++ b/sql/resource_sql_query.go @@ -488,8 +488,7 @@ func (a QueryAPI) Delete(queryID string) error { return a.client.Delete(a.context, fmt.Sprintf("/preview/sql/queries/%s", queryID), nil) } -// ResourceQuery ... -func ResourceQuery() *schema.Resource { +func ResourceSqlQuery() *schema.Resource { s := common.StructToSchema( QueryEntity{}, func(m map[string]*schema.Schema) map[string]*schema.Schema { diff --git a/sql/resource_query_test.go b/sql/resource_sql_query_test.go similarity index 97% rename from sql/resource_query_test.go rename to sql/resource_sql_query_test.go index cbfca616c0..7bdcc07521 100644 --- a/sql/resource_query_test.go +++ b/sql/resource_sql_query_test.go @@ -50,7 +50,7 @@ func TestQueryCreate(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, State: map[string]interface{}{ "data_source_id": "xyz", @@ -73,7 +73,7 @@ func TestQueryCreate(t *testing.T) { func TestQueryCreateWithMultipleSchedules(t *testing.T) { qa.ResourceFixture{ - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, HCL: ` data_source_id = "xyz" @@ -134,7 +134,7 @@ func TestQueryCreateWithContinuousSchedule(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, HCL: ` data_source_id = "xyz" @@ -198,7 +198,7 @@ func TestQueryCreateWithDailySchedule(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, HCL: ` data_source_id = "xyz" @@ -265,7 +265,7 @@ func TestQueryCreateWithWeeklySchedule(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, HCL: ` data_source_id = "xyz" @@ -332,7 +332,7 @@ func TestQueryCreateDeletesDefaultVisualization(t *testing.T) { Resource: "/api/2.0/preview/sql/visualizations/12345", }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Create: true, State: map[string]interface{}{ "data_source_id": "xyz", @@ -359,7 +359,7 @@ func TestQueryRead(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Read: true, ID: "foo", }.Apply(t) @@ -387,7 +387,7 @@ func TestQueryReadWithSchedule(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Read: true, ID: "foo", }.Apply(t) @@ -422,7 +422,7 @@ func TestQueryUpdate(t *testing.T) { }, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Update: true, ID: "foo", State: map[string]interface{}{ @@ -552,7 +552,7 @@ func TestQueryUpdateWithParams(t *testing.T) { Response: body, }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Update: true, ID: "foo", HCL: ` @@ -683,7 +683,7 @@ func TestQueryDelete(t *testing.T) { Resource: "/api/2.0/preview/sql/queries/foo", }, }, - Resource: ResourceQuery(), + Resource: ResourceSqlQuery(), Delete: true, ID: "foo", }.Apply(t) @@ -693,5 +693,5 @@ func TestQueryDelete(t *testing.T) { } func TestResourceQueryCornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceQuery()) + qa.ResourceCornerCases(t, ResourceSqlQuery()) } diff --git a/sql/resource_visualization.go b/sql/resource_sql_visualization.go similarity index 98% rename from sql/resource_visualization.go rename to sql/resource_sql_visualization.go index a9f973dad6..f59a3b8acc 100644 --- a/sql/resource_visualization.go +++ b/sql/resource_sql_visualization.go @@ -125,8 +125,7 @@ func jsonRemarshal(in []byte) ([]byte, error) { return out, nil } -// ResourceVisualization ... -func ResourceVisualization() *schema.Resource { +func ResourceSqlVisualization() *schema.Resource { p := common.NewPairSeparatedID("query_id", "visualization_id", "/") s := common.StructToSchema( VisualizationEntity{}, diff --git a/sql/resource_visualization_test.go b/sql/resource_sql_visualization_test.go similarity index 95% rename from sql/resource_visualization_test.go rename to sql/resource_sql_visualization_test.go index 76a1fa5cfd..79ed0acf92 100644 --- a/sql/resource_visualization_test.go +++ b/sql/resource_sql_visualization_test.go @@ -60,7 +60,7 @@ func TestVisualizationCreate(t *testing.T) { }, }, }, - Resource: ResourceVisualization(), + Resource: ResourceSqlVisualization(), Create: true, State: map[string]interface{}{ "query_id": "foo", @@ -114,7 +114,7 @@ func TestVisualizationRead(t *testing.T) { }, }, }, - Resource: ResourceVisualization(), + Resource: ResourceSqlVisualization(), Read: true, ID: "foo/12345", State: map[string]interface{}{ @@ -156,7 +156,7 @@ func TestVisualizationReadNotFound(t *testing.T) { }, }, }, - Resource: ResourceVisualization(), + Resource: ResourceSqlVisualization(), Read: true, Removed: true, RequiresNew: true, @@ -226,7 +226,7 @@ func TestVisualizationUpdate(t *testing.T) { }, }, }, - Resource: ResourceVisualization(), + Resource: ResourceSqlVisualization(), Update: true, ID: "foo/12345", InstanceState: map[string]string{ @@ -264,7 +264,7 @@ func TestVisualizationDelete(t *testing.T) { Resource: "/api/2.0/preview/sql/visualizations/12345", }, }, - Resource: ResourceVisualization(), + Resource: ResourceSqlVisualization(), Delete: true, ID: "foo/12345", }.Apply(t) @@ -274,5 +274,5 @@ func TestVisualizationDelete(t *testing.T) { } func TestResourceVisualizationCornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceVisualization(), qa.CornerCaseID("foo/bar")) + qa.ResourceCornerCases(t, ResourceSqlVisualization(), qa.CornerCaseID("foo/bar")) } diff --git a/sql/resource_widget.go b/sql/resource_sql_widget.go similarity index 99% rename from sql/resource_widget.go rename to sql/resource_sql_widget.go index 446708e671..172111730e 100644 --- a/sql/resource_widget.go +++ b/sql/resource_sql_widget.go @@ -254,8 +254,7 @@ func (a WidgetAPI) Delete(widgetID string) error { return a.client.Delete(a.context, fmt.Sprintf("/preview/sql/widgets/%s", widgetID), nil) } -// ResourceWidget ... -func ResourceWidget() *schema.Resource { +func ResourceSqlWidget() *schema.Resource { p := common.NewPairSeparatedID("dashboard_id", "widget_id", "/") s := common.StructToSchema( WidgetEntity{}, diff --git a/sql/resource_widget_test.go b/sql/resource_sql_widget_test.go similarity index 97% rename from sql/resource_widget_test.go rename to sql/resource_sql_widget_test.go index 96eb0ef1e7..f153aad9a9 100644 --- a/sql/resource_widget_test.go +++ b/sql/resource_sql_widget_test.go @@ -68,7 +68,7 @@ func TestWidgetCreateWithVisualization(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -133,7 +133,7 @@ func TestWidgetCreateWithVisualizationByResourceID(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -193,7 +193,7 @@ func TestWidgetCreateWithText(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -284,7 +284,7 @@ func TestWidgetCreateWithParamValue(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -399,7 +399,7 @@ func TestWidgetCreateWithPosition(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -492,7 +492,7 @@ func TestWidgetCreateWithPositionAndAutoheight(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Create: true, HCL: ` dashboard_id = "some-uuid" @@ -543,7 +543,7 @@ func TestWidgetReadNotFound(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Read: true, Removed: true, RequiresNew: true, @@ -603,7 +603,7 @@ func TestWidgetUpdate(t *testing.T) { }, }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Update: true, ID: "some-uuid/12345", InstanceState: map[string]string{ @@ -637,7 +637,7 @@ func TestWidgetDelete(t *testing.T) { Resource: "/api/2.0/preview/sql/widgets/12345", }, }, - Resource: ResourceWidget(), + Resource: ResourceSqlWidget(), Delete: true, ID: "some-uuid/12345", }.Apply(t) @@ -647,7 +647,7 @@ func TestWidgetDelete(t *testing.T) { } func TestResourceWidgetCornerCases(t *testing.T) { - qa.ResourceCornerCases(t, ResourceWidget(), qa.CornerCaseID("foo/bar")) + qa.ResourceCornerCases(t, ResourceSqlWidget(), qa.CornerCaseID("foo/bar")) } func TestWidgetParameterSorter(t *testing.T) { diff --git a/storage/acceptance/adls_gen1_test.go b/storage/acceptance/azure_adls_gen1_mount_test.go similarity index 100% rename from storage/acceptance/adls_gen1_test.go rename to storage/acceptance/azure_adls_gen1_mount_test.go diff --git a/storage/acceptance/adls_gen2_test.go b/storage/acceptance/azure_adls_gen2_mount_test.go similarity index 100% rename from storage/acceptance/adls_gen2_test.go rename to storage/acceptance/azure_adls_gen2_mount_test.go diff --git a/storage/acceptance/resource_mount_test.go b/storage/acceptance/mount_test.go similarity index 100% rename from storage/acceptance/resource_mount_test.go rename to storage/acceptance/mount_test.go diff --git a/storage/data_dbfs_file.go b/storage/data_dbfs_file.go index 5595b897e9..04c75d326a 100644 --- a/storage/data_dbfs_file.go +++ b/storage/data_dbfs_file.go @@ -8,8 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceDBFSFile ... -func DataSourceDBFSFile() *schema.Resource { +func DataSourceDbfsFile() *schema.Resource { return &schema.Resource{ ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { limitFileSize := d.Get("limit_file_size").(bool) diff --git a/storage/data_dbfs_file_paths.go b/storage/data_dbfs_file_paths.go index feb455d423..193bb5e90f 100644 --- a/storage/data_dbfs_file_paths.go +++ b/storage/data_dbfs_file_paths.go @@ -8,8 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// DataSourceDBFSFilePaths ... -func DataSourceDBFSFilePaths() *schema.Resource { +func DataSourceDbfsFilePaths() *schema.Resource { return &schema.Resource{ ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { path := d.Get("path").(string) diff --git a/storage/data_dbfs_file_paths_test.go b/storage/data_dbfs_file_paths_test.go index 4c9f104cf8..b44232f1ce 100644 --- a/storage/data_dbfs_file_paths_test.go +++ b/storage/data_dbfs_file_paths_test.go @@ -44,7 +44,7 @@ func TestDataSourceFilePaths(t *testing.T) { }, Read: true, NonWritable: true, - Resource: DataSourceDBFSFilePaths(), + Resource: DataSourceDbfsFilePaths(), ID: ".", State: map[string]interface{}{ "path": "/a/b/c", diff --git a/storage/data_dbfs_file_test.go b/storage/data_dbfs_file_test.go index 5589a6ecad..f0a325c6ff 100644 --- a/storage/data_dbfs_file_test.go +++ b/storage/data_dbfs_file_test.go @@ -31,7 +31,7 @@ func TestDataSourceFile(t *testing.T) { }, Read: true, NonWritable: true, - Resource: DataSourceDBFSFile(), + Resource: DataSourceDbfsFile(), ID: ".", State: map[string]interface{}{ "path": "/a/b/c", diff --git a/storage/resource_dbfs_file.go b/storage/resource_dbfs_file.go index a532502a12..d4c530542a 100644 --- a/storage/resource_dbfs_file.go +++ b/storage/resource_dbfs_file.go @@ -10,8 +10,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -// ResourceDBFSFile manages files on DBFS -func ResourceDBFSFile() *schema.Resource { +// ResourceDbfsFile manages files on DBFS +func ResourceDbfsFile() *schema.Resource { return common.Resource{ SchemaVersion: 1, Schema: workspace.FileContentSchema(map[string]*schema.Schema{ diff --git a/storage/resource_dbfs_file_test.go b/storage/resource_dbfs_file_test.go index e3506c49ff..2fafecab23 100644 --- a/storage/resource_dbfs_file_test.go +++ b/storage/resource_dbfs_file_test.go @@ -167,7 +167,7 @@ func TestDBFSFileCreate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { d, err := qa.ResourceFixture{ Fixtures: tt.fixtures, - Resource: ResourceDBFSFile(), + Resource: ResourceDbfsFile(), Create: true, State: map[string]interface{}{ "source": tt.source, @@ -190,7 +190,7 @@ func TestDBFSFileDelete(t *testing.T) { path := "/abc" d, err := qa.ResourceFixture{ Fixtures: getBaseDBFSDeleteFixtures(path, false), - Resource: ResourceDBFSFile(), + Resource: ResourceDbfsFile(), Delete: true, ID: path, State: map[string]interface{}{ @@ -207,7 +207,7 @@ func TestDBFSFileRead_IsMissingResource(t *testing.T) { path := "/abc" qa.ResourceFixture{ Fixtures: getBaseDBFSFileGetStatusFixtures(path, false, true), - Resource: ResourceDBFSFile(), + Resource: ResourceDbfsFile(), Read: true, ID: path, Removed: true, diff --git a/tokens/acceptance/obo_test.go b/tokens/acceptance/obo_token_test.go similarity index 100% rename from tokens/acceptance/obo_test.go rename to tokens/acceptance/obo_token_test.go