Terraform 설치 · 3 min read · Dec 18, 2025
우분투 서버 22.04에 Terraform 설치하는 방법

Terraform은 명령줄 인터페이스를 통해 수백 대의 서버를 배포하고 관리할 수 있는 오픈 소스 인프라 자동화 도구입니다. Terraform을 사용하면 사람이 읽을 수 있는 파일에 구성을 정의하여 인프라를 구축, 변경 및 관리할 수 있습니다. AWS, Azure, GCP 및 Alibaba 클라우드와 같은 많은 클라우드 공급자를 지원합니다. Terraform은 서버, 데이터베이스, 방화벽, 로드 밸런서 등을 자동화하고 프로비저닝할 수 있습니다.
이 튜토리얼에서는 우분투 22.04에 Terraform을 설치하는 방법을 설명합니다.
전제 조건
- 우분투 22.04가 실행되는 서버.
- 서버에 루트 비밀번호가 설정되어 있어야 합니다.
우분투 저장소에서 Terraform 설치하기
기본적으로 Terraform 패키지는 우분투 22.04 기본 저장소에 없습니다. 따라서 Terraform 공식 저장소를 시스템에 추가해야 합니다.
먼저, 다음 명령어를 사용하여 필요한 모든 종속성을 추가합니다:
apt install -y gnupg software-properties-common curl -y모든 종속성을 설치한 후, 다음 명령어를 사용하여 Terraform GPG 키와 저장소를 추가합니다:
curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"저장소가 추가되면 다음 명령어를 사용하여 Terraform 패키지를 설치할 수 있습니다:
apt install terraform -y설치가 성공적으로 완료되면 다음 명령어를 사용하여 Terraform 버전을 확인합니다:
terraform --version다음과 같은 출력이 표시되어야 합니다:
Terraform v1.3.6
on linux_amd64
소스에서 Terraform 설치하기
Terraform의 최신 버전을 공식 웹사이트에서 다운로드하여 설치할 수도 있습니다.
다음 명령어를 사용하여 다운로드할 수 있습니다:
wget https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_linux_amd64.zip다운로드가 완료되면 다음 명령어를 사용하여 다운로드한 파일의 압축을 풉니다:
unzip terraform_1.3.6_linux_amd64.zip다음으로, Terraform 바이너리를 시스템 위치로 이동합니다:
mv terraform /usr/bin/이제 다음 명령어를 사용하여 Terraform 버전을 확인할 수 있습니다:
terraform --version다음과 같은 출력이 표시됩니다:
Terraform v1.3.6
on linux_amd64
Terraform “자동 완성” 기능 설치하기
“자동 완성” 기능을 사용하면 TAB 키를 누른 후 모든 Terraform 하위 명령을 볼 수 있습니다. 다음 명령어를 사용하여 이 기능을 설치할 수 있습니다.
terraform -install-autocomplete“자동 완성” 기능을 활성화하려면 터미널 셸에서 로그아웃한 후 다시 로그인하거나 다음 명령어를 실행합니다:
source ~/.bashrc다음으로, Terraform 명령어를 실행하고 TAB 키를 두 번 눌러 “자동 완성” 기능을 확인합니다.
terraform다음과 같은 출력에서 모든 하위 명령을 볼 수 있어야 합니다:
apply env get init output push state untaint workspace
console fmt graph login plan refresh taint validate
destroy force-unlock import logout providers show test version
Terraform 사용 방법
Terraform을 사용하려면 먼저 프로젝트를 위한 디렉토리를 생성합니다:
mkdir aws다음으로, 프로젝트 디렉토리로 이동하여 Terraform 구성 파일을 생성합니다:
cd aws
nano main.tf다음 코드를 추가합니다:
# Provider
provider "aws" {
access_key = ""
secret_key = ""
region = "us-west-1"
}
파일을 저장하고 닫은 후 다음 명령어를 사용하여 Terraform을 초기화합니다:
terraform init이 명령은 자동으로 .terraform 디렉토리에 공급자 구성을 다운로드합니다.
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Installing hashicorp/aws v4.46.0...
- Installed hashicorp/aws v4.46.0 (signed by HashiCorp)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
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.
다음으로, 리소스 정의를 정의하고 AWS 변수를 설정한 후 실행 계획을 생성하고 표시해야 합니다.
다음 명령어를 사용하여 생성할 수 있습니다:
terraform plan마지막으로, 다음 명령어를 사용하여 인프라를 구축하고 배포합니다:
terraform applyTerraform이 관리하는 인프라를 파괴하려면 다음 명령어를 실행합니다:
terraform destroy결론
이 게시물에서는 우분투 22.04에 Terraform을 설치하는 방법을 보여주었습니다. 또한 AWS 인스턴스를 프로비저닝하기 위해 Terraform을 사용하는 방법을 설명했습니다. 이제 클라우드 공급자에 따라 자신의 Terraform 구성 파일을 생성할 수 있습니다. 더 많은 정보는 Terraform 문서 페이지를 방문하십시오.
새 게시물을 받은 편지함에서 받기
스팸은 없습니다. 언제든지 구독 해지 가능합니다.