본문으로 건너뛰기

Terragrunt

설치

정보

Terraform이 설치되어 있어야 합니다.

asdf plugin add terragrunt
terragrunt -install-autocomplete

Terragrunt 설정 파일

각 모듈에는 Terragrunt 설정파일인 terragrunt.hcl이 있어야 합니다. 가장 많이 사용되는 remote_state, generate, include 예시는 아래와 같습니다.

backend.hcl
remote_state {
backend = "s3"
generate = {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
}
config = {
bucket = "iac"
region = "ap-northeast-2"

key = "${get_path_from_repo_root()}/terraform.tfstate"
}
}
aws.hcl
generate "aws" {
path = "aws.tf"
if_exists = "overwrite_terragrunt"
contents = <<-EOF
provider "aws" {
default_tags {
tags = {
ManagedBy = "iac/${get_path_from_repo_root()}"
}
}
}
EOF
}
terragrunt.hcl
include "base" {
path = find_in_parent_folders("backend.hcl")
}

include "aws" {
path = find_in_parent_folders("aws.hcl")
}

terragrunt.hcl 파일 수정 후 terragrunt init 명령어를 실행하면 설정에 따라 파일들이 생성됩니다.