목차
본문으로 바로가기

[Azure] Terraform으로 Azure Provider 설정하기

category DevOps/Terraform 2025. 7. 17. 14:59
  • Terraform을 사용해 Azure 리소스를 관리하려면 가장 먼저 Provider를 설정하고 작업 디렉터리를 초기화해야 합니다. 이 문서는 Azure Provider인 azurerm을 설정하고 초기화하는 전체 과정을 단계별로 설명합니다.

1. Provider.tf 파일 작성

  • Terraform 작업 디렉터리를 초기화하고, 필요한 Provider 플러그인을 다운로드합니다.
$ cat Provider.tf 
# Azure Provider source and version being used
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.0.0"      # Azure용 Provider인 azurerm을 버전 3.0.0
    }
  }
}
# Configure the Microsoft Azure Provider
provider "azurerm" {            # “Azure를 사용하겠다”고 Terraform에게 알려주는 부분
  features {}                   # Azure의 여러 기능을 사용할 수 있도록 기본 설정을 켜주는 옵션
}
$ tree -a
.
└── Provider.tf
1 directory, 1 file

2. terraform init 명령 실행

  • Terraform 작업 디렉터리를 초기화하고, 필요한 Provider 플러그인을 다운로드합니다.
$ terraform init 
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/azurerm versions matching "3.0.0"...
- Installing hashicorp/azurerm v3.0.0...
- Installed hashicorp/azurerm v3.0.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.

3. 초기화 후 디렉터리 구조 확인

$ tree -a        
.
├── .terraform
│   └── providers
│       └── registry.terraform.io
│           └── hashicorp
│               └── azurerm
│                   └── 3.0.0
│                       └── darwin_arm64
│                           └── terraform-provider-azurerm_v3.0.0_x5
├── .terraform.lock.hcl
└── Provider.tf
8 directories, 3 files

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

[Terraform] 기본 설명 # 2  (0) 2025.07.15
[Terraform] 설치 방법 #1  (0) 2025.07.15