38. Terraform을 사용한 사용자 변수 설정

발행: (2026년 2월 2일 오후 06:30 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

실습 정보

Nautilus DevOps 팀은 더 나은 ID 관리를 위해 Terraform을 사용하여 IAM 사용자 생성을 자동화하고 있습니다.
다음 요구 사항에 따라 AWS IAM 사용자를 생성합니다:

  • IAM 사용자 이름 iamuser_markKKE_user라는 변수에 저장되어야 합니다.
  • 구성 값은 variables.tf 파일에 저장되어야 합니다.
  • Terraform 스크립트는 variables.tf를 참조하는 main.tf 파일로 구성되어야 합니다.
  • 작업 디렉터리: /home/bob/terraform.

variables.tf

# Define variable for IAM user name
variable "KKE_user" {
  description = "The name of the IAM user to create"
  type        = string
  default     = "iamuser_mark"
}

main.tf

# Create AWS IAM User with variable reference
resource "aws_iam_user" "this" {
  name = var.KKE_user

  tags = {
    Name = var.KKE_user
  }
}

Terraform 명령어

cd /home/bob/terraform
terraform init

출력 (발췌):

Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/aws versions matching "5.91.0"...
- Installing hashicorp/aws v5.91.0...
- Installed hashicorp/aws v5.91.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider selections.
Terraform has been successfully initialized!
terraform plan

출력 (발췌):

Terraform used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
  + create

# aws_iam_user.this will be created
+ resource "aws_iam_user" "this" {
    + arn           = (known after apply)
    + force_destroy = false
    + id            = (known after apply)
    + name          = "iamuser_mark"
    + path          = "/"
    + tags          = {
        + "Name" = "iamuser_mark"
      }
    + tags_all      = {
        + "Name" = "iamuser_mark"
      }
    + unique_id     = (known after apply)
  }

Plan: 1 to add, 0 to change, 0 to destroy.
terraform apply

프롬프트가 표시되면 yes를 입력하여 확인합니다.

출력 (발췌):

aws_iam_user.this: Creating...
aws_iam_user.this: Creation complete after 0s [id=iamuser_mark]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Back to Blog

관련 글

더 보기 »

34. Terraform을 사용하여 S3에 데이터 복사

Lab Information 나우틸러스 DevOps 팀은 현재 데이터 마이그레이션을 수행하고 있으며, 온프레미스 스토리지 시스템에서 AWS S3 버킷으로 데이터를 이동하고 있습니다. They have rece...