스터디/AEWS

[AEWS] 7주차 Terraform

안녕유지 2025. 3. 29. 17:43
Cloudnet AEWS 7주차 스터디를 진행하며 정리한 글입니다.

 

이번 포스팅에서는 대표적인 IaC 도구인 Terraform에 대해 알아보겠습니다.

(조금 더 구체적으로 포스팅을 수정할 계획에 있습니다.)

 

Terraform

Terraform은 HashiCorp에서 만든 오픈소스 Infrastructure as Code(IaC) 도구입니다.  
클라우드 인프라를 코드로 정의하고, 생성, 변경, 삭제 등 작업이 가능합니다.

 

  • 선언적 문법 사용 (HCL)
  • AWS, GCP, Azure, K8s 등 멀티 클라우드 지원
  • 상태 기반 변경 추적 (State 파일)
  • 반복 실행 가능, 협업 가능

 

Terraform 주요 개념

  • Provider : 어떤 클라우드를 사용할지 지정
  • Resource : 생성할 리소스 정의 (ex, EC2, S3)
  • State : 인프라 상태 추적하는 파일

 

Terraform 설치

❯ terraform init                                                          
zsh: command not found: terraform

❯ brew install tfenv                                                      
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Auto-updated Homebrew!
Updated 4 taps (homebrew/services, aws/tap, homebrew/core and homebrew/cask).
==> New Formulae
adaptivecpp                        grafana-alloy                      node-red
alloy                              gtree                              projectable
anyquery                           gut                                protobuf@29
cargo-spellcheck                   icu4c@77                           ra-multiplex
decompose                          jaguar                             rasterio
dockcheck                          keyutils                           shuttle
excalidraw-converter               krep                               terraform-iam-policy-validator
fiona                              libgoa                             umockdev
git-graph                          libgudev                           zlib-rs
git-who                            lume
gnome-online-accounts              nmstatectl
==> New Casks
charles@4                 font-webdings             kate                      qt-design-studio
coterm                    font-winky-rough          mouseless@preview         thelowtechguys-cling
font-playpen-sans-arabic  irpf2025                  nethlink
font-playpen-sans-hebrew  k6-studio                 qobuz-downloader

You have 51 outdated formulae installed.

==> Downloading https://ghcr.io/v2/homebrew/core/tfenv/manifests/3.0.0-1
################################################################################################# 100.0%
==> Fetching dependencies for tfenv: grep
==> Downloading https://ghcr.io/v2/homebrew/core/grep/manifests/3.11-2
################################################################################################# 100.0%
==> Fetching grep
==> Downloading https://ghcr.io/v2/homebrew/core/grep/blobs/sha256:3b671635a7a98ec6a5fd2f1ed1f7b61274fe6
################################################################################################# 100.0%
==> Fetching tfenv
==> Downloading https://ghcr.io/v2/homebrew/core/tfenv/blobs/sha256:c66a9c7c90b14b63c471b56405ec064b0814
################################################################################################# 100.0%
==> Installing dependencies for tfenv: grep
==> Installing tfenv dependency: grep
==> Downloading https://ghcr.io/v2/homebrew/core/grep/manifests/3.11-2
Already downloaded: /Users/yoo/Library/Caches/Homebrew/downloads/ad81f65102ec61a6dacd2d8927cd680d905e10addb8c5e955ffd454b1910d8e0--grep-3.11-2.bottle_manifest.json
==> Pouring grep--3.11.arm64_ventura.bottle.2.tar.gz
🍺  /opt/homebrew/Cellar/grep/3.11: 18 files, 1MB
==> Installing tfenv
==> Pouring tfenv--3.0.0.all.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/tfenv/3.0.0: 29 files, 103.6KB
==> Running `brew cleanup tfenv`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).


❯ tfenv list-remote                                                   17s 21:04:50
1.12.0-alpha20250312
1.12.0-alpha20250213
1.11.2
1.11.1
1.11.0
1.11.0-rc3
1.11.0-rc2
1.11.0-rc1
1.11.0-beta2
1.11.0-beta1
1.11.0-alpha20250107
1.11.0-alpha20241218
1.11.0-alpha20241211
1.11.0-alpha20241106
1.10.5
1.10.4
1.10.3
1.10.2
1.10.1
1.10.0
1.10.0-rc3
1.10.0-rc2
1.10.0-rc1
1.10.0-beta1
1.10.0-alpha20241023
1.10.0-alpha20241009
...

❯ tfenv install 1.5.6                                                     21:06:05
Installing Terraform v1.5.6
Downloading release tarball from https://releases.hashicorp.com/terraform/1.5.6/terraform_1.5.6_darwin_arm64.zip
################################################################################################# 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.5.6/terraform_1.5.6_SHA256SUMS
Not instructed to use Local PGP (/opt/homebrew/Cellar/tfenv/3.0.0/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /var/folders/jp/xkc710_x3ljb4bx2vg5gy6r40000gn/T/tfenv_download.XXXXXX.TpA316RU/terraform_1.5.6_darwin_arm64.zip
  inflating: /opt/homebrew/Cellar/tfenv/3.0.0/versions/1.5.6/terraform
Installation of terraform v1.5.6 successful. To make this your default version, run 'tfenv use 1.5.6'

❯ tfenv list                                                              21:06:23
  1.5.6
No default set. Set with 'tfenv use <version>'

❯ tfenv use 1.5.6                                                         21:06:37
Switching default version to v1.5.6
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.5.6

❯ tfenv list                                                              21:06:38

* 1.5.6 (set by /opt/homebrew/Cellar/tfenv/3.0.0/version)

 ❯ terraform version                                                       21:06:58

Terraform v1.5.6
on darwin_arm64

Your version of Terraform is out of date! The latest version
is 1.11.2. You can update by downloading from https://www.terraform.io/downloads.html