//
Search
Duplicate
😁

Terraform

IaC와 Terraform

μ½”λ“œν˜• 인프라 Infrastructure as code (IaC)λŠ” 영문 κ·ΈλŒ€λ‘œ β€˜μ½”λ“œλ‘œμ„œμ˜ 인프라’ 의미λ₯Ό 가지고 μžˆμŠ΅λ‹ˆλ‹€.
μ½˜μ†”μ—μ„œ UIλ₯Ό 톡해 μ‘°μž‘ν•˜λŠ”κ²ƒμ΄ μ•„λ‹Œ μ½”λ“œλ‘œ λŒ€μƒμ„ κ΄€λ¦¬ν•©λ‹ˆλ‹€.

인프라 μžλ™ν™”μ™€ μ„±μˆ™λ„

1.
맀뉴얼 - 인프라 κ΄€λ ¨ λͺ¨λ“  정보와 ꡬ성 ,λ³€κ²½, κΈ°μ‘΄ μ•„ν‚€ν…μ²˜μ— λŒ€ν•œ λͺ¨λ“  λ‚΄μš©μ„ λ¬Έμ„œλ‘œ 관리 - ν˜„μž¬λ„ μ—‘μ…€ μ‹œνŠΈλ₯Ό μ΄μš©ν•΄μ„œ IP, ID, Service등에 λŒ€ν•΄ κ΄€λ¦¬ν•˜λŠ” κ³³ 쑴재 - μ¦‰μ‹œ 확인 κ°€λŠ₯ν•˜μ§€λ§Œ μ‹€μ œ μž‘μ—…μ„ μœ„ν•œ λͺ…령어와 ꡬ성 νŒŒμΌμ€ λ³„λ„λ‘œ μ€€λΉ„
2.
슀크립트 - λ°˜λ³΅λ˜λŠ” μž‘μ—…μ€ μž‘μ—…μžκ°€ 슀크립트둜 μž‘μ„±ν•˜κ³  κ²½ν—˜μ μΈ λ…Έν•˜μš°λ₯Ό 톡해 슀크립트λ₯Ό μž‘μ„± - ν•œ 번 잘 λ§Œλ“€λ©΄ νŽΈν•¨ - μ½”λ“œ 양이 λ§Žμ•„μ§€λ©΄ 고렀사항이 λ§Žμ•„μ§
3.
가상 λ¨Έμ‹ (VM) - 가상화 μ†”λ£¨μ…˜μ„ 톡해 이미지 ν…œν”Œλ¦Ών™” κ°€λŠ₯해짐 - ν•„μš”ν•œ νŒ¨ν‚€μ§€μ™€ μ†”λ£¨μ…˜μ„ 미리 μ„€μΉ˜ν•˜μ—¬ 반볡적으둜 ν™œμš© κ°€λŠ₯
4.
ν΄λΌμš°λ“œ 인프라 - ν΄λΌμš°λ“œ λ¦¬μ†ŒμŠ€λ₯Ό μ›κ²©μœΌλ‘œ 관리할 수 있음 - λΉ λ₯Έ 인프라 μ‹œμž‘κ³Ό ꡬ성이 κ°€λŠ₯ν•˜κ³  ν™•μž₯성이 뛰어남
5.
μ»¨ν…Œμ΄λ„ˆ - 운영체제λ₯Ό κ°€μƒν™”ν•œ ν™˜κ²½μ„ μ œκ³΅ν•˜κΈ° λ•Œλ¬Έμ— λΉ λ₯Έ μ„œλΉ„μŠ€ κ°œλ°œμ„ ν•  수 있음 - 데브옡슀 흐름에 λ§žμΆ°μ„œ λΉ λ₯΄κ²Œ μ„±μž₯ - μ»¨ν…Œμ΄λ„ˆ 관리와 배포λ₯Ό μœ„ν•œ μ œμ–΄ μ‹œμŠ€ν…œμ„ κ΅¬μΆ•ν•˜κ³  λͺ¨λ‹ˆν„°λ§μ— μŸλŠ” λ…Έλ ₯이 μƒλ‹€μ μœΌλ‘œ 컀지고 있음 - μ „λ¬Έ 인λ ₯이 기술 κΈ°λ°˜μ— λΉ„ν•΄ λΆ€μ‘±

IaC의 이해

μ½”λ“œλ₯Ό 톡해 인프라λ₯Ό κ΄€λ¦¬ν•œλ‹€λŠ” 것은 μ‰½κ²Œ λ³€κ²½ν•˜κ³  ν™˜κ²½μ„ 이해 그리고 반볡적으둜 λ™μΌν•œ μƒνƒœλ₯Ό λ§Œλ“€ 수 μžˆλ‹€λŠ” λ§μž…λ‹ˆλ‹€.
1.
쒋은 μ½”λ“œμ˜ νŠΉμ§• - μ •μƒμ μœΌλ‘œ λ™μž‘ - 읽기 쉬움 - λͺ¨λ“ˆν™”됨 - ν…ŒμŠ€νŠΈκ°€ κ°€λŠ₯함 - μš°μ•„ν•¨ - 관리가 쉬움 - 변경이 쉬움 - κ°„κ²° - 효율

IaC λ„μž…μ˜ 긍정적인 μΈ‘λ©΄

β€’
속도와 νš¨μœ¨μ„± - μˆ˜λ™μœΌλ‘œ μž‘μ—…μ—…ν•  λ•Œλ³΄λ‹€ μ‹ μ†ν•˜κ³  λΆˆν•„μš”ν•œ 인프라 ꡬ성 방지 - μ½”λ“œλ₯Ό λ³€κ²½ν•˜μ—¬ μ μš©ν•˜λ©΄ 인프라도 λ³€κ²½ν•˜μ—¬ κΈ°μ‘΄ 방식보닀 λ³€κ²½ 속도가 빠름
β€’
버전 관리 - μ½”λ“œ ν˜•νƒœλ‘œ κ΄€λ¦¬ν•˜κΈ° λ•Œλ¬Έμ— VCS 툴과 연계 κ°€λŠ₯ - λ³€κ²½ λ‚΄μš©μ„ μΆ”μ ν•˜κ³  이전 μ½”λ“œλ‘œ λ‘€λ°±ν•˜κ±°λ‚˜ 비ꡐ κ°€λŠ₯
β€’
ν˜‘μ—… - 파일 ν˜•νƒœλ‘œ λ˜μ–΄ μžˆμ–΄ μ‰¬μš΄ 곡유 κ°€λŠ₯ν•˜κ³  곡동 μž‘μ—…μ„ μœ„ν•œ ν™˜κ²½ ꡬ좕 κ°€λŠ₯
β€’
μž¬μ‚¬μš©μ„± - μ£Όμš” μ½”λ“œ 반볡 λ˜λŠ” ν‘œμ€€ν™”λœ ꡬ성을 νŒ¨ν‚€μ§•ν•˜λ©΄ 맀번 μƒˆλ‘œ μ½”λ“œλ₯Ό κ΅¬μ„±ν•˜μ§€ μ•Šκ³  κΈ°μ‘΄ λͺ¨λ“ˆλ‘œ 배포 κ°€λŠ₯

IaC λ„μž…μ˜ μš°λ €λ˜λŠ” μΈ‘λ©΄

β€’
μ½”λ“œ 문법 ν•™μŠ΅ - ν•™μŠ΅ ν•„μš”
β€’
νŒŒμ΄ν”„λΌμΈ 톡합 - κΈ°μ‘΄ μ›Œν¬ν”Œλ‘œμ— μžλ™ν™”λ₯Ό μœ„ν•œ μˆ˜κ³ λ‘œμ›€
β€’
λŒ€μƒ 인프라에 λŒ€ν•œ 이해 ν•„μš” - 관리 λŒ€μƒμ΄ λ˜λŠ” μΈν”„λΌμ˜ 지식이 ν•„μš”

ν…ŒλΌνΌμ˜ νŠΉμ„±

2012λ…„ ν•˜μ‹œμ½”ν”„λ₯Ό μ„€λ¦½ν–ˆκ³  μž‘μ—… ν™˜κ²½μ„ μ‰½κ²Œ 반볡적으둜 ꡬ성할 수 μžˆλŠ” 베이그런트λ₯Ό μ‹œμž‘μœΌλ‘œ 2014λ…„ ν…ŒλΌνΌμ΄ 처음 μΆœμ‹œ 2021λ…„ 1.0 λ²„μ „μ˜ ν…ŒλΌνΌμ„ μΆœμ‹œν–ˆμŠ΅λ‹ˆλ‹€.
ν…ŒλΌνΌμ€ μ„Έ 가지 μ€‘μš”ν•œ μ² ν•™
β€’
μ›Œν¬ν”Œλ‘œμ— 집쀑
β€’
μ½”λ“œν˜• 인프라
β€’
μ‹€μš©μ£Όμ˜

ν…ŒλΌνΌ 제곡 μœ ν˜•

β€’
On-premise - 일반적으둜 Terraform이라 λΆˆλ¦¬λŠ” ν˜•νƒœ - μ‚¬μš©μžμ˜ μ»΄ν“¨νŒ… ν™˜κ²½μ— μ˜€ν”ˆμ†ŒμŠ€ λ°”μ΄λ„ˆλ¦¬ 툴린 ν…ŒλΌνΌμ΄ κ΅¬μ„±λ˜μ–΄ κ°€μž₯ 널리 이용
β€’
Hosted SaaS - Terraform Cloud둜 λΆˆλ¦¬λŠ” μ„œλΉ„μŠ€ν˜• μ†Œν”„νŠΈμ›¨μ–΄λ‘œ μ œκ³΅λ˜λŠ” ꡬ성 ν™˜κ²½μœΌλ‘œ ν•˜μ‹œμ½”ν”„κ°€ κ΄€λ¦¬ν•˜λŠ” μ„œλ²„ ν™˜κ²½μ΄ 제곡
β€’
Private Install - Terraform Enterprise둜 λΆˆλ¦¬λŠ” μ„œλ²„ μ„€μΉ˜ν˜• ꡬ성 ν™˜κ²½μœΌλ‘œ κΈ°μ—…μ˜ 사내 μ •μΉ˜μ— 따라 인터넷/μ™ΈλΆ€ λ„€νŠΈμ›Œν¬ μ‚¬μš©μ΄ λΆˆκ°€λŠ₯ν•œ λ„€νŠΈμ›Œν¬ ν™˜κ²½

ν…ŒλΌνΌ ν™˜κ²½ ꡬ성

β€’
미리 λΉŒλ“œλœ λ°”μ΄λ„ˆλ¦¬ 파일 λ‹€μš΄λ‘œλ“œ https://www.terraform.io/
β€’
ν…ŒλΌνΌ μ†ŒμŠ€ μ½”λ“œλ₯Ό λ‹€μš΄λ‘œλ“œ ν›„ λΉŒλ“œ
β€’
OS νŒ¨ν‚€μ§€ κ΄€λ¦¬μž ν™œμš©

IDE ꡬ성

λŒ€λΆ€λΆ„μ˜ 개발 μ–Έμ–΄κ°€ κ·Έλ ‡λ“― ν…ŒλΌνΌλ„ λ°”μ΄λ„ˆλ¦¬ μ„€μΉ˜ 파일과 λ©”λͺ¨μž₯ 같은 κΈ°λ³Έ ν…μŠ€νŠΈ νŽΈμ§‘κΈ°λ§Œ μžˆμ–΄λ„ μ‹œμž‘ν•  수 μžˆλ‹€. ν•˜μ§€λ§Œ μ½”λ“œ 양이 λ§Žμ•„μ§€κ³  μ—¬λŸ¬ 도ꡬ와 ν•¨κ²Œ μ‚¬μš© κ°€λŠ₯ν•œ ν™˜κ²½μ„ κ΅¬μ„±ν•œλ‹€λ©΄ IDE ν™˜κ²½μ΄ 더 λ‚˜μ€ 개발 ν™˜κ²½μ„ μ œκ³΅ν•©λ‹ˆλ‹€.
VSCode ν™•μž₯ μ•„μ΄μ½˜μ„ λˆŒλŸ¬μ„œ HashiCorp HCL 검색 ν›„ μ„€μΉ˜λ₯Ό ν•˜λ©΄ VSCodeμ—μ„œ ν…ŒλΌνΌμ„ μ‹€ν–‰μ‹œν‚¬ 수 있게 λ©λ‹ˆλ‹€.

μ£Όμš” λͺ…λ Ήμ–΄

ν„°λ―Έν„Έμ—μ„œ terraform λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜λŠ” κ²ƒμœΌλ‘œ κΈ°λ³Έ 도움말을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

1.1 init

terraform init λͺ…령은 ν…ŒλΌνΌ ꡬ성 파일이 μžˆλŠ” 디렉터리λ₯Ό μ΄ˆκΈ°ν™” ν•˜λŠ”λ° μ‚¬μš©ν•©λ‹ˆλ‹€. 이 μž‘μ—…μ„ μ‹€ν–‰ν•˜λŠ” 디렉터리λ₯Ό β€œλ£¨νŠΈ λͺ¨λ“ˆβ€ 이라 λΆ€λ¦…λ‹ˆλ‹€. ν…ŒλΌνΌμ„ 처음 μ‹œμž‘ν•˜λŠ” 데 μ‚¬μš©λ˜λŠ” 첫 번째 λͺ…λ Ήμ–΄λ‘œ ν”„λ‘œλ°”μ΄λ”, λͺ¨λ“ˆ λ“±μ˜ μ§€μ •λœ 버전에 맞좰 루트 λͺ¨λ“ˆμ„ κ΅¬μ„±ν•˜λŠ” 역할을 μˆ˜ν–‰ν•©λ‹ˆλ‹€.
μžλ°”μ˜ pom.xml, Node.js의 package.json, 파이썬의 requirements.txt 처럼 κ΅¬μ„±μ—μ„œ ν•„μš”ν•œ μ˜μ‘΄μ„± μ •μ˜λ₯Ό 읽고 처음 μ‹€ν–‰ν•  λ•Œ 싀행에 ν•„μš”ν•œ μ•„ν‹°νŒ©νŠΈλ‚˜ 라이브러리λ₯Ό λ‹€μš΄λ‘œλ“œν•˜κ³  μ€€λΉ„μ‹œν‚€λŠ” μ—­ν• κ³Ό λΉ„μŠ·ν•©λ‹ˆλ‹€.
ν…ŒλΌνΌ μ½”λ“œμ—μ„œ μ‚¬μš©λœ ꡬ문을 기반으둜 ν•„μš”ν•œ ν”ŒλŸ¬κ·ΈμΈμ„ μ°Ύμ•„μ„œ μ„€μΉ˜ν•˜λŠ” κ³Όμ •μž…λ‹ˆλ‹€.

1.2 validate

ν…ŒλΌνΌ 파일의 μ½”λ“œμ μΈ μœ νš¨μ„±λ§Œ ν™•μΈν•©λ‹ˆλ‹€. ν…ŒλΌνΌ plan λ™μž‘κ³Ό 달리 μž‘μ„±λœ κ΅¬μ„±μ˜ 문법, 쒅속성, 속성 μ΄λ¦„μ΄λ‚˜ μ—°κ²°λœ κ°’μ˜ 정확성을 ν™•μΈν•©λ‹ˆλ‹€.
terraform validate을 싀행해보면 μ—λŸ¬ 좜λ ₯을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
resource "local_file" "abc" { content = "123!" # filename = "${path.module}/abc.txt" } PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe validate β•· β”‚ Error: Missing required argument β”‚ β”‚ on main.tf line 1, in resource "local_file" "abc": β”‚ 1: resource "local_file" "abc" { β”‚ β”‚ The argument "filename" is required, but no definition was found.
Shell
볡사
local_file λ¦¬μ†ŒμŠ€ μ •μ˜μ— filename이 ν•„μˆ˜ 인수인데 주석 μ²˜λ¦¬λ˜μ—ˆκΈ° λ•Œλ¬Έμ— ν•΄λ‹Ή μ •μ˜κ°€ μ—†λ‹€λŠ” λ©”μ‹œμ§€κ°€ 좜λ ₯λ©λ‹ˆλ‹€.
β€’
-no-color 둜컬 ν™˜κ²½μ΄ μ•„λ‹Œ μ™ΈλΆ€ ν™˜κ²½μ—μ„œ(μ  ν‚¨μŠ€, ν…ŒλΌνΌ ν΄λΌμš°λ“œ, κΉƒν—™ μ•‘μ…˜ λ“±) ν•΄λ‹Ή μ˜΅μ…˜μ„ μ‚¬μš©ν•˜λ©΄ 색상 ν‘œκΈ° λ¬Έμžκ°€ μžˆλŠ”λ° 이 경우 -no-color μ˜΅μ…˜μ„ μΆ”κ°€ν•˜λ©΄ 색상 ν‘œκΈ° 문자 없이 좜λ ₯ν•©λ‹ˆλ‹€.
β€’
-json μ˜΅μ…˜ 쀑에 -json μ˜΅μ…˜μ„ μ‚¬μš©ν•˜λ©΄ μ‹€ν–‰ κ²°κ³Όλ₯Ό JSON ν˜•μ‹μœΌλ‘œ 좜λ ₯ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe validate -json { "format_version": "1.0", "valid": true, "error_count": 0, "warning_count": 0, "diagnostics": [] }
Shell
볡사

plan & apply

plan λͺ…령은 ν…ŒλΌνΌμœΌλ‘œ μ μš©ν•  μΈν”„λΌμ˜ λ³€κ²½ 사항에 λŒ€ν•΄ μ‹€ν–‰ κ³„νšμ„ μƒμ„±ν•˜λŠ” λͺ…λ Ήμ–΄μž…λ‹ˆλ‹€. λ˜ν•œ 좜λ ₯λ˜λŠ” κ²°κ³Όλ₯Ό ν™•μΈν•˜μ—¬ μ–΄λ–€ 변경이 μ μš©λ μ§€ 미리 κ²€ν† ν•  수 μžˆμ–΄ μ΄ν•΄ν•˜λŠ”λ° 도움을 μ€λ‹ˆλ‹€.
applyλŠ” μœ„ plan κ³„νšμ„ 기반으둜 μž‘μ—…μ„ μ‹€ν–‰ν•©λ‹ˆλ‹€.
plan λͺ…령은 λ³€κ²½ 사항을 μ‹€μ œλ‘œ μ μš©ν•˜μ§€λŠ” μ•ŠμœΌλ―€λ‘œ 적용 전에 μ˜ˆμƒν•œ ꡬ성이 λ§žλŠ”μ§€ κ²€ν† ν•˜λŠ”λ° μ΄μš©λ©λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # local_file.abc will be created + resource "local_file" "abc" { + content = "abc!" + content_base64sha256 = (known after apply) + content_base64sha512 = (known after apply) + content_md5 = (known after apply) + content_sha1 = (known after apply) + content_sha256 = (known after apply) + content_sha512 = (known after apply) + directory_permission = "0777" + file_permission = "0777" + filename = "./abc.txt" + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy.
Shell
볡사
plan λͺ…령을 μ‹€ν–‰ν•˜λ©΄ 처음 좜λ ₯된 λ‚΄μš©μ—μ„œ + κΈ°ν˜ΈλŠ” μƒˆλ‘œ μƒμ„±λ˜λŠ” λ¦¬μ†ŒμŠ€μž…λ‹ˆλ‹€.
λ§ˆμ§€λ§‰ Plan: 1 to add, 0 to change, 0 to destroy. κ²°κ³ΌλŠ” 이 ꡬ성을 μ μš©ν•  경우 1개의 λ¦¬μ†ŒμŠ€κ°€ μΆ”κ°€λ˜κ³ , λ³€κ²½λ˜κ±°λ‚˜ μ‚­μ œλ˜λŠ” 것은 μ—†λ‹€κ³  좜λ ₯ν•΄μ€λ‹ˆλ‹€.
terraform apply λͺ…령을 싀행해보면 plan λͺ…령어와 μœ μ‚¬ν•œ 좜λ ₯을 ν‘œκΈ°ν•˜μ§€λ§Œ μ‹€ν–‰ κ³„νšμ„ 보여쀀 ν›„ 적용 μ—¬λΆ€λ₯Ό λ¬»λŠ” μž…λ ₯ λͺ¨λ“œκ°€ ν™œμ„±ν™”λ©λ‹ˆλ‹€. yesκ°€ μ•„λ‹ˆλ©΄ λͺ¨λ‘ μ·¨μ†Œν•˜λŠ” κ²ƒμœΌλ‘œ κ°„μ£Όν•©λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # local_file.abc will be created + resource "local_file" "abc" { + content = "abc!" + content_base64sha256 = (known after apply) + content_base64sha512 = (known after apply) + content_md5 = (known after apply) + content_sha1 = (known after apply) + content_sha256 = (known after apply) + content_sha512 = (known after apply) + directory_permission = "0777" + file_permission = "0777" + filename = "./abc.txt" + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: <yes or no>
Shell
볡사
μ΄λ²ˆμ—λŠ” μ‹€ν–‰ κ³„νš νŒŒμΌμ„ 별도 μž‘μ„±ν•΄μ„œ apply ν•˜λŠ” 방법에 λŒ€ν•΄μ„œ μ•Œμ•„λ΄…λ‹ˆλ‹€.
terraform plan -out=tfplan
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe plan -out=tfplan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # local_file.abc will be created + resource "local_file" "abc" { + content = "abc!" + content_base64sha256 = (known after apply) + content_base64sha512 = (known after apply) + content_md5 = (known after apply) + content_sha1 = (known after apply) + content_sha256 = (known after apply) + content_sha512 = (known after apply) + directory_permission = "0777" + file_permission = "0777" + filename = "./abc.txt" + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Saved the plan to: tfplan To perform exactly these actions, run the following command to apply: terraform apply "tfplan"
Shell
볡사
μƒμ„±λ˜λŠ” νŒŒμΌμ€ λ°”μ΄λ„ˆλ¦¬ ν˜•νƒœμ΄κΈ° λ•Œλ¬Έμ— λ‚΄μš©μ„ 확인할 μˆ˜λŠ” μ—†μ§€λ§Œ applyλ₯Ό μ‹€ν–‰ν–ˆμ„ λ•Œ plan의 κ³Όμ •κ³Ό apply 과정이 λ™μ‹œμ— λ³΄μ˜€λŠ”λ° μ§€κΈˆμ€ μ‹€ν–‰ κ³„νš 파일이 있기 λ•Œλ¬Έμ— μ¦‰μ‹œ μ μš©ν•˜λŠ” 것을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply .\tfplan local_file.abc: Creating... local_file.abc: Creation complete after 0s [id=5678fb68a642f3c6c8004c1bdc21e7142087287b] Apply complete! Resources: 1 added, 0 changed, 0 destroyed. PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply local_file.abc: Refreshing state... [id=5678fb68a642f3c6c8004c1bdc21e7142087287b] No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Shell
볡사
λ‹€μ‹œ applyλ₯Ό μ‹œλ„ν•˜λ©΄ 이미 적용이 λ˜μ—ˆκ³  λ³€κ²½ 사항이 μ—†κΈ° λ•Œλ¬Έμ— No changes. λ©”μ‹œμ§€λ₯Ό 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.
resource "local_file" "abc" { content = "abc!" filename = "${path.module}/abc.txt" } resource "local_file" "def" { content = "def!" filename = "${path.module}/def.txt" }
Shell
볡사
μ΄λ²ˆμ—λŠ” κΈ°μ‘΄ main.tf νŒŒμΌμ— μƒˆλ‘œμš΄ ν•­λͺ©μ„ μΆ”κ°€ν•˜κ³  applyλ₯Ό ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply local_file.abc: Refreshing state... [id=5678fb68a642f3c6c8004c1bdc21e7142087287b] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # local_file.def will be created + resource "local_file" "def" { + content = "def!" + content_base64sha256 = (known after apply) + content_base64sha512 = (known after apply) + content_md5 = (known after apply) + content_sha1 = (known after apply) + content_sha256 = (known after apply) + content_sha512 = (known after apply) + directory_permission = "0777" + file_permission = "0777" + filename = "./def.txt" + id = (known after apply) } Plan: 1 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes local_file.def: Creating... local_file.def: Creation complete after 0s [id=15f946cb27f0730866cefea4f0923248d9366cb0] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Shell
볡사
κ²°κ³ΌλŠ” μƒˆλ‘œ μΆ”κ°€λœ λ¦¬μ†ŒμŠ€μ— λŒ€ν•΄μ„œλ§Œ μƒˆλ‘œ μƒμ„±ν•˜λŠ” μ‹€ν–‰ κ³„νšμ„ λ³΄μ—¬μ£Όκ²Œ λ©λ‹ˆλ‹€. Enter a value 값에 yesλ₯Ό μž…λ ₯ν•΄μ„œ μ μš©ν•˜λ©΄ ν˜„μž¬ 디렉터리에 def.txt 파일이 μƒμ„±λœ 것을 λ³΄μ—¬μ€λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> ls 디렉터리: D:\ν…ŒλΌνΌ\terraform_code Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2023-07-23 μ˜€μ „ 8:47 .terraform -a---- 2023-07-23 μ˜€μ „ 8:47 1153 .terraform.lock.hcl -a---- 2023-07-25 μ˜€ν›„ 5:34 4 abc.txt -a---- 2023-07-25 μ˜€ν›„ 5:55 4 def.txt -a---- 2023-07-25 μ˜€ν›„ 5:40 184 main.tf -a---- 2023-06-21 μ˜€ν›„ 7:29 63411880 terraform.exe -a---- 2023-07-25 μ˜€ν›„ 5:55 2658 terraform.tfstate -a---- 2023-07-25 μ˜€ν›„ 5:55 1420 terraform.tfstate.backup -a---- 2023-07-25 μ˜€ν›„ 5:25 2195 tfplan
Shell
볡사
이전에 μƒμ„±ν•œ μ‹€ν–‰ κ³„νš 파일 tfplanμ—λŠ” abc.txt만 μƒμ„±ν•˜λŠ” ꡬ성인데 λ‹€μ‹œ applyλ₯Ό μ§„ν–‰ν•˜λ©΄ κ²°κ³Όκ³Ό μ–΄λ–»κ²Œ λ κΉŒμš”?
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply .\tfplan β•· β”‚ Error: Saved plan is stale β”‚ β”‚ The given plan file can no longer be applied because the state was changed by another operation after the plan was created.
Shell
볡사
μ—λŸ¬κ°€ λ°œμƒν–ˆλŠ”λ° tfplan이 μƒμ„±λœ 이후에 변경이 λ°œμƒν–ˆκΈ° λ•Œλ¬Έμ— 이전에 μž‘μ„±λœ μ‹€ν–‰ κ³„νšμœΌλ‘œ μ μš©ν•  수 μ—†λ‹€λŠ” λ©”μ‹œμ§€ μž…λ‹ˆλ‹€.
μƒˆλ‘œ μΆ”κ°€ν•œ def μ½”λ“œλ₯Ό μ‚­μ œν•˜κ³  λ‹€μ‹œ μ§„ν–‰ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€.
PS D:\ν…ŒλΌνΌ\terraform_code> .\terraform.exe apply local_file.def: Refreshing state... [id=15f946cb27f0730866cefea4f0923248d9366cb0] local_file.abc: Refreshing state... [id=5678fb68a642f3c6c8004c1bdc21e7142087287b] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: - destroy Terraform will perform the following actions: # local_file.def will be destroyed # (because local_file.def is not in configuration) - resource "local_file" "def" { - content = "def!" -> null - content_base64sha256 = "Rm4skjSqJGFRkUFCflW7rNUZ4sAS3vzjWfrOjTwlDBU=" -> null - content_base64sha512 = "JwN8zsR7XvAQZ9KkxokoJPkPZt5LElyjPuH0Pmhd82GIL/Zu3rZOHRacv8myxhbbZzpUahtQ6HDB0OMSiXedyA==" -> null - content_md5 = "3f6d9022e2f7b9cf3995155f239cba7c" -> null - content_sha1 = "15f946cb27f0730866cefea4f0923248d9366cb0" -> null - content_sha256 = "466e2c9234aa2461519141427e55bbacd519e2c012defce359face8d3c250c15" -> null - content_sha512 = "27037ccec47b5ef01067d2a4c6892824f90f66de4b125ca33ee1f43e685df361882ff66edeb64e1d169cbfc9b2c616db673a546a1b50e870c1d0e31289779dc8" -> null - directory_permission = "0777" -> null - file_permission = "0777" -> null - filename = "./def.txt" -> null - id = "15f946cb27f0730866cefea4f0923248d9366cb0" -> null } Plan: 0 to add, 0 to change, 1 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes local_file.def: Destroying... [id=15f946cb27f0730866cefea4f0923248d9366cb0] local_file.def: Destruction complete after 0s Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
Shell
볡사
ν…ŒλΌνΌμ€ μ„ μ–Έμ μœΌλ‘œ λ™μž‘ν•˜κΈ° λ•Œλ¬Έμ— ν˜„μž¬μ˜ μ½”λ“œ μƒνƒœμ™€ μ μš©ν•  μƒνƒœλ₯Ό λΉ„κ΅ν•΄μ„œ μΌμΉ˜μ‹œν‚€λŠ” μž‘μ—…μ„ μˆ˜ν–‰ν•©λ‹ˆλ‹€. κ·Έλ ‡κ²Œ λ•Œλ¬Έμ— 제거된 def μ½”λ“œλ₯Ό μ‚­μ œν•˜λŠ” λ™μž‘μ„ μˆ˜ν–‰ν•˜λŠ” 것을 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.