https://gasidaseo.notion.site/gasidaseo/CloudNet-Blog-c9dfa44a27ff431dafdd2edacc8a1863
테스트 버킷을 여러가 만들어야 할떄~~
NICKNAME=masterseo
cat <<EOT > s3.tf
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_s3_bucket" "mybucket" {
count = 3
bucket = "$NICKNAME.\${count.index}"
}
EOT
terraform init && terraform plan && terraform apply -auto-approve
aws_s3_bucket.mybucket[0]: Creation complete after 3s [id=masterseo.0]
aws_s3_bucket.mybucket[1]: Creation complete after 4s [id=masterseo.1]
aws_s3_bucket.mybucket[2]: Creation complete after 4s [id=masterseo.2]
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
[root@ip-172-31-61-209 test]#
terraform destroy -auto-approve
rm -rf *
참고
https://developer.hashicorp.com/terraform/language/meta-arguments/count
지정된 이름으로 버킷을 여러개 만들어야 할때 ~~
버킷 3개 생성
cat <<EOT > variables.tf
variable "bucket_names" {
description = "Create s3"
type = list(string)
default = ["seo111", "tae1112", "ho111"]
}
EOT
cat <<EOT > s3.tf
provider "aws" {
region = "ap-northeast-2"
}
resource "aws_s3_bucket" "mybucket" {
count = length(var.bucket_names)
bucket = var.bucket_names[count.index]
}
EOT
terraform init && terraform plan && terraform apply -auto-approve
aws s3 ls
2022-11-15 07:23:15 ho111
2022-11-15 07:23:15 seo111
2022-11-15 07:23:16 tae111
3
terraform destroy -auto-approve
rm -rf *
다음
https://brunch.co.kr/@topasvga/2813
https://brunch.co.kr/@topasvga/2421
감사합니다.