-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from data-platform-hq/feat/databricks_aws_uc_role
feat: databricks aws uc role
- Loading branch information
Showing
5 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
resource "databricks_storage_credential" "this" { | ||
name = coalesce(var.storage_credential_name, "${var.iam_role_name}-creds") | ||
metastore_id = var.metastore_id | ||
force_update = true | ||
force_destroy = true | ||
|
||
aws_iam_role { | ||
role_arn = "arn:aws:iam::${var.aws_account_id}:role/${var.iam_role_name}" | ||
} | ||
} | ||
|
||
data "databricks_aws_unity_catalog_assume_role_policy" "this" { | ||
aws_account_id = var.aws_account_id | ||
role_name = var.iam_role_name | ||
external_id = databricks_storage_credential.this.aws_iam_role[0].external_id | ||
} | ||
|
||
data "databricks_aws_unity_catalog_policy" "this" { | ||
for_each = var.bucket_names | ||
|
||
aws_account_id = var.aws_account_id | ||
bucket_name = each.value | ||
role_name = var.iam_role_name | ||
} | ||
|
||
module "iam_uc_role_policy" { | ||
for_each = var.bucket_names | ||
source = "terraform-aws-modules/iam/aws//modules/iam-policy" | ||
version = "~>5.0" | ||
|
||
name = each.value | ||
policy = data.databricks_aws_unity_catalog_policy.this[each.key].json | ||
} | ||
|
||
module "iam_uc_role" { | ||
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role" | ||
version = "~>5.0" | ||
|
||
role_name = var.iam_role_name | ||
create_role = true | ||
create_custom_role_trust_policy = true | ||
custom_role_trust_policy = data.databricks_aws_unity_catalog_assume_role_policy.this.json | ||
role_permissions_boundary_arn = var.iam_role_boundary_arn | ||
custom_role_policy_arns = [for k, v in var.bucket_names : module.iam_uc_role_policy[k].arn] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output "storage_creds_id" { | ||
description = "The ID of the Databricks storage credential." | ||
value = databricks_storage_credential.this.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
variable "aws_account_id" { | ||
description = "The AWS account ID" | ||
type = string | ||
} | ||
|
||
variable "bucket_names" { | ||
description = "A map of bucket names to their IDs" | ||
type = map(string) | ||
} | ||
|
||
variable "iam_role_boundary_arn" { | ||
description = "The ARN of the IAM permissions boundary" | ||
type = string | ||
} | ||
|
||
variable "metastore_id" { | ||
description = "The ID of the Databricks metastore" | ||
type = string | ||
} | ||
|
||
variable "iam_role_name" { | ||
description = "The name of the IAM role" | ||
type = string | ||
} | ||
|
||
variable "storage_credential_name" { | ||
description = "The name of the Databricks storage credential." | ||
type = string | ||
default = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 1.7" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~>5.0" | ||
} | ||
databricks = { | ||
source = "databricks/databricks" | ||
version = "~>1.0" | ||
} | ||
} | ||
} |