S3에 Terraform 상태 저장

발행: (2025년 12월 4일 오후 09:55 GMT+9)
1 min read
원문: Dev.to

Source: Dev.to

Configuring S3 as a Terraform Backend

Terraform can store its state in an S3 bucket. Below is a minimal configuration that sets up the S3 backend:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 4.0"
    }
  }
  required_version = ">= 1.0"

  backend "s3" {
    bucket                  = "terraform-state-dev"
    key                     = "my-key"
    region                  = "us-east-1"
    shared_credentials_file = "~/.aws/credentials"
  }
}
  • You can use a single key (the key argument) to store all of your Terraform state in one file, or
  • You can allocate one key per Terraform workspace (or per environment) to keep states isolated.

Migrating Existing State to S3

If you already have a local state file or are using a different backend, you can migrate it to the S3 bucket with:

terraform init -migrate-state

Warning: Losing your Terraform state can cause significant trouble, as Terraform relies on that state to track resources. Ensure the S3 bucket is versioned and backed up to prevent accidental loss.

Back to Blog

관련 글

더 보기 »

Day-13: Terraform의 데이터 소스

Data Sources란 무엇인가요? 데이터 소스를 사용하면 기존 VPC, 서브넷, AMI, 보안 그룹 등과 같은 정보를 가져올 수 있습니다. hcl data 'data_source_type' 'dat...

13일 차: Terraform 데이터 소스

Data Source 데이터 소스를 전화번호부와 같이 사용자 이름과 전화번호가 key‑value 쌍으로 API를 통해 접근되는 것으로 생각해 보세요. 값을 hard‑coding 하는 대신…