aws-samples / service-catalog-engine-for-terraform-os

Apache License 2.0
127 stars 40 forks source link

Products aren't being launched in the right AWS Account #82

Open JhonathanOrtiz opened 3 months ago

JhonathanOrtiz commented 3 months ago

Hi team,

I've been carefully following the guide to deploy external products from aws

https://docs.aws.amazon.com/servicecatalog/latest/adminguide/getstarted-Terraform.html

Issue description

I'm trying to deploy cross account and I followed this steps.

The launching process is running as expected, but the product is being deployed in the administrator account and I'd expect the product to be in the end user account.

Launch Role

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "s3:GetObject",
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "s3:ExistingObjectTag/servicecatalog:provisioning": "true"
                }
            }
        },
        {
            "Action": [
                "s3:CreateBucket*",
                "s3:DeleteBucket*",
                "s3:Get*",
                "s3:List*",
                "s3:PutBucketTagging"
            ],
            "Resource": "arn:aws:s3:::*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "resource-groups:CreateGroup",
                "resource-groups:ListGroupResources",
                "resource-groups:DeleteGroup",
                "resource-groups:Tag"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "tag:GetResources",
                "tag:GetTagKeys",
                "tag:GetTagValues",
                "tag:TagResources",
                "tag:UntagResources"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "GivePermissionsToServiceCatalog",
            "Effect": "Allow",
            "Principal": {
                "Service": "servicecatalog.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::account_id:root"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "StringLike": {
                    "aws:PrincipalArn": [
                        "arn:aws:iam::accounti_id:role/TerraformEngine/TerraformExecutionRole*",
                        "arn:aws:iam::accounti_id:role/TerraformEngine/ServiceCatalogExternalParameterParserRole*",
                        "arn:aws:iam::accounti_id:role/TerraformEngine/ServiceCatalogTerraformOSParameterParserRole*"
                    ]
                }
            }
        }
    ]
}
variable "bucket_name" {
  type = string
}
provider "aws" {
}
resource "aws_s3_bucket" "bucket" {
  bucket = var.bucket_name
}
output regional_domain_name {
  value = aws_s3_bucket.bucket.bucket_regional_domain_name
}

Notes:

smaly-amazon commented 3 months ago

In general (not specific to external products), you can check a couple things.

  1. Is the launch role constraint using LocalRoleName? This is needed for provisioning in share-recipient accounts. If you use RoleArn, then the arn is fixed to the product owning account regardless of which share-recipient account is calling ProvisionProduct, so you don't want RoleArn unless you are provisioning to the account for that arn.
  2. Are you calling ProvisionProduct from the share-recipient account where you expect the resources to be provisioned? That's pretty obvious, but I thought I would check because we all make little mistakes sometimes.
JhonathanOrtiz commented 3 months ago

@smaly-amazon Thanks a lot for your answer.

For #1 and using the option Select IAM role asn shown in the image

Screenshot 2024-03-22 at 12 36 14

For #2 I'm running Lanunch Product in the target account.

According to your answer I think I should select Role Name Option. right?

jyjohnson commented 2 months ago

using the 'enter role name' (aka local role name) worked for me. also make sure the trust policy in the SCLaunch- role(s) uses the management acct ID