728x90
Amazon S3로 Terraform 백엔드 구성하기 - terraform code
s3 버킷 생성
- 버킷 이름 : okahpt16-terraform-s3-bucket
dynamoDB 테이블 생성
- 테이블 이름 : okahpt16_terraform_lock
- 파티션 키 : LockID
Terraform Code
$ tree
.
├── main.tf
└── provider.tf
vim provider.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.27.0"
}
}
}
provider "aws" {
# Configuration options
profile = "terraform"
region = "ap-northeast-2"
}
vim main.tf
### s3 버킷 생성
resource "aws_s3_bucket" "terraform_state" {
bucket = "okahpt16-terraform-s3-bucket"
}
resource "aws_s3_bucket_acl" "terraform_state" {
bucket = aws_s3_bucket.terraform_state.id
acl = "private"
}
resource "aws_s3_bucket_versioning" "terraform_state_version" {
bucket = aws_s3_bucket.terraform_state.id
versioning_configuration {
status = "Enabled"
}
}
### dynamodb 테이블 생성
resource "aws_dynamodb_table" "terraform_lock" {
name = "okahpt16_terraform_lock"
hash_key = "LockID"
billing_mode = "PAY_PER_REQUEST"
attribute {
name = "LockID"
type = "S"
}
}
$ terraform state list
aws_dynamodb_table.terraform_lock
aws_s3_bucket.terraform_state
aws_s3_bucket_acl.terraform_state
aws_s3_bucket_versioning.terraform_state_version
참고URL
- https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_versioning
- https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table
728x90
'퍼블릭 클라우드' 카테고리의 다른 글
Packer를 사용하여 AWS AMI(Amazon Machine Image)를 빌드하는 방법 (0) | 2022.08.30 |
---|---|
AWS Billing(Budgets) 알람을 설정하는 방법 (0) | 2022.08.29 |
[iac] Amazon S3로 Terraform 백엔드 구성하기 (0) | 2022.08.28 |
[iac][terraform] aws provider 생성 (0) | 2022.08.26 |
Amazon Route 53 Invalid Change Batch 오류(InvalidChangeBatch 400) (0) | 2022.08.19 |