Skip to content

๐Ÿ’ก How To? Terraform Locust๋กœ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ ์ง„ํ–‰ํ•˜๊ธฐ

Kim Minju edited this page Sep 1, 2024 · 13 revisions

Terraform์„ ๋” ์ž˜ ์“ฐ๋Š” ๋ฐฉ๋ฒ•๋ณด๋‹ค๋Š”, ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ๊ตฌ์ถ•์˜ ๋ถˆํŽธํ•จ์„ ํ•ด๊ฒฐํ•˜๋ ค๋Š” ์ˆ˜๋‹จ์œผ๋กœ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค~

Terraform ๊ฐœ๋ฐœ ํ™˜๊ฒฝ ์„ธํŒ…

์„ค์น˜

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

์„ค์น˜ ํ™•์ธ

terraform version

autocomplete ์„ธํŒ…

terraform -install-autocomplete

๊ฐ„๋‹จ ์˜ˆ์ œ

main.tf

provider "aws" {
  region = "ap-northeast-2"  # ๋ฆฌ์ „์„ ap-northeast-2๋กœ ์„ค์ •
}

resource "aws_instance" "terrafor-example-miiiinju" {
  ami                    = "ami-056a29f2eddc40520"  # ์ง€์ •๋œ AMI ID
  instance_type          = "t3.micro"  # ์ง€์ •๋œ ์ธ์Šคํ„ด์Šค ํƒ€์ž…
  key_name               = "team5_guys_pub"  # ์ง€์ •๋œ ํ‚ค ํŽ˜์–ด ์ด๋ฆ„
  subnet_id              = "subnet-ac32f2f3"  # default subnet
  vpc_security_group_ids = ["sg-0946e533330930594"]  # ์‚ฌ์šฉํ•  ๋ณด์•ˆ ๊ทธ๋ฃน์˜ ID

  tags = {
    Name = "miiiinju-terraform"
  }

  root_block_device {
    delete_on_termination = true  # ์ธ์Šคํ„ด์Šค ์ข…๋ฃŒ ์‹œ EBS ๋ณผ๋ฅจ ์‚ญ์ œ
  }

  credit_specification {
    cpu_credits = "standard"
  }

  enable_monitoring = false
}

๋””๋ ‰ํ„ฐ๋ฆฌ ์ดˆ๊ธฐํ™”

terraform init

Terraform ์‹คํ–‰ ๊ณ„ํš ํ™•์ธ

terraform plan

์‹คํ–‰

terraform apply

Terraform + Locust๋กœ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ ์ง„ํ–‰ํ•˜๊ธฐ

์ปค์Šคํ…€ AMI ๋งŒ๋“ค์–ด์•ผํ•˜๋Š” ์ด์œ 

  • ํ•ญ์ƒ EC2๋ฅผ ์ผœ๋‘” ์ƒํƒœ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ, ํ•„์š”ํ•  ๋•Œ ์ž ๊น terraform์œผ๋กœ ์ธ์Šคํ„ด์Šค๋ฅผ ์ผœ์„œ ๋ถ€ํ•˜ ํ…Œ์ŠคํŠธ๋ฅผ ์ˆ˜ํ–‰ํ•œ ์ดํ›„, ์ข…๋ฃŒํ•˜๋Š” ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ EC2๋ฅผ ๋งค๋ฒˆ ์ผœ์„œ ํ™˜๊ฒฝ ์„ค์ •์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ์—๋Š” ์‹œ๊ฐ„ ๋ถ€๋‹ด์ด ํฌ๋ฏ€๋กœ, ๋ฏธ๋ฆฌ ์„ธํŒ…ํ•ด์„œ ์ปค์Šคํ…€ AMI๋ฅผ ๋งŒ๋“ค์–ด๋‘” ๋’ค ์ด๋ฅผ ํ†ตํ•ด EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์„ธํŒ… ์™„๋ฃŒํ•˜๊ธฐ

  • EC2๋ฅผ ๊ธฐ๋ณธ ubuntu ์ด๋ฏธ์ง€๋ฅผ ํ†ตํ•ด ์ง์ ‘ ๋งŒ๋“  ํ›„, Locust ๊ตฌ๋™์— ํ•„์š”ํ•œ python, locust ์„ค์น˜ ๋“ฑ์˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ–ˆ์Šต๋‹ˆ๋‹ค.

aws-cli๋กœ ami๋งŒ๋“ค๊ธฐ

aws ec2 create-image \
    --instance-id {์ธ์Šคํ„ด์Šค-ID} \
    --name "locust-ami" \
    --no-reboot

๐Ÿงซ ํŒ€ ๋ฌธํ™”

โš™๏ธ ๊ตฌ์„ฑ

๐Ÿ”จ ๊ฐœ๋ฐœ ์œ„ํ‚ค

๐Ÿž Bug Report

๐Ÿงช Test Logs

Clone this wiki locally