테라폼 환경 구성
테라폼 실행 환경을 구성하는 방법은 크게 세 가지로 나뉜다.
- 미리 빌드된 바이너리(실행) 파일 다운로드
- 테라폼 소스 코드를 다운로드 후 빌드
- OS 패키지 관리자 활용
그 중, OS 패키지 관리자를 활용하여 테라폼 실행 환경 구성을 진행하겠다.
테라폼 설치
Terraform 사이트에 접속하여 Download Terraform을 통해 다운로드 페이지로 접속한다.
그 중, 내가 사용하는 환경인 Ubuntu 환경에 맞는 패키지 매니저를 확인하여 설치한다.
# wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform--2024-07-08 20:52:50-- https://apt.releases.hashicorp.com/gpg
Resolving apt.releases.hashicorp.com (apt.releases.hashicorp.com)... 13.225.131.54, 13.225.131.99, 13.225.131.7, ...
Connecting to apt.releases.hashicorp.com (apt.releases.hashicorp.com)|13.225.131.54|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3980 (3.9K) [binary/octet-stream]
Saving to: ‘STDOUT’
- 100%[=================================================>] 3.89K --.-KB/s in 0s
2024-07-08 20:52:50 (108 MB/s) - written to stdout [3980/3980]
# echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com focal main
# sudo apt update && sudo apt install terraform
Get:1 https://apt.releases.hashicorp.com focal InRelease [12.9 kB]
Ign:2 https://pkg.jenkins.io/debian-stable binary/ InRelease
Get:3 https://pkg.jenkins.io/debian-stable binary/ Release [2044 B]
Get:4 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [833 B]
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [128 kB]
Hit:6 http://archive.ubuntu.com/ubuntu focal InRelease
Get:7 https://apt.releases.hashicorp.com focal/main amd64 Packages [138 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal-updates InRelease [128 kB]
Get:9 https://pkg.jenkins.io/debian-stable binary/ Packages [27.1 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [3023 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal-backports InRelease [128 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [3396 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [452 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [14.0 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [2927 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [410 kB]
Get:17 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [544 B]
Get:18 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [990 kB]
Get:19 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [210 kB]
Get:20 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [20.9 kB]
Get:21 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [24.8 kB]
Get:22 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [5968 B]
Get:23 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [540 B]
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [532 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [17.7 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [3045 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [426 kB]
Get:28 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [540 B]
Get:29 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [1209 kB]
Get:30 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [291 kB]
Get:31 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [27.5 kB]
Get:32 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [27.1 kB]
Get:33 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [7936 B]
Get:34 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [616 B]
Fetched 17.6 MB in 6s (2901 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
220 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
terraform
0 upgraded, 1 newly installed, 0 to remove and 220 not upgraded.
Need to get 28.0 MB of archives.
After this operation, 89.0 MB of additional disk space will be used.
Get:1 https://apt.releases.hashicorp.com focal/main amd64 terraform amd64 1.9.1-1 [28.0 MB]
Fetched 28.0 MB in 1s (20.1 MB/s)
Selecting previously unselected package terraform.
(Reading database ... 65787 files and directories currently installed.)
Preparing to unpack .../terraform_1.9.1-1_amd64.deb ...
Unpacking terraform (1.9.1-1) ...
Setting up terraform (1.9.1-1) ...
terraform 명령어로 terraform 설치되었는지 확인해보자.
$ terraform
Usage: terraform [global options] <subcommand> [args]
The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.
Main commands:
init Prepare your working directory for other commands
validate Check whether the configuration is valid
plan Show changes required by the current configuration
apply Create or update infrastructure
destroy Destroy previously-created infrastructure
All other commands:
console Try Terraform expressions at an interactive command prompt
fmt Reformat your configuration in the standard style
force-unlock Release a stuck lock on the current workspace
get Install or upgrade remote Terraform modules
graph Generate a Graphviz graph of the steps in an operation
import Associate existing infrastructure with a Terraform resource
login Obtain and save credentials for a remote host
logout Remove locally-stored credentials for a remote host
metadata Metadata related commands
output Show output values from your root module
providers Show the providers required for this configuration
refresh Update the state to match remote systems
show Show the current state or a saved plan
state Advanced state management
taint Mark a resource instance as not fully functional
test Execute integration tests for Terraform modules
untaint Remove the 'tainted' state from a resource instance
version Show the current Terraform version
workspace Workspace management
Global options (use these before the subcommand, if any):
-chdir=DIR Switch to a different working directory before executing the
given subcommand.
-help Show this help output, or the help for a specified subcommand.
-version An alias for the "version" subcommand.
IDE 구성
VS Code에서 ‘HashiCorp HCL’을 검색 후 설치한다.