๋ฐ˜์‘ํ˜•

๐Ÿ“‚ IaC/Terraform 17

[Terraform] Output ์ถœ๋ ฅ ๋ณ€์ˆ˜

์ถœ๋ ฅ ๋ณ€์ˆ˜ ์ถœ๋ ฅ ๋ณ€์ˆ˜(output values)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๋ณด๋‚ผ ์ˆ˜ ์žˆ์œผ๋ฉฐ child module(์ž์‹ ๋ชจ๋“ˆ)์—์„œ root module(๋ฃจํŠธ ๋ชจ๋“ˆ)๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ• ๋•Œ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋‚ด๋ณด๋‚ธ ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค๋ฅธ ์ธํ”„๋ผ์˜ ๊ตฌ์„ฑ์— ํ™œ์šฉํ•˜๊ฑฐ๋‚˜ ๋ฐ์ดํ„ฐ ์†Œ์Šค๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. output ์„ ์–ธ์€ ๋ชจ๋“  ๊ตฌ์„ฑํŒŒ์ผ์˜ ๋ชจ๋“  ์œ„์น˜์—์„œ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, outputs.tf์— ์„ ์–ธ ํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. output values๋Š” ๋ฃจํŠธ ๋ชจ๋“ˆ์˜ ์ƒํƒœ ํŒŒ์ผ์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. terraform output๋Š” output์— queryํ•˜๋Š” ๋ช…๋ น์ž…๋‹ˆ๋‹ค. ์ถœ๋ ฅ ๋ณ€์ˆ˜ ์„ ์–ธ Output Blocks description์€ ์„ ํƒ์‚ฌํ•ญ์ด์ง€๋งŒ ์ž‘์„ฑํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. terraform์˜ ํ‘œํ˜„์‹์˜ ๊ฒฐ๊ณผ๋ฅผ value๋กœ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ..

[Terraform] Variable ์ž…๋ ฅ ๋ณ€์ˆ˜

variables / ์ž…๋ ฅ ๋ณ€์ˆ˜ ์ž…๋ ฅ ๋ณ€์ˆ˜(Input variable)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ…Œ๋ผํผ ๊ตฌ์„ฑ ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์œ ์—ฐํ•˜๊ฒŒ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…๋ ฅ ๋ณ€์ˆ˜๋Š” ํ…Œ๋ผํผ์ด ์‹คํ–‰ ๋˜๊ธฐ ์ „์— ํ• ๋‹น๋˜๊ธฐ์— ์ธํ”„๋ผ๋ฅผ ๋ณด๋‹ค ์•ˆ์ „ํ•˜๊ฒŒ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณ€์ˆ˜ ์„ ์–ธ์€ ๋ชจ๋“  ๊ตฌ์„ฑํŒŒ์ผ์˜ ๋ชจ๋“  ์œ„์น˜์—์„œ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, variables.tf์—์„œ ์„ ์–ธ ํ•  ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. ๋ณ€์ˆ˜ ์„ ์–ธ ๋ธ”๋Ÿญ description : ๋ณ€์ˆ˜์˜ ๋ชฉ์ ์„ ๋ฌธ์„œํ™”ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ์„ค๋ช… type : ๋ณ€์ˆ˜์˜ ๋ฐ์ดํ„ฐ ํƒ€์ž… default : ๋ณ€์ˆ˜์˜ ๊ธฐ๋ณธ ๊ฐ’ ๋ชจ๋“  ๋ณ€์ˆ˜์— ๋Œ€ํ•ด description๊ณผ type์„ ์ง€์ •ํ•˜๊ณ , ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ default๊นŒ์ง€ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. variable "aws_region" { description = "AWS region" type ..

[Terraform] Error: Incompatible provider version

Error ๋ฉ”์„ธ์ง€ โ”‚ Error: Incompatible provider version โ”‚ โ”‚ Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform, darwin_arm64. โ”‚ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• brew install go git clone https://github.com/hashicorp/terraform-provider-template.git cd ./terraform-provider-template go build chmod +x terraform-provider-template mkdir -p ~/.terraform.d/plugins/registr..

[Terraform] Provider, Resource, Data Source, Variable, Output, Locals, Module

Terraform Terraform์€ ํ…Œ๋ผํผ ์ž์ฒด๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ๋‚ด์šฉ์œผ๋กœ backend, required_version ๋“ฑ์„ ์ง€์ •ํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. terraform { required_version = ">= 1.0.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 4.0" } } }Provider Provider๋Š” ํ…Œ๋ผํผ์ด ๋™์ž‘ํ•˜๋Š” ํด๋ผ์šฐ๋“œ ์ œ๊ณต์ž(cloud providers) ๋˜๋Š” API ์ œ๊ณต์ž(API providers)์— ๋Œ€ํ•ด ๊ธฐ์ˆ ํ•ฉ๋‹ˆ๋‹ค. provider๋“ค์ด ํ…Œ๋ผํผ์„ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด terraform์€ ์–ด๋–ค ์ข…๋ฅ˜์˜ ์ธํ”„๋ผ๋„ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. provider "aws" { profile = "aws_hyuckang" reg..

[Terraform] Configuration file๊ณผ HCL

Terraform & Configuration file ํ…Œ๋ผํผ์€ IaC(Infra as a Code) Tool๋กœ ๊ตฌ์„ฑ ํŒŒ์ผ(configuration file)์„ ์„ ์–ธ์ (declarative)์œผ๋กœ ์ž‘์„ฑํ•จ์œผ๋กœ์„œ ์ธํ”„๋ผ๋ฅผ ๊ด€๋ฆฌ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค๋‹ˆ๋‹ค. ๊ตฌ์„ฑ ํŒŒ์ผ์€ ํ…Œ๋ผํผ์—๊ฒŒ ์„ค์น˜ํ•  ํ”Œ๋Ÿฌ๊ทธ์ธ, ์ƒ์„ฑํ•  ์ธํ”„๋ผ, ๊ฐ€์ ธ์˜ฌ ๋ฐ์ดํ„ฐ ๋“ฑ์„ ์•Œ๋ ค์ค๋‹ˆ๋‹ค. ๊ตฌ์„ฑ ํŒŒ์ผ์€ ํ…Œ๋ผํผ ๋„ค์ดํ‹ฐ๋ธŒ ์–ธ์–ด์ธ HCL(Hashicorp Configuration Language)๊ณผ JSON์œผ๋กœ ์ž‘์„ฑ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ๊ฐ .tf, .tf.json์˜ ํ™•์žฅ์ž๋ฅผ ๊ฐ–์œผ๋ฉฐ ํ‰๋ฌธ(plain text)์œผ๋กœ ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. ํ…Œ๋ผํผ์€ CDKTF(Cloud Development Kit for Terraform)์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. Typescript, Python, Java,..

[TF] terraform์œผ๋กœ aws ec2 ๋งŒ๋“ค๊ธฐ

terraform init → terraform plan → terraform apply provider.tf provider "aws" { profile = "{PROFILE_NAME}" region = "{REGION}" } ec2_test.tf resource "aws_instance" "tf_test_ec2" { ami = "ami-00000000000000000" instance_type = "t2.nano" subnet_id = "subnet-00000000000000000" private_ip = "10.100.100.100" tags = { Name = "TF_test_ec2" } vpc_security_group_ids = [ "sg-00000000000000000", "sg-000000..

[IaC/TF] Terraform ์„ค์น˜

์„ค์น˜ํ•˜๊ณ ์ž ํ•˜๋Š” OS์— ๋งž๋„๋ก ๋งํฌ ๋ณต์‚ฌ Download Terraform - Terraform by HashiCorp wget๊ณผ ๋ณต์‚ฌํ•œ ๋งํฌ๋กœ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ macOS Arm64 wget https://releases.hashicorp.com/terraform/1.0.10/terraform_1.0.10_darwin_arm64.zip Linux 64-bit wget https://releases.hashicorp.com/terraform/1.0.10/terraform_1.0.10_linux_amd64.zip ๋‹ค์šด๋กœ๋“œํ•œ ํŒŒ์ผ unzip macOs Arm64 unzip terraform_1.0.10_darwin_arm64.zip Linux 64-bit unzip terraform_1.0.10_linux_am..

๋ฐ˜์‘ํ˜•