0
Error: cannot create mws credentials: MALFORMED_REQUEST: Failed credential validation checks: please use a valid cross account IAM role with permissions setup correctly

  on cross-account-role.tf line 33, in resource "databricks_mws_credentials" "this":
  33: resource "databricks_mws_credentials" "this" {

Getting above error when I run terraform apply. What does it mean. How do I resolve it?

I am sharing some below files for reference:

// Create the required AWS STS assume role policy in your AWS account.
// See https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/aws_assume_role_policy
data "databricks_aws_assume_role_policy" "this" {
  external_id = var.databricks_account_id
}

// Create the required IAM role in your AWS account.
// See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role
resource "aws_iam_role" "cross_account_role" {
  name               = "${local.prefix}-crossaccount"
  assume_role_policy = data.databricks_aws_assume_role_policy.this.json
  tags               = var.tags
}

// Create the required AWS cross-account policy in your AWS account.
// See https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/aws_crossaccount_policy
data "databricks_aws_crossaccount_policy" "this" {}

output "databricks_aws_crossaccount_policy" {
  value = data.databricks_aws_crossaccount_policy.this
}

// Create the required IAM role inline policy in your AWS account.
// See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy
resource "aws_iam_role_policy" "this" {
  name   = "${local.prefix}-policy"
  role   = aws_iam_role.cross_account_role.id
  policy = data.databricks_aws_crossaccount_policy.this.json
}

// Properly configure the cross-account role for the creation of new workspaces within your AWS account.
// See https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/mws_credentials
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]
}

Here is what init.tf looks like

terraform {
  required_providers {
    databricks = {
      source = "databricks/databricks"
      version = "1.11.1"
    }
    aws = {
      source = "hashicorp/aws"
      version = "4.57.0"
    }
  }
}

provider "aws" {
  region = var.region
}

// Initialize provider in "MWS" mode to provision the new workspace.
// alias = "mws" instructs Databricks to connect to https://accounts.cloud.databricks.com, to create
// a Databricks workspace that uses the E2 version of the Databricks on AWS platform.
// See https://registry.terraform.io/providers/databricks/databricks/latest/docs#authentication
provider "databricks" {
  alias    = "mws"
  host     = "https://accounts.cloud.databricks.com"
  username = var.databricks_account_username
  password = var.databricks_account_password
}

Here is what vars.tf looks like

# variable "databricks_connection_profile" {}
variable "databricks_account_id" {}
variable "databricks_account_username" {}
variable "databricks_account_password" {}


variable "tags" {
  default = {
      using     = "terraform"
      test      = "true"
      date      = "6 March 2023"
  }
}

variable "cidr_block" {
  default = "10.4.0.0/16"
}

variable "region" {
  default = "us-east-1"
}

locals {
  prefix = "databricksdev"
}

The value I am passing for databricks_account_id is a uuid i found in databricks console on clicking on email address at the top right corner

Vinit Khandelwal
  • 490
  • 8
  • 20
  • What you've shared looks like databricks example code. Are you sure that is the code that is not working? – Marko E Mar 07 '23 at 08:08
  • follow this guide from terraform documentation: https://registry.terraform.io/providers/databricks/databricks/latest/docs/guides/aws-workspace or take this module: https://registry.terraform.io/modules/databricks/examples/databricks/latest/submodules/aws-workspace-basic – Alex Ott Apr 07 '23 at 12:07

0 Answers0