TerraformのS3バックエンドを作成
/icons/point.icon状態をローカルに置くのは推奨されない
S3バケットを作成
code:tf
provider "aws" {
profile = "scala1117_working"
region = "ap-northeast-1"
}
resource "aws_s3_bucket" "state_bucket" {
bucket = "hiroki1117-tf-ec2-state"
acl = "private"
}
terraform apply
backendにs3を指定
code:tf
provider "aws" {
profile = "scala1117_working"
region = "ap-northeast-1"
}
terraform {
backend "s3" {
bucket = "hiroki1117-tf-state"
key = "ec2-state"
region = "ap-northeast-1"
profile = "scala1117_working"
}
}
resource "aws_s3_bucket" "state_bucket" {
bucket = "hiroki1117-tf-state"
acl = "private"
}
terraform init
ローカルのtfstateファイルを削除する