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

관련 글

더 보기 »

AWS Terraform 라이프사이클 규칙

소개 인프라스트럭처 코드(IaC)는 업데이트, 교체 및 삭제 시 리소스가 어떻게 동작하는지에 대한 완전한 제어가 있을 때 가장 강력합니다. Terr...