Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure Databricks external location role exists before making it self-referential #667

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions databricks-catalog-external-location/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ data "aws_caller_identity" "current" {
}

locals {
path = "/databricks/"
name = "${var.tags.project}-${var.tags.env}"
bucket_name = "${local.name}-dbx-catalog-bucket"
iam_role_name = "external_location_dbx_${var.tags.env}_aws_role"
iam_role_prefix = "databricks"
path = "/${local.iam_role_prefix}/"
name = "${var.tags.project}-${var.tags.env}"
bucket_name = "${local.name}-dbx-catalog-bucket"
iam_role_name = "external_location_dbx_${var.tags.env}_aws_role"
iam_role_arn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${local.iam_role_name}"
}

## Bucket and policy
Expand Down Expand Up @@ -61,8 +63,7 @@ data "aws_iam_policy_document" "databricks_external_location_assume_role" {
principals {
type = "AWS"
identifiers = [
"arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${local.iam_role_name}"
"arn:aws:iam::414351767826:role/unity-catalog-prod-UCMasterRole-14S5ZJVKOTYTL"
]
}

Expand All @@ -86,7 +87,7 @@ data "aws_iam_policy_document" "databricks_external_location_assume_role" {
test = "ArnEquals"
variable = "aws:PrincipalArn"

values = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${local.iam_role_name}"]
values = [local.iam_role_arn]
}
}
}
Expand Down Expand Up @@ -119,13 +120,8 @@ data "aws_iam_policy_document" "databricks_external_location_bucket_access" {

statement {
sid = "databricksAssumeRole"
effect = "Allow"
actions = [
"sts:AssumeRole"
]
resources = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role${local.path}${local.iam_role_name}"
]
actions = ["sts:AssumeRole"]
resources = [local.iam_role_arn]
}
}

Expand All @@ -140,6 +136,12 @@ resource "aws_iam_role_policy_attachment" "databricks_external_location_bucket_a
role = aws_iam_role.databricks_external_location_iam_role.name
}

resource "aws_iam_role_policy" "databricks_external_location_access_role_policy" {
name_prefix = local.iam_role_prefix
role = aws_iam_role.databricks_external_location_iam_role.id
policy = data.aws_iam_policy_document.databricks_external_location_bucket_access.json
}

### Databricks storage credential - allows workspace to access an external location.
### NOTE: names need to be unique across an account, not just a workspace
resource "databricks_storage_credential" "external" {
Expand Down
Loading