티스토리 뷰

반응형

 

  • terraform init은 해당 명령어를 사용한 디렉토리를 기준으로 .tf 파일을 스캔한 후, 필요한 plugin을 확인한다.
  • 필요한 plugin 목록을 정리한 후 .terraform 디렉토리를 만들고, releases.hashicorp.com로부터 필요한 plugin을 제공하는 provider 파일을 다운로드 받는다.
  • terraform의 제작사인 hashicorp의 경우, registry 또는 releases를 위해 Fastly(회사 이름)의 CDN을 사용하지만 한국에서는 해당 CDN이 먹통이 되는 경우가 종종 있다.
    • 이에 따라 1분 안팎으로 종료되는 terraform init 과정이 20분을 넘어가는 경우가 생김!
  • 이 경우, https://releases.hashicorp.com/에 접속하여 필요한 provider를 사용자의 OS에 맞춰 직접 다운로드한 후 다음을 실행한다.
[terraform] ls -al
total 24
drwxr-xr-x  6 ingnoh  staff   192  3 16 09:57 .
drwxr-xr-x  5 ingnoh  staff   160  3 16 09:56 ..
drwxr-xr-x  3 ingnoh  staff    96  3 16 09:57 .terraform
-rw-r--r--  1 ingnoh  staff  2047  3 16 09:57 .terraform.lock.hcl
-rw-r--r--  1 ingnoh  staff  1875  3 16 09:56 commons.tf
-rw-r--r--  1 ingnoh  staff  2973  3 16 09:56 destination.tf

# 현재 폴더의 .terraform을 지정. -plugin-dir는 상대 경로 / 절대 경로 모두 상관 없음
[terraform] terraform init -plugin-dir=.terraform/providers

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/null from the dependency lock file
- Using previously-installed hashicorp/aws v3.32.0
- Using previously-installed hashicorp/null v3.1.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
[terraform]
  • terraform init의 -plugin-dir 옵션은 로컬 디렉토리에 위치한 terraform provider 디렉토리를 통해 terraform init을 수행한다.
  • 즉, 인터넷이 연결되지 않았더라도 local에 필요한 provider 파일이 모두 존재한다면 문제 없이 terraform init을 수행할 수 있는 방법을 제공한다.

 

  • terraform은 해당 방법은 1회성 terraform init만 사용하는 경우에 권장하며, 잦은 사용시에는 ~/.terraform.d/.terraformrc에 (없으면 생성하여) 다음과 같이 작성하는 것을 권장한다.
provider_installation {
  filesystem_mirror {
    path    = "/usr/share/terraform/providers"
    include = ["example.com/*/*"]
  }
  direct {
    exclude = ["example.com/*/*"]
  }
}

 

댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함