brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Nov 15. 2022

19탄-20. 테라폼-AWS-조건문으로 S3 버킷

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

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


<1> createBucket가 true이면   NICKNAME에 해당 하는 버킷을 만든다.

<2> createBucket가 false 면  버킷을 만들지 않는다.



<1> createBucket가 true이면   NICKNAME에 해당 하는 버킷을 만든다.


1

terraform destroy -auto-approve

rm -rf *


2

NICKNAME=masterseo


cat <<EOT > variables.tf

variable "createBucket" {

  type = bool

  default = true

}

EOT


cat <<EOT > s3.tf

provider "aws" {

  region = "ap-northeast-2"

}

resource "aws_s3_bucket" "this" {

  count = var.createBucket? 1 : 0

  bucket = "$NICKNAME-bucket"

}

EOT


terraform init && terraform plan  && terraform apply -auto-approve


aws s3 ls


버킷이 만들어진다






<2> createBucket가 false 면  버킷을 만들지 않는다.


NICKNAME=masterseo


cat <<EOT > variables.tf

variable "createBucket" {

  type = bool

  default = false

}

EOT

cat <<EOT > s3.tf

provider "aws" {

  region = "ap-northeast-2"

}

resource "aws_s3_bucket" "this" {

  count = var.createBucket? 1 : 0

  bucket = "$NICKNAME-bucket"

}

EOT



terraform init && terraform plan  && terraform apply -auto-approve

aws s3 ls


안만들어진다.




다음

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





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

감사합니다.

                    

keyword
매거진의 이전글 19탄-19. 테라폼-AWS-반복문으로 s3 

작품 선택

키워드 선택 0 / 3 0

댓글여부

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