Skip to content

Commit db4859e

Browse files
authored
Merge pull request #20 from tomarv2/updates
moving to use terraform 1.0.1
2 parents b6f57d2 + c473e58 commit db4859e

File tree

12 files changed

+112
-58
lines changed

12 files changed

+112
-58
lines changed

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535

3636
## Versions
3737

38-
- Module tested for Terraform 0.14.
39-
- `databrickslabs/databricks` provider version [0.3.3](https://registry.terraform.io/providers/databrickslabs/databricks/latest)
40-
- AWS provider version [3.30](https://registry.terraform.io/providers/hashicorp/aws/latest).
38+
- Module tested for Terraform 1.0.1.
39+
- `databrickslabs/databricks` provider version [0.3.5](https://registry.terraform.io/providers/databrickslabs/databricks/latest)
40+
- AWS provider version [3.47](https://registry.terraform.io/providers/hashicorp/aws/latest).
4141
- `main` branch: Provider versions not pinned to keep up with Terraform releases.
4242
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-databricks-aws-workspace/tags" alt="GitHub tag">
4343
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-databricks-aws-workspace" /></a>).
@@ -57,7 +57,7 @@ terraform destroy -var='teamid=tryme' -var='prjid=project1'
5757

5858
### Option 2:
5959

60-
#### Recommended method (store remote state in S3 using `prjid` and `teamid` to create directory structure):
60+
#### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure):
6161

6262
- Create python 3.6+ virtual environment
6363
```
@@ -66,41 +66,55 @@ python3 -m venv <venv name>
6666

6767
- Install package:
6868
```
69-
pip install tfremote
69+
pip install tfremote --upgrade
7070
```
7171

7272
- Set below environment variables:
7373
```
7474
export TF_AWS_BUCKET=<remote state bucket name>
75-
export TF_AWS_PROFILE=default
7675
export TF_AWS_BUCKET_REGION=us-west-2
76+
export TF_AWS_PROFILE=<profile from ~/.ws/credentials>
7777
```
7878

79-
- Updated `examples` directory with required values.
79+
or
80+
81+
- Set below environment variables:
82+
```
83+
export TF_AWS_BUCKET=<remote state bucket name>
84+
export TF_AWS_BUCKET_REGION=us-west-2
85+
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
86+
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
87+
```
88+
89+
- Update [main.tf](examples/sample/main.tf) file with required values.
8090

8191
- Run and verify the output before deploying:
8292
```
83-
tf -cloud aws plan -var='teamid=foo' -var='prjid=bar'
93+
tf -c=aws plan -var='teamid=foo' -var='prjid=bar'
8494
```
8595

8696
- Run below to deploy:
8797
```
88-
tf -cloud aws apply -var='teamid=foo' -var='prjid=bar'
98+
tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
8999
```
90100

91101
- Run below to destroy:
92102
```
93-
tf -cloud aws destroy -var='teamid=foo' -var='prjid=bar'
103+
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
94104
```
95105

96106
**NOTE:**
97107

98108
- Read more on [tfremote](https://github.com/tomarv2/tfremote)
99109

110+
### Databricks workspace creation with new role
100111
```
101112
module "databricks_workspace" {
102113
source = "git::git@github.com:tomarv2/terraform-databricks-aws-workspace.git"
103114
115+
# NOTE: One of the below is required:
116+
# - 'profile_for_iam' - for IAM creation (if none is provided 'default' is used)
117+
# - 'existing_role_name'
104118
profile_for_iam = "iam-admin"
105119
aws_region = "us-east-2"
106120
databricks_account_username = "example@example.com"
@@ -113,6 +127,26 @@ module "databricks_workspace" {
113127
}
114128
```
115129

130+
### Databricks workspace creation with existing role
131+
```
132+
module "databricks_workspace" {
133+
source = "git::git@github.com:tomarv2/terraform-databricks-aws-workspace.git"
134+
135+
# NOTE: One of the below is required:
136+
# - 'profile_for_iam' - for IAM creation (if none is provided 'default' is used)
137+
# - 'existing_role_name'
138+
existing_role_arn = "arn:aws:iam::123456789012:role/demo-role"
139+
aws_region = "us-east-2"
140+
databricks_account_username = "example@example.com"
141+
databricks_account_password = "sample123!"
142+
databricks_account_id = "1234567-1234-1234-1234-1234567"
143+
# -----------------------------------------
144+
# Do not change the teamid, prjid once set.
145+
teamid = var.teamid
146+
prjid = var.prjid
147+
}
148+
```
149+
116150
Please refer to examples directory [link](examples) for references.
117151

118152
## Coming up:

examples/sample/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module "databricks_workspace" {
2-
source = "git::git@github.com:tomarv2/terraform-databricks-aws-workspace.git?ref=v0.0.5"
2+
source = "git::git@github.com:tomarv2/terraform-databricks-aws-workspace.git?ref=v0.0.6"
33

4+
# NOTE: One of the below is required:
5+
# - 'profile_for_iam' - for IAM creation (if none is provided 'default' is used)
6+
# - 'existing_role_name'
47
profile_for_iam = "iam-admin"
8+
existing_role_name = "arn:aws:iam::123456789012:role/demo-role"
59
aws_region = "us-east-2"
610
databricks_account_username = "example@example.com"
711
databricks_account_password = "sample123!"

examples/sample/outputs.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ output "databricks_mws_network_id" {
2121
output "storage_configuration_id" {
2222
description = "databricks mws storage id"
2323
value = module.databricks_workspace.databricks_mws_storage_id
24+
sensitive = true
2425
}
2526

2627
output "databricks_host" {
2728
description = "databricks workspace url"
2829
value = module.databricks_workspace.workspace_url
30+
sensitive = true
2931
}
3032

3133
output "databricks_credentials_id" {
@@ -43,9 +45,9 @@ output "pat_token" {
4345
description = "databricks pat"
4446
value = module.databricks_workspace.pat_token
4547
}
48+
*/
4649

4750
output "pat_token_duration" {
4851
description = "databricks pat"
4952
value = module.databricks_workspace.pat_token_duration
5053
}
51-
*/

examples/sample/remote_backend.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/test/remote_backend.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

iam.tf

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,3 @@ data "databricks_aws_assume_role_policy" "this" {
33
}
44

55
data "databricks_aws_crossaccount_policy" "cross_account_iam_policy" {}
6-
7-
8-
data "databricks_aws_bucket_policy" "this" {
9-
bucket = module.s3.s3_bucket_name
10-
}
11-
12-
resource "aws_s3_bucket_policy" "root_bucket_policy" {
13-
bucket = module.s3.s3_bucket_id
14-
policy = data.databricks_aws_bucket_policy.this.json
15-
depends_on = [databricks_mws_networks.this]
16-
}

main.tf

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,38 @@ module "vpc" {
99
}
1010

1111
module "iam_role" {
12-
source = "git::git@github.com:tomarv2/terraform-aws-iam-role.git//modules/iam_role_external?ref=v0.0.3"
12+
source = "git::git@github.com:tomarv2/terraform-aws-iam-role.git//modules/iam_role_external?ref=v0.0.4"
13+
14+
count = var.existing_role_name == null ? 1 : 0
1315

14-
profile_to_use = local.profile_to_use
1516
assume_role_policy = data.databricks_aws_assume_role_policy.this.json
1617
external_id = var.databricks_account_id
1718
# -----------------------------------------
1819
# Do not change the teamid, prjid once set.
1920
teamid = var.teamid
2021
prjid = "${var.prjid}-${local.suffix}"
22+
23+
providers = {
24+
aws = aws.iam-management
25+
}
2126
}
2227

2328
module "iam_policies" {
24-
source = "git::git@github.com:tomarv2/terraform-aws-iam-policies.git?ref=v0.0.3"
29+
source = "git::git@github.com:tomarv2/terraform-aws-iam-policies.git?ref=v0.0.4"
2530

26-
profile_to_use = local.profile_to_use
27-
role_name = module.iam_role.iam_role_name
28-
policy = data.databricks_aws_crossaccount_policy.cross_account_iam_policy.json
29-
inline_policy = true
31+
count = var.existing_role_name == null ? 1 : 0
32+
33+
role_name = join("", module.iam_role.*.iam_role_name)
34+
policy = data.databricks_aws_crossaccount_policy.cross_account_iam_policy.json
35+
inline_policy = true
3036
# -----------------------------------------
3137
# Do not change the teamid, prjid once set.
3238
teamid = var.teamid
3339
prjid = "${var.prjid}-${local.suffix}"
40+
41+
providers = {
42+
aws = aws.iam-management
43+
}
3444
}
3545

3646
module "s3" {

mws.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ resource "databricks_mws_networks" "this" {
1010
resource "databricks_mws_credentials" "this" {
1111
provider = databricks.mws
1212
account_id = var.databricks_account_id
13-
role_arn = module.iam_role.iam_role_arn
13+
role_arn = var.existing_role_name != null ? var.existing_role_name : join("", module.iam_role.*.iam_role_arn)
1414
credentials_name = "${var.teamid}-${var.prjid}-${local.suffix}"
15-
depends_on = [module.iam_role]
15+
16+
depends_on = [module.iam_role]
1617
}
1718

1819
resource "databricks_mws_storage_configurations" "this" {

outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ output "vpc_id" {
55

66
output "iam_role_arn" {
77
description = "iam role arn"
8-
value = module.iam_role.iam_role_arn
8+
value = module.iam_role.*.iam_role_arn
99
}
1010

1111
output "inline_policy_id" {
1212
description = "inline policy id"
13-
value = module.iam_policies.inline_policy_id
13+
value = module.iam_policies.*.inline_policy_id
1414
}
1515

1616
output "s3_bucket_name" {
@@ -76,11 +76,11 @@ output "workspace_url" {
7676
/*
7777
output "pat_token" {
7878
description = "databricks pat"
79-
value = databricks_token.pat.id
79+
value = databricks_token.pat.pat_token
8080
}
81+
*/
8182

8283
output "pat_token_duration" {
8384
description = "databricks pat"
8485
value = databricks_token.pat.lifetime_seconds
8586
}
86-
*/

s3.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data "databricks_aws_bucket_policy" "this" {
2+
bucket = module.s3.s3_bucket_name
3+
}
4+
5+
resource "aws_s3_bucket_policy" "root_bucket_policy" {
6+
bucket = module.s3.s3_bucket_id
7+
policy = data.databricks_aws_bucket_policy.this.json
8+
depends_on = [databricks_mws_networks.this]
9+
}

0 commit comments

Comments
 (0)