๋ฐ˜์‘ํ˜•

๐Ÿ“‚ IaC 18

TF 101 Study 4์ฃผ์ฐจ ์ •๋ฆฌ - state, module

๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” CloudNeta์˜ Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC CH 5. State ํ…Œ๋ผํผ์€ Statefulํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ → ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๋น„์ €๋‹ ๊ฒฐ๊ณผ๋ฅผ State์— ์ €์žฅํ•˜๊ณ  ํ”„๋กœ๋น„์ €๋‹ํ•œ ๋ชจ๋“  ๋‚ด์šฉ์„ ์ €์žฅ๋œ ์ƒํƒœ๋กœ ์ถ”์  terraform.tfstate ํŒŒ์ผ์— JSON ์œผ๋กœ ์ €์žฅ → ํ˜ผ์ž ๋กœ์ปฌ์—์„œ ๊ด€๋ฆฌํ•˜๊ฑฐ๋‚˜ ํ˜‘์—…ํ•˜๊ธฐ ์œ„ํ•ด ์›๊ฒฉ ์ €์žฅ์†Œ์—์„œ ๊ด€๋ฆฌ State์—๋Š” ์ž‘์—…์ž๊ฐ€ ์ •์˜ํ•œ ์ฝ”๋“œ์™€ ์‹ค์ œ ํ”„๋กœ๋น„์ €๋‹ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅ → ์ดํ›„ํ›„์˜ ๋ฆฌ์†Œ์Šค ์ƒ์„ฑ, ์ˆ˜์ •, ์‚ญ์ œ์— ๋Œ€ํ•œ ๋™์ž‘์„ ํŒ๋‹จ 5-1. State์˜ ๋ชฉ์ ๊ณผ ์˜๋ฏธ terraform apply → State๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด์ „์— ์ƒ์„ฑ๋œ ๋ฆฌ์†Œ์Šค์™€ ๋น„๊ตํ•ด ์ƒ์„ฑ, ์ˆ˜์ •, ์‚ญ์ œ..

TF 101 Study 3์ฃผ์ฐจ ๋„์ „ ๊ณผ์ œ - ์กฐ๊ฑด์‹, ํ•จ์ˆ˜, ํ”„๋กœ๋น„์ €๋„ˆ, ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ํ”„๋กœ๋ฐ”์ด๋”

CloudNeta์˜ ๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC [3์ฃผ์ฐจ ๋„์ „๊ณผ์ œ] 1. ์กฐ๊ฑด๋ฌธ์„ ํ™œ์šฉํ•˜์—ฌ AWS ๋ฆฌ์†Œ์Šค ๋ฐฐํฌ # ์ž…๋ ฅ ๋ณ€์ˆ˜๋กœ ๋ฐฐํฌ ํ™˜๊ฒฝ(dev, prod)๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ EC2 ์ธ์Šคํ„ด์Šค์˜ ์‚ฌ์ด์ฆˆ ์กฐ์ •ํ•˜๊ธฐ variable "env" {} resource "aws_instance" "app" { # ๋ฐฐํฌ ํ™˜๊ฒฝ์„ ์˜๋ฏธํ•˜๋Š” env ๋ณ€์ˆ˜๊ฐ€ prod๊ฐ€ ์•„๋‹ˆ๋ฉด EC2 ์ธ์Šคํ„ด์Šค๋Š” t3.micro๋กœ ๋ฐฐํฌํ•œ๋‹ค. instance_type = var.env != "prod" ? "t3.micro" : "m5.xlarge" ami = "ami-0c9c942bd7bf113a2" tags = { Name = "app" env = v..

TF 101 Study 3์ฃผ์ฐจ ์ •๋ฆฌ - ์กฐ๊ฑด์‹, ํ•จ์ˆ˜, ํ”„๋กœ๋น„์ €๋„ˆ, ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ํ”„๋กœ๋ฐ”์ด๋”

CloudNeta์˜ ๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC CH3. ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ• - 3 3-10. ์กฐ๊ฑด์‹ ํ…Œ๋ผํผ์˜ ์กฐ๊ฑด์‹์€ 3ํ•ญ ์—ฐ์‚ฐ์ž ํ˜•ํƒœ → ? : ์กฐ๊ฑด์‹์—์„œ ํƒ€์ž…์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ ํ…Œ๋ผํผ์€ ์กฐ๊ฑด ๋น„๊ต๋ฅผ ์œ„ํ•ด ํ˜•ํƒœ๋ฅผ ์ถ”๋ก ํ•˜์—ฌ ์ž๋™์œผ๋กœ ๋ณ€ํ™˜ → ์กฐ๊ฑด์‹์„ ๋ช…์‹œ์ ์ธ ํ˜•ํƒœ๋กœ ์ž‘์„ฑ ์ž…๋ ฅ ๋ณ€์ˆ˜๋กœ ๋ฐฐํฌ ํ™˜๊ฒฝ(dev, prod)๋ฅผ ๊ตฌ๋ถ„ํ•˜์—ฌ EC2 ์ธ์Šคํ„ด์Šค์˜ ์‚ฌ์ด์ฆˆ ์กฐ์ •ํ•˜๊ธฐ 3-11. ํ•จ์ˆ˜ ํ…Œ๋ผํผ์€ ๊ฐ’์˜ ์œ ํ˜•์„ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ ์กฐํ•จํ•  ์ˆ˜ ์žˆ๋Š” ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋‚ด์žฅํ•จ์ˆ˜ ์™ธ์— ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜๋Š” ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. terraform console ์ปค๋งจ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ํ…Œ๋ผํผ์—์„œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. cidrhost(๋‚ด..

Terraform 101 Study - 2์ฃผ์ฐจ(2) ๋„์ „ ๊ณผ์ œ

CloudNeta์˜ ๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC [2์ฃผ์ฐจ ๋„์ „๊ณผ์ œ] 1. ๋ฐ์ดํ„ฐ ์†Œ์Šค ์‹ค์Šต ๋ฆฌ์ „ ๋‚ด์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฐ€์šฉ์˜์—ญ ๋ชฉ๋ก ๊ฐ€์ ธ์˜ค๊ธฐ data "aws_availability_zones" "available" { state = "available" } output "available_az_names" { value = data.aws_availability_zones.available.names } [2์ฃผ์ฐจ ๋„์ „๊ณผ์ œ] 2. ๋ฆฌ์†Œ์Šค ์œ ํ˜•๊ณผ ์ด๋ฆ„์˜ ์ฐจ์ด vpc์™€ subnet์„ ๋ฐฐํฌํ•˜๋ฉด์„œ ๋ฆฌ์†Œ์Šค ์œ ํ˜•๊ณผ ์ด๋ฆ„์˜ ์ฐจ์ด๋ฅผ ์ดํ•ด ๋ฆฌ์†Œ์Šค ๋ธ”๋Ÿญ์€ “_” “”์œผ๋กœ ์„ ์–ธ _..์œผ๋กœ ์ฐธ์กฐ provider "aws" { ..

TF 101 Study 2์ฃผ์ฐจ ์ •๋ฆฌ - data source, variable, local, output, for_each, for, dynamic

๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” CloudNeta์˜ Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC CH3. ๊ธฐ๋ณธ ์‚ฌ์šฉ๋ฒ• - 2 3-5. ๋ฐ์ดํ„ฐ ์†Œ์Šค ๋ฐ์ดํ„ฐ ์†Œ์Šค → ํ…Œ๋ผํผ์œผ๋กœ ์ •์˜๋˜์ง€ ์•Š์€ ์™ธ๋ถ€ ๋ฆฌ์†Œ์Šค ๋˜๋Š” ์ €์žฅ๋œ ์ •๋ณด๋ฅผ ํ…Œ๋ผํผ ๋‚ด์—์„œ ์ฐธ์กฐํ•  ๋•Œ ์‚ฌ์šฉ ์™ธ๋ถ€์—์„œ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•œ ์กฐ๊ฑด → ์ธ์ˆ˜(Arguments) ๊ฐ€์ ธ์˜จ ๋ฐ์ด์„œ ์†Œ์Šค์˜ ๋‚ด์šฉ → ์†์„ฑ(Attributes) # ํ…Œ๋ผํผ ์ฝ”๋“œ data "" "" { = } # ๋ฐ์ดํ„ฐ ์†Œ์Šค ์ฐธ์กฐ data... ๋ฐ์ดํ„ฐ ์†Œ์Šค๋กœ ๋ฆฌ์ „ ๋‚ด์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๊ฐ€์šฉ์˜์—ญ ๋ชฉ๋ก ๊ฐ€์ ธ์˜ค๊ธฐ 3-6. ์ž…๋ ฅ ๋ณ€์ˆ˜(variable) Input Variables → ํ•„์š”ํ•œ ์†์„ฑ ๊ฐ’์„ ์ •์˜ํ•ด ์ฝ”๋“œ์˜ ๋ณ€๊ฒฝ ์—†์ด ์ธํ”„๋ผ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด..

Terraform 101 Study - 1์ฃผ์ฐจ(2) ๋„์ „ ๊ณผ์ œ

CloudNeta์˜ ๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC [1์ฃผ์ฐจ ๋„์ „๊ณผ์ œ] 1. EC2 ์›น์„œ๋ฒ„ ๋ฐฐํฌ Ubuntu ์— apache(httpd) ๋ฅผ ์„ค์น˜ํ•˜๊ณ  index.html ์ƒ์„ฑ(๋‹‰๋„ค์ž„ ์ถœ๋ ฅ)ํ•˜๋Š” userdata ๋ฅผ ์ž‘์„ฑํ•ด์„œ ์„ค์ • ๋ฐฐํฌ ํ›„ ์›น ์ ‘์† provider "aws" { region = "ap-northeast-2" } resource "aws_instance" "apache" { ami = "ami-0c9c942bd7bf113a2" instance_type = "t2.micro" vpc_security_group_ids = [aws_security_group.apache.id] user_data =

Terraform 101 Study - 1์ฃผ์ฐจ(1) ๋‚ด์šฉ์ •๋ฆฌ

CloudNeta์˜ ๊ฐ€์‹œ๋‹ค๋‹˜์ด ์ง„ํ–‰ํ•˜์‹œ๋Š” Terraform 101 Study์— ์ฐธ๊ฐ€ํ•˜๋ฉฐ ์ž‘์„ฑํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์Šคํ„ฐ๋”” ๊ต์žฌ → ํ…Œ๋ผํผ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” IaC CH1. IaC์™€ ํ…Œ๋ผํผ ์ฝ”๋“œ๋กœ ์ธํ”„๋ผ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค๋Š” ๊ฒƒ → ‘์ž์œ ๋กญ๊ฒŒ ๋ณ€๊ฒฝ’ํ•˜๊ณ , ‘ํ™˜๊ฒฝ์„ ์ดํ•ด’ํ•˜๊ณ , ‘๋ฐ˜๋ณต์ ์œผ๋กœ ๋™์ผํ•œ ์ƒํƒœ’๋ฅผ ๋งŒ๋“ค์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ → ๋ช…์„ธ๋ฅผ ๋ณ„๋„์˜ ๋ฌธ์„œ๋กœ ์ •๋ฆฌํ•˜์ง€ ์•Š์•„๋„ ์ธํ”„๋ผ๊ฐ€ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜๋˜์–ด ๋‚จ๋Š”๋‹ค๋Š” ์˜๋ฏธ IaC๋Š” ์ปดํ“จํ„ฐ์—์„œ ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ํ˜•ํƒœ์˜ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด ์ธํ”„๋ผ๋‚˜ ์„œ๋น„์Šค๋ฅผ ํ”„๋กœ๋น„์ €๋‹ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค terraform์€ ํ•˜์‹œ์ฝ”ํ”„์—์„œ ๊ณต๊ฐœํ•œ IaC ๋„๊ตฌ Terraform์€ Provider๋ผ๊ณ  ํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ†ตํ•ด ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž(AWS, GCP, …)๋‚˜ ๊ธฐํƒ€ ์„œ๋น„์Šค์™€ ์ƒํ˜ธ ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค. ํ…Œ๋ผํผ ์ œ๊ณต ์œ ํ˜• 3๊ฐ€์ง€ On-Premise(..

[Terraform] Provider

Provider์™€ Provider maintainer Terraform์€ Provider๋ผ๊ณ  ํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํ†ตํ•ด ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž(AWS, GCP, …)๋‚˜ ๊ธฐํƒ€ ์„œ๋น„์Šค์™€ ์ƒํ˜ธ ์ž‘์šฉํ•ฉ๋‹ˆ๋‹ค. Provider๋Š” ์ปดํ“จํŒ… ๋จธ์‹ , ์„œ๋ธŒ๋„ท, ์Šคํ† ๋ฆฌ์ง€์™€ ๊ฐ™์€ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐœ๋ณ„ ๋‹จ์œ„๋กœ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. Provider maintainer๋Š” ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž๋‚˜ ๊ธฐํƒ€ ์„œ๋น„์Šค์˜ API๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉด provider๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ณ  ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. Terraform Registry์—์„œ Provider๋“ค์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ง์ ‘ ์ž‘์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Providr ๋ฒ„์ „ ๊ด€๋ฆฌ Provider ๋ฒ„์ „์„ ์ ์ ˆํžˆ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฒ„์ „ ์ œ์•ฝ ์กฐ๊ฑด ๋‚ด์—์„œ ์ตœ์‹  ๋ฒ„์ „์„ ๋‹ค์šด๋กœ๋“œํ•˜๋ฉฐ ์ด๋กœ ์ธํ•ด ์˜ˆ์ƒํ•˜์ง€ ๋ชปํ•œ ์ธํ”„๋ผ ๋ณ€๊ฒฝ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋™์ผ..

[Terraform] ์˜์กด์„ฑ(dependency) ๊ด€๋ฆฌ

dependency(์˜์กด์„ฑ) ๋ฆฌ์†Œ์Šค๋‚˜ ๋ชจ๋“ˆ๋กœ ์ƒ์„ฑํ•œ ์ž์› ๊ฐ„์—๋Š” ์˜์กด์„ฑ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ…Œ๋ผํผ์€ ์ด๋ฅผ ํ™•์ธํ•˜์—ฌ ์ž์›์„ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ์‚ญ์ œํ•  ์ˆœ์„œ๋ฅผ ์ •ํ•ฉ๋‹ˆ๋‹ค. ์ข…์†์„ฑ์€ implicit dependency(์•”์‹œ์  ์˜์กด์„ฑ)๊ณผ explicit dependency(๋ช…์‹œ์  ์˜์กด์„ฑ)์ด ์žˆ์Šต๋‹ˆ๋‹ค. implicit dependency(์•”์‹œ์  ์˜์กด์„ฑ) ์•”์‹œ์  ์ข…์†์„ฑ์€ ํ…Œ๋ผํผ์ด ๋ฆฌ์†Œ์Šค๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์ดํ•ดํ•˜๋Š” ์ผ๋ฐ˜์ ์ธ ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด aws_eip.ip์—์„œ aws_instance.example_a.id๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด ์•”์‹œ์  ์ข…์†์„ฑ์ž…๋‹ˆ๋‹ค. resource "aws_instance" "example_a" { ami = "ami-05fa00d4c63e32376" instance_type = "t2.micro" } resource..

[Terraform] data source

Data Source data source๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด API๋‚˜ ๋‹ค๋ฅธ terraform state backend์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ ์˜ˆ์‹œ๋Š” AWS์˜ AMI ID, ๋‹ค๋ฅธ ํ…Œ๋ผํผ ๊ตฌ์„ฑ์˜ output ๋“ฑ์„ ์˜ˆ๋กœ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. data source๋Š” configurationd์„ ๋ณด๋‹ค ์œ ์—ฐํ•˜๊ณ  ๋™์ ์œผ๋กœ ๋งŒ๋“ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. data source๋Š” data..์œผ๋กœ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. data source ๋ธ”๋Ÿญ aws_availability_zones๋Š” aws์—์„œ ๊ฐ€์šฉ์˜์—ญ์„ ์กฐํšŒํ•˜๋Š” data source์ž…๋‹ˆ๋‹ค. data "aws_availability_zones" "available" { state = "available" filter { name = "zone-type" values = ["av..

๋ฐ˜์‘ํ˜•