Terraform Iam생성

임종혁·2024년 10월 28일

Iam 계정 생성하기

1. aws cli 다운로드

https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/getting-started-install.html

2. 있는 IAM 계정 등록

set AWS_PROFILE=
aws configure # 계정등록

3. Terraform 을 통한 Iam 계정 등록

provider "aws" {
  region = "ap-northeast-2"
}

resource "aws_iam_user" "devloper1" {
  name = "devloper1"
  path = "/system/"
}

provider

provider "aws" {
  region = "ap-northeast-2"
}

aws 이용 및 리젼 서울로

user 생성

resource "aws_iam_user" "devloper1" {
  name = "devloper1"
  path = "/system/"
}

path는 네임 스페이스 역할
/system/ 경로는 시스템 관련 리소스를 그룹화하는 데 사용할 수 있습니다.


4. 생성 유저에 정책 추가

resource "aws_iam_policy" "policy" {
  name        = "test_policy"
  path        = "/system/"
  description = "My test policy"

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "iam:*"
        ]
        Effect   = "Allow"
        Resource = "*"
      },
    ]
  })
}

resource "aws_iam_user_policy_attachment" "developer1_policy_attachment" {
    user = aws_iam_user.devloper1.name
    policy_arn = aws_iam_policy.policy.arn
}

정책 생성

resource "aws_iam_policy" "policy" {
  name        = "test_policy"
  path        = "/system/"
  description = "My test policy"

  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [
      {
        Action = [
          "iam:*"
        ]
        Effect   = "Allow"
        Resource = "*"
      },
    ]
  })
}

"iam:" iam 관련 모든 api 정책 수용
Effect = "Allow" 허용한다
Resource = "
" 모든 iam 리소스에 대해

5. 리소스 유저 권한 주기

   user = aws_iam_user.devloper1.name
   policy_arn = aws_iam_policy.policy.arn
}

0개의 댓글