Execute Terraform apply with AWS assume role

后端 未结 4 1958
夕颜
夕颜 2021-02-02 01:11

I need to execute a Terraform template to provision infrastructure for an AWS account which I can access by assuming a role.

The problem I have now is I do not have an I

4条回答
  •  野的像风
    2021-02-02 01:36

    You should be able to do it like this: In Terraform configure the aws provider to use your local shared_credentials_file

    provider "aws" {
      region                  = "us-east-1"
      shared_credentials_file = "${pathexpand("~/.aws/credentials")}"
      profile                 = "default"
    
      assume_role {
        role_arn = "arn:aws:iam::1234567890:role/OrganizationAccountAccessRole"
      }
    }
    

    "profile" is a named profile in ~/.aws/credentials that has AWS Access keys. E.g.

    [default]
    region = us-east-1
    aws_access_key_id = AKIAJXXXXXXXXXXXX
    aws_secret_access_key = Aadxxxxxxxxxxxxxxxxxxxxxxxxxxxx    
    

    This is not an IAM user in the account you want to access. It's in the "source" account (you need keys at some point to access the AWS cli).

    "assume_role.role_arn" is the role in the account you want to assume. The IAM user in "profile" needs to be allowed to assume that role.

提交回复
热议问题