Engineering/Terraform

1. Terraform 시작하기

mutjang2 2025. 8. 4. 14:44

 

Terraform 이란?

Terraform은 Hashicorp에서 오픈소스로 공개한 IaC 도구이다. 사용자는 테라폼을 이용하여 Cloud 및 On-premise 환경의 인프라를 구축, 관리할 수 있다.

 


Terraform의 특징

 

1. 선언적 구성

테라폼은 코드로써 원하는 상태를 정의하고, 작업 실행 시 테라폼이 해당 상태로 변경을하는 선언적 구성을 갖춘다.

 

2. 플랫폼 독립성

테라폼은 플랫폼에 종속되지 않는다. 다양한 클라우드 플랫폼과 온프레미스, 그리고 테라폼이 실행되는 OS 환경 또한 다양하게 지원한다.

 

3. 자동화

테라폼은 인프로 프로비저닝, 구성, 배포 등의 작업을 자동화하여 수동 작업 간의 오류를 줄이고 효율성을 높인다. CI/CD 툴과도 결합하여 코드관리까지 자동화할 수 있다.

 


Terraform 환경 구성

 

테라폼 실행환경을 구성하는 방법은 크게 세 가지로 나뉜다.

  • 미리 빌드된 바이너리 파일 다운로드
  • 테라폼 소스코드를 다운로드 한 후 빌드
  • OS 패키지 매니저를 통하여 다운로드

앞서 언급한 것 처럼 테라폼은 다양한 OS 위에서 실행이 가능하다. 테라폼 홈페이지에 접속하면 각각의 OS와 CPU 아키텍처에 알맞게 다운로드가 가능하다.

https://developer.hashicorp.com/terraform/install

 

Install | Terraform | HashiCorp Developer

Explore Terraform product documentation, tutorials, and examples.

developer.hashicorp.com

 

혹은 OS package 매니저로 설치가 가능하다. 그러기 위해서는 repository를 구성해주어야 한다.

]# yum install -y yum-utils
]# yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
]# yum -y install terraform

 

설치가 완료되고 terraform을 실행하면 기본 도움말이 표기된다. 여기까지 완료되었다면, 테라폼을 시작할 수 있다.

]# terraform 
[root@Rocky-Test yum.repos.d]# 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
  modules       Show all declared modules in a working directory
  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.

'Engineering > Terraform' 카테고리의 다른 글

2. Terraform - 기본 사용법  (0) 2026.04.07