Skip to content

Commit d7388bd

Browse files
authored
Enforce consistent naming for resource files (#1366)
* Fixed README.md * Enforced consistent naming for resources and files * Added provider/completeness.md to track documentation and testing coverage
1 parent b2de36c commit d7388bd

File tree

78 files changed

+971
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+971
-569
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,6 @@ tf.log
340340

341341
scripts/tt
342342

343-
.metals
343+
.metals
344+
345+
provider/completeness.md

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
| [databricks_dbfs_file](docs/resources/dbfs_file.md)
2121
| [databricks_dbfs_file_paths](docs/data-sources/dbfs_file_paths.md) data
2222
| [databricks_dbfs_file](docs/data-sources/dbfs_file.md) data
23+
| [databricks_directory](docs/resources/directory.md)
2324
| [databricks_external_location](docs/resources/external_location.md)
25+
| [databricks_git_credential](docs/resources/git_credential.md)
2426
| [databricks_global_init_script](docs/resources/global_init_script.md)
2527
| [databricks_grants](docs/resources/grants.md)
2628
| [databricks_group](docs/resources/group.md)
@@ -31,17 +33,22 @@
3133
| [databricks_instance_profile](docs/resources/instance_profile.md)
3234
| [databricks_ip_access_list](docs/resources/ip_access_list.md)
3335
| [databricks_job](docs/resources/job.md)
36+
| [databricks_jobs](docs/data-sources/jobs.md)
3437
| [databricks_library](docs/resources/library.md)
3538
| [databricks_metastore](docs/resources/metastore.md)
3639
| [databricks_metastore_assignment](docs/resources/metastore_assignment.md)
3740
| [databricks_metastore_data_access](docs/resources/metastore_data_access.md)
3841
| [databricks_mlflow_model](docs/resources/mlflow_model.md)
3942
| [databricks_mlflow_experiment](docs/resources/mlflow_experiment.md)
43+
| [databricks_mlflow_webhook](docs/resources/mlflow_webhook.md)
44+
| [databricks_mount](docs/resources/mount.md)
4045
| [databricks_mws_credentials](docs/resources/mws_credentials.md)
4146
| [databricks_mws_customer_managed_keys](docs/resources/mws_customer_managed_keys.md)
4247
| [databricks_mws_log_delivery](docs/resources/mws_log_delivery.md)
4348
| [databricks_mws_networks](docs/resources/mws_networks.md)
49+
| [databricks_mws_private_access_settings](docs/resources/mws_private_access_settings.md)
4450
| [databricks_mws_storage_configurations](docs/resources/mws_storage_configurations.md)
51+
| [databricks_mws_vpc_endpoint](docs/resources/mws_vpc_endpoint.md)
4552
| [databricks_mws_workspaces](docs/resources/mws_workspaces.md)
4653
| [databricks_node_type](docs/data-sources/node_type.md) data
4754
| [databricks_notebook](docs/resources/notebook.md)
@@ -56,6 +63,8 @@
5663
| [databricks_secret](docs/resources/secret.md)
5764
| [databricks_secret_acl](docs/resources/secret_acl.md)
5865
| [databricks_secret_scope](docs/resources/secret_scope.md)
66+
| [databricks_service_principal](docs/resources/service_principal.md)
67+
| [databricks_service_principal_role](docs/resources/service_principal_role.md)
5968
| [databricks_spark_version](docs/data-sources/spark_version.md) data
6069
| [databricks_sql_dashboard](docs/resources/sql_dashboard.md)
6170
| [databricks_sql_endpoint](docs/resources/sql_endpoint.md)
@@ -69,8 +78,11 @@
6978
| [databricks_tables](docs/data-sources/table.md) data
7079
| [databricks_token](docs/resources/token.md)
7180
| [databricks_user](docs/resources/user.md)
81+
| [databricks_user_role](docs/resources/user_role.md)
7282
| [databricks_user_instance_profile](docs/resources/user_instance_profile.md)
83+
| [databricks_views](docs/data-sources/views.md) data
7384
| [databricks_workspace_conf](docs/resources/workspace_conf.md)
85+
| [databricks_zones](docs/data-sources/zones.md)
7486
| [Contributing and Development Guidelines](CONTRIBUTING.md)
7587

7688
[![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)
File renamed without changes.
File renamed without changes.

aws/data_aws_assume_role_policy.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
type awsIamPolicy struct {
13+
Version string `json:"Version,omitempty"`
14+
ID string `json:"Id,omitempty"`
15+
Statements []*awsIamPolicyStatement `json:"Statement"`
16+
}
17+
18+
type awsIamPolicyStatement struct {
19+
Sid string `json:"Sid,omitempty"`
20+
Effect string `json:"Effect,omitempty"`
21+
Actions interface{} `json:"Action,omitempty"`
22+
NotActions interface{} `json:"NotAction,omitempty"`
23+
Resources interface{} `json:"Resource,omitempty"`
24+
NotResources interface{} `json:"NotResource,omitempty"`
25+
Principal map[string]string `json:"Principal,omitempty"`
26+
Condition map[string]map[string]string `json:"Condition,omitempty"`
27+
}
28+
29+
30+
// DataAwsAssumeRolePolicy ...
31+
func DataAwsAssumeRolePolicy() *schema.Resource {
32+
return &schema.Resource{
33+
ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
34+
externalID := d.Get("external_id").(string)
35+
policy := awsIamPolicy{
36+
Version: "2012-10-17",
37+
Statements: []*awsIamPolicyStatement{
38+
{
39+
Effect: "Allow",
40+
Actions: "sts:AssumeRole",
41+
Condition: map[string]map[string]string{
42+
"StringEquals": {
43+
"sts:ExternalId": externalID,
44+
},
45+
},
46+
Principal: map[string]string{
47+
"AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)),
48+
},
49+
},
50+
},
51+
}
52+
if v, ok := d.GetOk("for_log_delivery"); ok {
53+
if v.(bool) {
54+
// this is production UsageDelivery IAM role, that is considered a constant
55+
logDeliveryARN := "arn:aws:iam::414351767826:role/SaasUsageDeliveryRole-prod-IAMRole-3PLHICCRR1TK"
56+
policy.Statements[0].Principal["AWS"] = logDeliveryARN
57+
}
58+
}
59+
policyJSON, err := json.MarshalIndent(policy, "", " ")
60+
if err != nil {
61+
return diag.FromErr(err)
62+
}
63+
d.SetId(externalID)
64+
// nolint
65+
d.Set("json", string(policyJSON))
66+
return nil
67+
},
68+
Schema: map[string]*schema.Schema{
69+
"databricks_account_id": {
70+
Type: schema.TypeString,
71+
Default: "414351767826",
72+
Optional: true,
73+
},
74+
"for_log_delivery": {
75+
Type: schema.TypeBool,
76+
Description: "Grant AssumeRole to Databricks SaasUsageDeliveryRole instead of root account",
77+
Optional: true,
78+
Default: false,
79+
},
80+
"external_id": {
81+
Type: schema.TypeString,
82+
Required: true,
83+
},
84+
"json": {
85+
Type: schema.TypeString,
86+
Computed: true,
87+
ForceNew: true,
88+
},
89+
},
90+
}
91+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package aws
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databrickslabs/terraform-provider-databricks/qa"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestDataAwsAssumeRolePolicy(t *testing.T) {
11+
d, err := qa.ResourceFixture{
12+
Read: true,
13+
Resource: DataAwsAssumeRolePolicy(),
14+
NonWritable: true,
15+
ID: ".",
16+
HCL: `external_id = "abc"`,
17+
}.Apply(t)
18+
assert.NoError(t, err)
19+
j := d.Get("json")
20+
assert.Lenf(t, j, 299, "Strange length for policy: %s", j)
21+
}

aws/data_aws_bucket_policy.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"regexp"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12+
)
13+
14+
// DataAwsBucketPolicy ...
15+
func DataAwsBucketPolicy() *schema.Resource {
16+
return &schema.Resource{
17+
ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
18+
bucket := d.Get("bucket").(string)
19+
policy := awsIamPolicy{
20+
Version: "2012-10-17",
21+
Statements: []*awsIamPolicyStatement{
22+
{
23+
Effect: "Allow",
24+
Actions: []string{
25+
"s3:GetObject",
26+
"s3:GetObjectVersion",
27+
"s3:PutObject",
28+
"s3:DeleteObject",
29+
"s3:ListBucket",
30+
"s3:GetBucketLocation",
31+
},
32+
Resources: []string{
33+
fmt.Sprintf("arn:aws:s3:::%s/*", bucket),
34+
fmt.Sprintf("arn:aws:s3:::%s", bucket),
35+
},
36+
Principal: map[string]string{
37+
"AWS": fmt.Sprintf("arn:aws:iam::%s:root", d.Get("databricks_account_id").(string)),
38+
},
39+
},
40+
},
41+
}
42+
if v, ok := d.GetOk("full_access_role"); ok {
43+
policy.Statements[0].Principal["AWS"] = v.(string)
44+
}
45+
policyJSON, err := json.MarshalIndent(policy, "", " ")
46+
if err != nil {
47+
return diag.FromErr(err)
48+
}
49+
d.SetId(bucket)
50+
// nolint
51+
d.Set("json", string(policyJSON))
52+
return nil
53+
},
54+
Schema: map[string]*schema.Schema{
55+
"databricks_account_id": {
56+
Type: schema.TypeString,
57+
Default: "414351767826",
58+
Optional: true,
59+
},
60+
"full_access_role": {
61+
Type: schema.TypeString,
62+
Optional: true,
63+
},
64+
"bucket": {
65+
Type: schema.TypeString,
66+
Required: true,
67+
ValidateFunc: validation.StringMatch(
68+
regexp.MustCompile(`^[0-9a-zA-Z_-]+$`),
69+
"must contain only alphanumeric, underscore, and hyphen characters"),
70+
},
71+
"json": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
ForceNew: true,
75+
},
76+
},
77+
}
78+
}

aws/data_aws_bucket_policy_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package aws
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databrickslabs/terraform-provider-databricks/qa"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestDataAwsBucketPolicy(t *testing.T) {
11+
d, err := qa.ResourceFixture{
12+
Read: true,
13+
Resource: DataAwsBucketPolicy(),
14+
NonWritable: true,
15+
ID: ".",
16+
HCL: `
17+
bucket = "abc"
18+
`,
19+
}.Apply(t)
20+
assert.NoError(t, err)
21+
j := d.Get("json")
22+
assert.Lenf(t, j, 440, "Strange length for policy: %s", j)
23+
}
24+
25+
func TestDataAwsBucketPolicy_FullAccessRole(t *testing.T) {
26+
d, err := qa.ResourceFixture{
27+
Read: true,
28+
Resource: DataAwsBucketPolicy(),
29+
NonWritable: true,
30+
ID: ".",
31+
HCL: `
32+
bucket = "abc"
33+
full_access_role = "bcd"
34+
`,
35+
}.Apply(t)
36+
assert.NoError(t, err)
37+
j := d.Get("json")
38+
assert.Lenf(t, j, 413, "Strange length for policy: %s", j)
39+
}

0 commit comments

Comments
 (0)