목적

token이나 id/password 없이 Access 할 수 없는 github repository에서 모듈을 꺼내쓰자

사전 준비

해당 레포에 접근할 수 있는 토큰이 있어야 함

모듈 정의

모듈 폴더가 모듈을 사용하는 레포와 동일하면 아래와 같이 사용하면 되는데, 다른 레포에 있을 경우 source부분을 바꿔주면 된다.

module "test_module" {
  source = "../modules/test"
}

변경 후

git::<git repo url>//<module path>

module "test_module" {
  source = "git::<https://github.com/example/infra.git//modules/test>"
}

그리고 terraform init을 하면 git repo에 접근할 수 있는 password를 입력하라고 뜨는데, token을 입력해주면 된다. 이 작업은 한번만 하면 된다.

모듈 업그레이드

만약 repo에 있는 모듈이 변경되었으면 아래 명령어로 업그레이드 시켜주어야 한다.

terraform init -upgrade

참고

Using Private Git Repositories as Terraform Modules - Wahl Network