티스토리 뷰

테라폼을 이용하여 클라우드 인프라를 코드로 어떻게 작성하고 관리할 수 있는지 간단한 예제 작성 및 실행방법을 정리하였다.
아래 github 소스를 클론하여 진행하면 파일작성 없이 바로 테스트 진행이 가능하다.

https://github.com/rocksea/terraform-tutorial

 

GitHub - rocksea/terraform-tutorial

Contribute to rocksea/terraform-tutorial development by creating an account on GitHub.

github.com

 

Commands


명렁은 총 세가지 단계로 구성되어있으며 매우 단순하다.f파일 작성 후 초기화를 하고 실행계획을 돌리고 적용하는 단계를 거친다.
apply를 하게되면 terraform.tfstate파일이 생기는데 이 파일이 있어야 변경사항에 대한 적용이 가능하니 지우지 않도록한다.

#The commands are divided into three steps.

$ terraform init

$ terraform plan

$ terraform apply

 

Workspace


workspace를 통해 environment를 관리할 수 있다. 

$ terraform workspace new dev

$ terraform workspace show
  dev

$ terraform workspace list
  default
* dev
  stage
  prod
  
$ terraform workspace select prod
 
$ terraform workspace show
  prod
Workspace를 이용하면 환경변수를 통해 각 환경별 상태를 코드를 작성 할 수 있다.
예) autoscale_min = terraform.workspace == "dev" ? 1 : 2

 

Result


작성한 코드를 실행하여 AWS 클라우드환경에 프로비저닝된 결과를 확인.

'Developer' 카테고리의 다른 글

아마존웹서비시즈코리아 Inverview 후기  (7) 2021.10.01
퇴사 회고록  (0) 2021.09.15
ElastiCache with SpringData  (0) 2021.05.21
MongoDB with SpringData  (0) 2021.01.08
[OpenJDK] How to install OpenJDK  (0) 2020.10.20
댓글