sklass의 s-class 프로그래밍 blog

Terraform 설치 본문

Terraform

Terraform 설치

sklass 2021. 12. 20. 14:52
$ touch ~/.bashrc
$ terraform -install-autocomplete

Terraform을 설치하는데 있어서 OS별로 설치하는 방법이 다 다릅니다.

 

MacOS를 사용한다면, 아래의 링크로 가서 다운받으면됩니다.

https://www.terraform.io/downloads

 

Downloads | Terraform by HashiCorp

Terraform is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure.

www.terraform.io

Terraform Auto-Complete

zsh이나 bash를 shell로 쓰고있다면, terraform 까지만 치면 자동완성이 되게끔 하도록 설정할 수 가 있습니다. 아래의 명령어를 실행시켜주세요.

bash

$ touch ~/.bashrc
$ terraform -install-autocomplete

zsh

$ touch ~/.zshrc
$ terraform -install-autocomplete

plugin-cache-dir

테라폼을 사용하여 여러 workspace를 관리하게 되는데, 각 workspace에서 필요로하는 provider나 module을 다운로드 받게됩니다.

 

이때 plugin-cache-dir을 설정해놓지 않으면, 각 workspace 폴더별로 .terraform 이라는 디렉토리안에 해당 provider와 module을 설치하게 됩니다.

 

그러면 workspace의 증가하면 증가할 수록, plugin-cache들의 용량이 기하급수적으로 증가하게 되고, 어느 순간 컴퓨터의 저장 공간이 부족해지게됩니다. 

 

이를 방지하기 위해서, plugin-cache-dir을 설정해서, 중앙집중식으로, 동일한 plugin은 한번만 설치하도록 관리하여 컴퓨터의 terraform 저장 공간을 효율적으로 관리할 수 있습니다.

 

아래의 명령어들을 통해서 plugin-cache-dir을 설정할 수 있습니다.

$ vi ~/.terraformrc

.terraformrc 안에 아래의 내용을 넣어주세요.

plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"

그리고 mkdir -p를 통해서 아래의 경로를 생성해주세요.

$ mkdir -p ~/.terraform.d/plugin-cache