본문 바로가기
프로그래밍 언어/terraform

[terraform] provider를 로컬 캐쉬를 이용하여 초기화 하는 방법

by hs_seo 2024. 2. 7.

테라폼을 이용해서 작업을 할 때 terrafom init 명령을 입력하면 프로바이더를 다운로드 하게 되는데 , 폐쇄된 환경에서는 사용할 수 없게 됩니다.

 

이런 경우 로컬 캐쉬를 이용해서 테라폼 프로바이더를 설정할 수 있습니다.

 

# home 디렉토리에 .terraformrc 파일 생성 후 다음 내용을 입력 
# .terraformrc 파일 내용 
plugin_cache_dir = "/home/deploy/.terraform.d/plugins-cache"
disable_checkpoint = true
provider_installation {
    filesystem_mirror {
        path    = "/home/deploy/.terraform.d/plugins-cache"
        include = ["registry.terraform.io/*/*"]
    }
    direct {
        exclude = ["registry.terraform.io/*/*"]
    }
}

# plugin_cache_dir 내용
# 플러그인 캐쉬는 기존에 다운 받은 내용이나, git 에서 추가 
# 경로는 다음과 같은 형식으로 추가 
~/.terraform.d/plugins-cache/registry.terraform.io

 

이렇게 입력 후 terraform init 을 입력하면 정상적으로 추가 되었을 때 Initializing provider plugis 를 처리할 때 from the shared cache directory 문구를 확인할 수 있습니다.

 

https://terraformguru.com/terraform-certification-using-azure-cloud/65-Terraform-CLI-Config-File-MacOS-and-Linux/

 

Terraform CLI Config File MacOS and LinuxOS - STACKSIMPLIFY

 

terraformguru.com

 

반응형