모듈 소스
모듈 소스 (Module Sources)
Terraform 모듈이 로드되는 다양한 소스 위치를 설명해 드릴게요. 로컬 경로, 레지스트리, GitHub, 버킷 등에서 모듈을 가져올 수 있어요.
출처: 문서
본문
module 블록의 source 인자는 모듈을 로드할 위치를 지정해요. Terraform은 다양한 소스 형식을 지원하며, 각각 버전 관리 방식이 달라요.
로컬 경로 (Local paths)
가장 간단한 소스는 로컬 파일시스템 경로예요:
module "consul" {
source = "./consul"
}
로컬 경로 소스는 절대 경로나 상대 경로를 사용할 수 있어요. 로컬 경로 모듈은 압축·버전 관리가 되지 않으며 수정 가능해요. 로컬 경로는 재사용 가능한 모듈 개발 초기 단계에 유용하지만, 배포된 모듈은 공유 가능한 소스를 사용하는 것이 좋아요.
Terraform 레지스트리 (Terraform Registry)
.terraform/modules에 설치하는 모듈은 Terraform 레지스트리에서 가져올 수 있어요:
module "consul" {
source = "hashicorp/consul/aws"
version = "0.1.0"
}
레지스트리 소스는 <NAMESPACE>/<NAME>/<PROVIDER> 형식이에요. 공개 Terraform Registry 외에도, HCP Terraform 프라이빗 레지스트리처럼 다른 레지스트리 주소를 지정할 수 있어요.
GitHub (GitHub)
GitHub 저장소에서 모듈을 직접 가져올 수 있어요:
module "consul" {
source = "github.com/hashicorp/example"
}
표준 HTTPS 형식(github.com/hashicorp/example)과 SSH 형식([email protected]:hashicorp/example.git)을 지원해요. ref 쿼리 매개변수로 브랜치, 태그, 커밋을 지정할 수 있어요:
source = "github.com/hashicorp/example//subdir?ref=v1.2.0"
// 뒤의 부분은 저장소 안의 하위 디렉터리를 지정해요.
기타 Git 저장소
GitHub 외의 Git 저장소(Bitbucket, GitLab 등)는 일반 Git URL로 지정할 수 있어요:
module "storage" {
source = "git::https://example.com/storage.git"
}
git:: 접두사로 Git 프로토콜을 강제할 수 있어요.
버킷 (Buckets)
S3, GCS 등 객체 스토리지 버킷의 아카이브에서 모듈을 가져올 수 있어요:
module "vpc" {
source = "s3::https://s3-eu-west-1.amazonaws.com/examplecorp-terraform-modules/vpc.zip"
}
:: 앞의 부분은 프로토콜을 지정해요(s3::, gcs:: 등).
HTTP URL
HTTP URL로 모듈을 가져올 수도 있어요:
module "vpc" {
source = "https://example.com/vpc-module.zip"
}
요약 표 (Summary table)
| 소스 유형 | 예시 |
|---|---|
| 로컬 경로 | ./modules/consul |
| 레지스트리 | hashicorp/consul/aws |
| GitHub | github.com/hashicorp/example |
| 일반 Git | git::https://example.com/storage.git |
| 버킷 | s3::https://.../vpc.zip |
| HTTP | https://example.com/vpc-module.zip |