Nubes et Stella

Terraform #01 본문

DevOps/Terraform

Terraform #01

SeongYeong Han 2023. 9. 25. 00:39

01. Terraform이란?

하시코프사에서 오픈소스로 개발한 대표적인 IaC 도구이다. 테라폼을 사용하면 여러 클라우드환경(AWS, Azure, GCP)에서 코드로 인프라 및 리소스를 관리할 수 있다.

링크 : https://www.terraform.io/

 

**IaC(Infrastructure as Code)란?

코드형 인프라를 뜻하는 단어로서, 기존 물리적 인프라 구성 방식을 탈피하여 코드로 간편하게 클라우드, 가상화, 컨테이너 환경을 프로비저닝 하는 것을 뜻한다. IaC의 대표적인 툴은 아래와 같다.

  • Chef
  • Puppet
  • Red Hat Ansible Automation Platform
  • Saltstack
  • Terraform 
  • AWS CloudFormation

 

 

02. Terraform 동작

Terraform은 크게 "Write", "Init", "Plan", "Apply" & "Destroy"로 구성된다.

 

1. Write : Terraform은 코드가 Yaml 형태와 비슷하게 "Key"와 "Value"로 구성되어 진다.

 

2. Init : 초기화단계이다. 이전 단계인 "Write"에서 모듈이 수정되거나 추가 되었을 때 필요한 단계이다. 본 단계에서 필요한 모듈, 플러그인을 추가하게 된다.

 

3. Plan : 코드를 정식배포하기 전 "계획 실행"하는 단계이다. 이 단계에서 코드의 수정, 추가, 삭제된 내역을 사전에 확인이 가능하다. (Plan 단계를 스킵하고 바로 Apply 할 수도 있다.)

 

4. Apply : 작성된 코드를 최종 실행하여, 실제 인프라를 생성하는 단계이다.

 

5. Destroy : Terraform으로 생성한 인프라를 완전삭제 하는 단계이다. (코드는 그대로 존재)

 

 

03. Terraform 워크스페이스

워크스페이스는 하나의 프로젝트 단위이다. 워크스페이스는 상태단위로 관리가 된다.

 

 

04. Terraform 설치

나는 Windows상에서 WSL로 만든 Ubuntu 환경에서 Terraform을 운영하고자 한다. Terraform 설치는 명령어 몇 가지로 간단하게 할 수 있으며, 해당 명령어는 아래의 링크에서 확인 가능하다.

 

설치 가이드 링크 : https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli

 

Install Terraform | Terraform | HashiCorp Developer

Install Terraform on Mac, Linux, or Windows by downloading the binary or using a package manager (Homebrew or Chocolatey). Then create a Docker container locally by following a quick-start tutorial to check that Terraform installed correctly.

developer.hashicorp.com

 

**  plugin_cache_dir 설정

해당 설정을 통해 필요한 각종 모듈이나 플러그인들을 중앙집중식으로 관리하여, PC의 리소스를 줄일 수 있다. 

cd ~
vi .terraformrc

.terraformrc 파일에 아래 내용 기입 및 저장

plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"

mkdir -p ~/.terraform.d/plugin-cache

 

상세 링크 : https://developer.hashicorp.com/terraform/cli/config/config-file

 

CLI Configuration | Terraform | HashiCorp Developer

Learn to use the CLI configuration file to customize your CLI settings, including credentials, plugin caching, provider installation methods, etc.

developer.hashicorp.com

 

- END -

'DevOps > Terraform' 카테고리의 다른 글

Terraform #06 (Conditional/For)  (0) 2023.10.19
Terraform #05 (count/for_each)  (1) 2023.10.18
Terraform #04 (Variable/Output/Local)  (1) 2023.10.09
Terraform #03  (0) 2023.09.27
Terraform #02  (0) 2023.09.26