brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Dec 13. 2022

19탄-29. 테라폼-AWS-오가니 제이션, 어슘롤

다음은 주말 CloudNet 테라폼 스터디 내용 참고하여  정리한 부분입니다.

https://gasidaseo.notion.site/gasidaseo/CloudNet-Blog-c9dfa44a27ff431dafdd2edacc8a1863


<1> 오가니 제이션 설정하자 - 콘솔로 설정

<2> 어슘롤 설정하기 - 테라폼으로 설정



<1> 오가니 제이션 설정하자 - 콘솔로 설정


0

사전 준비

크롬브라우저 확장 프로그램.

aws 멀티 로그인 가능 플러그인

https://chrome.google.com/webstore/detail/multilogin/ijfgglilaeakmoilplpcjcgjaoleopfi/related


1

메일 계정 2개를 준비하고 , AWS 에 신규 가입하자. 2번 가입.

 Account ID  2개가 만들어 진다.


2

중앙관리를 위해 오가니제이션을 설정한다.

payer 계정 만들기

sub 계정 초대하기

sub계정에서 수락하기

https://brunch.co.kr/@topasvga/756


3

내정보 확인

aws sts get-caller-identity --query Account --output text


4

root 계정을 사용하지 않고, 반드시  iam 계정을 각각 만들어 사용해야 한다.


sub 계정에서 role 하나 만든다.

seo-admin-role


ec2 > admin

arn:aws:iam::4xxxx083:role/seo-admin-role


https://brunch.co.kr/@topasvga/1877





<2> 어슘롤 설정하기 - 테라폼으로 설정



1

# 이동

cd ~/terraform-up-and-running-code/code/terraform/07-working-with-multiple-providers/examples/multi-account-root

cat main.tf 

cat variables.tf


[ec2-user@ip-172-31-61-209 multi-account-root]$ cat main.tf

terraform {

  required_version = ">= 1.0.0, < 2.0.0"

  required_providers {

    aws = {

      source  = "hashicorp/aws"

      version = "~> 4.0"

    }

  }

}

provider "aws" {

  region = "us-east-2"

  alias  = "parent"

}

provider "aws" {

  region = "us-east-2"

  alias  = "child"

  assume_role {

    role_arn = var.child_iam_role_arn

  }

}

data "aws_caller_identity" "parent" {

  provider = aws.parent

}

data "aws_caller_identity" "child" {

  provider = aws.child

}




[ec2-user@ip-172-31-61-209 multi-account-root]$ cat variables.tf

# ---------------------------------------------------------------------------------------------------------------------

# REQUIRED PARAMETERS

# You must provide a value for each of these parameters.

# ---------------------------------------------------------------------------------------------------------------------

variable "child_iam_role_arn" {

  description = "The ARN of an IAM role to assume in the child AWS account"

  type        = string

}[ec2-user@ip-172-31-61-209 multi-account-root]$ 




2

# IAM Role ARN 지정

#export TF_VAR_child_iam_role_arn='arn:aws:iam::<자신의 두번째 계정 Account ID>:role/<해당 계정의 IAM Role 이름>'

export TF_VAR_child_iam_role_arn='arn:aws:iam::47xxxxxxxxxxxxxx:role/seo-admin-role'



3

# 배포 확인

terraform init

terraform plan && terraform apply -auto-approve


Outputs:

child_account_id = "476286675138"

parent_account_id = "451032684083"





https://brunch.co.kr/@topasvga/2421


매거진의 이전글 19탄-28.테라폼-aws-멀티 프로바이더

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari