コンテンツにスキップ

Terraform (AWS)

You must generate an Access Key before getting started. All examples will utilize access_key_id and access_key_secret variables which represent the Access Key ID and Secret Access Key values you generated.


この例では、AWSプロバイダーを使用してTerraformでR2を構成する方法を示します。

terraformをインストールしたら、main.tfを作成し、以下の内容をコピーして、あなたのアカウントIDとR2の認証情報に置き換えます。

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5"
}
}
}
provider "aws" {
region = "us-east-1"
access_key = <R2 Access Key>
secret_key = <R2 Secret Key>
skip_credentials_validation = true
skip_region_validation = true
skip_requesting_account_id = true
endpoints {
s3 = "https://<account id>.r2.cloudflarestorage.com"
}
}
resource "aws_s3_bucket" "default" {
bucket = "<org>-test"
}
resource "aws_s3_bucket_cors_configuration" "default" {
bucket = aws_s3_bucket.default.id
cors_rule {
allowed_methods = ["GET"]
allowed_origins = ["*"]
}
}
resource "aws_s3_bucket_lifecycle_configuration" "default" {
bucket = aws_s3_bucket.default.id
rule {
id = "expire-bucket"
status = "Enabled"
expiration {
days = 1
}
}
rule {
id = "abort-multipart-upload"
status = "Enabled"
abort_incomplete_multipart_upload {
days_after_initiation = 1
}
}
}

その後、terraform planを使用して変更を確認し、terraform applyを使用して変更を適用できます。