databricks / terraform-databricks-examples

Examples of using Terraform to deploy Databricks resources
https://registry.terraform.io/modules/databricks/examples/databricks/latest
Other
206 stars 125 forks source link

Adding a dependency on the IAM Role when creating databricks_mws_credentials #62

Closed pavs23 closed 1 year ago

pavs23 commented 1 year ago

Introduction

I'm creating new Databricks workspace as a hobby using Terraform & AWS.

Issue

The issue I've faced a couple of times during the creation of the workspace, particularly the databricks_mws_credentials resource is that when we try to attach it to the IAM Role, it may not have been created yet. The terraform apply step fails due to the race condition where the aws_iam_role.cross_account_role doesn't exist yet.

I've pulled out the code which caused the issue from the docs: https://docs.databricks.com/dev-tools/terraform/tutorial-aws.html

resource "databricks_mws_credentials" "this" {
  provider         = databricks.mws
  account_id       = var.databricks_account_id
  role_arn         = aws_iam_role.cross_account_role.arn
  credentials_name = "${local.prefix}-creds"
  depends_on       = [aws_iam_role_policy.this]
}

Fix

The simplest fix:

resource "databricks_mws_credentials" "this" {
  provider         = databricks.mws
  account_id       = var.databricks_account_id
  role_arn         = aws_iam_role.cross_account_role.arn
  credentials_name = "${local.prefix}-creds"
  depends_on       = [aws_iam_role_policy.this, aws_iam_role.cross_account_role]
}

I'm willing to raise this PR to update the examples in this repo, someone from @databricks will need to kindly update the docs website.

Thank you, Pavan

yessawab commented 1 year ago

Hi @pavs23, which example are you referring to ? Can you check the fix with this PR ?

pavs23 commented 1 year ago

Hey @yessawab,

Thanks for the fast response. That fix you've linked is also a good option.

When I searched this repo I found examples like these:

My request would be to update the docs page please: https://docs.databricks.com/dev-tools/terraform/tutorial-aws.html

pavs23 commented 1 year ago

Hey @yessawab, I raised the PR to fix those examples. Please let me know your feedback.

Thanks, Pavan

yessawab commented 1 year ago

Awesome. Thanks for the PR @pavs23. I will request the doc change.