hashicorp / terraform-provider-awscc

Terraform AWS Cloud Control provider
https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
Mozilla Public License 2.0
260 stars 118 forks source link

awscc_databrew_job - fails to create the job in a multi account setup. "Cross-account pass role is not allowed" #1093

Open Venkat2512 opened 1 year ago

Venkat2512 commented 1 year ago

Community Note

Description:

We have a multi account setup where in the source account assumes a role in the destination account to create resources. Both the user in the source and assumed role in the destination account has full permissions on all the resources.

aws provider is able to create cross account resources without any issues but awscc fails to do so.

Terraform CLI and Terraform AWS Cloud Control Provider Version

Terraform v1.0.9 on darwin_arm64

Affected Resource(s)

awscc_databrew_job

Terraform Configuration Files

Root module:

provider.tf

provider "aws" {
  region = var.region
}

provider "awscc" {
  region = var.region
}

provider "awscc" {
  region = var.region
  alias  = "modeling"
  assume_role {
    role_arn = "Destination assumed role ARN"
  }
} 

versions.tf

terraform {
  required_version = ">= 0.15"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.9.0"
    }
    awscc = {
      source  = "hashicorp/awscc"
      version = ">= 0.55.0"
    }
  }

  backend "s3" {

  }
}

Main.tf

resource "awscc_databrew_job" "databrew" {
  name         = "brewjob"
  role_arn     = aws_iam_role.databrew_role[0].arn
  type         = "PROFILE"
  }

data "aws_iam_policy_document" "databrew_assume_role_document" {
  version = "2012-10-17"
  statement {
    effect = "Allow"
    principals {
      type        = "Service"
      identifiers = ["databrew.amazonaws.com"]
    }
    actions = [
      "sts:AssumeRole"
    ]
  }
}

resource "aws_iam_role" "databrew_role" {
  name               =  "testrole"
  assume_role_policy = data.aws_iam_policy_document.databrew_assume_role_document.json
}

resource "aws_iam_role_policy" "databrew_role_policy" {
  name   = "testpolicy"
  role   = aws_iam_role.databrew_role.id
  policy = data.aws_iam_policy_document.databrew_policy.json
}

data "aws_iam_policy_document" "databrew_policy" {
  version = "2012-10-17"
    statement {
    sid    = "ToUseCloudWatchLogs"
    effect = "Allow"
    actions = [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
    ]
 resources = ["*"]
    ]
  }
}

Debug Output

Panic Output

Expected Behavior

Actual Behavior


│ Error: AWS SDK Go Service Operation Incomplete
│ 
│   with module.modeling.awscc_databrew_job.databrew[0],
│   on module/modeling/main.tf line 1, in resource "awscc_databrew_job" "databrew":
│    1: resource "awscc_databrew_job" "databrew" {
│ 
│ Waiting for Cloud Control API service CreateResource operation completion returned: waiter state transitioned to FAILED. StatusMessage: Cross-account pass role is not allowed. (Service: DataBrew,
│ Status Code: 403, Request ID: 21cad71c-c45f-43c7-bb14-4f62811496cf, Extended Request ID: null). ErrorCode: ServiceInternalError

Steps to Reproduce

terraform apply with the above configuration.

Important Factoids

References

7adityaraj commented 1 year ago

I am having the same issue, is there any workaround for this @Venkat2512

Venkat2512 commented 1 year ago

Unfortunately, no. Any luck on your side?

7adityaraj commented 1 year ago

hi @ewbankkit any suggestions for this one please.

corrigac commented 1 year ago

Similar issue here on AWS account under control tower, works fine on non control tower AWS account

│ Error: AWS SDK Go Service Operation Incomplete │ │ with module.cloud_watch_alarms.awscc_chatbot_slack_channel_configuration.slack_integration[0], │ on ../../../cloudwatchalarm/main.tf line 31, in resource "awscc_chatbot_slack_channel_configuration" "slack_integration": │ 31: resource "awscc_chatbot_slack_channel_configuration" "slack_integration" { │ │ Waiting for Cloud Control API service CreateResource operation completion returned: waiter state transitioned to │ FAILED. StatusMessage: Cross-account pass role is not allowed. (Service: AWSChatbot; Status Code: 403; Error │ Code: AccessDeniedException; Request ID: c84dc7eb-7e1f-41ef-8216-d43e57ebdd53; Proxy: null). ErrorCode: │ GeneralServiceException provider = terraform-provider-aws_v5.14.0_x5: on darwin_arm64

Turns out to be an AWS IAM cross account configuration issue rather than TF resolved by adding a provider stanza for awscc with profile and region settings

tobywan commented 1 year ago

Thanks @corrigac

For clarity, this is the stanza I added successfully:

provider "awscc" {
  # As we use some resources not yet in the aws terraform provider
  # see https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
  region = "us-east-1"
  assume_role = {
    role_arn = local.aws_provider_iam_role_arn
  }
}

where the role arn is based on which control tower account we are deploying into

wellsiau-aws commented 1 year ago

@Venkat2512 are you able to incorporate the suggested fix above?

ravik2004 commented 4 months ago

this is working for me.

`provider "aws" { region = var.region }

provider "awscc" { region = var.region }

provider "awscc" { region = var.region alias = "modeling" assume_role = { role_arn = "Destination assumed role ARN" } }

terraform { required_version = ">= 0.15"

required_providers { aws = { source = "hashicorp/aws" version = ">= 4.9.0" } awscc = { source = "hashicorp/awscc" version = ">= 0.55.0" } }

backend "s3" {

} }

resource "awscc_databrew_job" "databrew" { name = "brewjob" role_arn = aws_iam_role.databrew_role[0].arn type = "PROFILE" provider = awscc.modeling }

data "aws_iam_policy_document" "databrew_assume_role_document" { version = "2012-10-17" statement { effect = "Allow" principals { type = "Service" identifiers = ["databrew.amazonaws.com"] } actions = [ "sts:AssumeRole" ] } }

resource "aws_iam_role" "databrew_role" { name = "testrole" assume_role_policy = data.aws_iam_policy_document.databrew_assume_role_document.json }

resource "aws_iam_role_policy" "databrew_role_policy" { name = "testpolicy" role = aws_iam_role.databrew_role.id policy = data.aws_iam_policy_document.databrew_policy.json }

data "aws_iam_policy_document" "databrew_policy" { version = "2012-10-17" statement { sid = "ToUseCloudWatchLogs" effect = "Allow" actions = [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ] resources = ["*"] ] } }`