Terragrunt를 통해 개발(dev) 환경과 운영(prod) 환경을 분리하여 소프트웨어 개발과 배포 과정에서 발생할 수 있는 문제를 최소화한다.
Terragrunt란, 테라폼 소스코드를 DRY(Don't Repeat Yourself) 하게 만들어주는 툴이다.
Terragrunt는 Terraform workspace을 사용하여 ${terraform.workspace} 환경 변수를 지원하며, 이를 이용해 환경별로 다른 리소스를 생성할 수 있다. 또한, terraform.tfvars 파일을 사용하여 코드를 동일하게 유지하면서 변경되는 부분만 변수화시켜서 관리할 수 있다.
Terraform VS Branch VS Terragrunt

mac
brew install terragrunt
using binary file
Release page에서 최신 패키지 다운로드 링크를 복사한 후 wget으로 다운
wget <https://github.com/gruntwork-io/terragrunt/releases/download/v0.45.2/terragrunt_linux_amd64>
mv terragrunt_linux_amd64 terragrunt
chmod u+x terragrunt
sudo mv terragrunt /usr/local/bin/terragrunt
resource "aws_instance" "example" {
ami = "ami-0fb653ca2d3203ac1"
instance_type = var.instance_type
tags = {
Name = var.instance_name
}
}
variable "instance_type" {
description = "The instance type to use"
type = string
}
variable "instance_name" {
description = "The name to use for the instance"
type = string
}
위 리소스를 배포할 모듈의 폴더 구조(예시)
.
└── modules
└── ec2-instance
├── main.tf
├── outputs.tf
└── variables.tf