feat(s3): add basic S3 module and dev-object environment
This commit is contained in:
parent
7c57c839ef
commit
4420416bf1
@ -0,0 +1,10 @@
|
||||
bucket_name: "svc-plus-dev-objects"
|
||||
|
||||
# 是否开启版本管理(默认建议开启)
|
||||
enable_versioning: true
|
||||
|
||||
# 是否启用加密,之后如果你想加 KMS 可以扩展
|
||||
enable_encryption: false
|
||||
|
||||
# Public Access Block(通常建议保持 true)
|
||||
block_public_access: true
|
||||
11
iac-template/terraform-standard/envs/dev-object/Makefile
Normal file
11
iac-template/terraform-standard/envs/dev-object/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
init:
|
||||
terraform init --upgrade
|
||||
|
||||
plan:
|
||||
terraform plan
|
||||
|
||||
apply:
|
||||
terraform apply -auto-approve
|
||||
|
||||
destroy:
|
||||
terraform destroy -auto-approve
|
||||
@ -0,0 +1,9 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "svc-plus-iac-state"
|
||||
key = "account/dev/iam/terraform.tfstate"
|
||||
region = "ap-northeast-1"
|
||||
dynamodb_table = "svc-plus-iac-state-dynamodb-lock"
|
||||
}
|
||||
}
|
||||
|
||||
18
iac-template/terraform-standard/envs/dev-object/main.tf
Normal file
18
iac-template/terraform-standard/envs/dev-object/main.tf
Normal file
@ -0,0 +1,18 @@
|
||||
locals {
|
||||
account = yamldecode(
|
||||
file("${path.root}/../../config/accounts/dev.yaml")
|
||||
)
|
||||
|
||||
s3_conf = yamldecode(
|
||||
file("${path.root}/../../config/resources/dev-object/bucket.yaml")
|
||||
)
|
||||
}
|
||||
|
||||
module "s3" {
|
||||
source = "../../modules/s3"
|
||||
|
||||
bucket_name = local.s3_conf.bucket_name
|
||||
enable_versioning = local.s3_conf.enable_versioning
|
||||
tags = local.account.tags
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
output "bucket_id" {
|
||||
value = module.s3.bucket_id
|
||||
}
|
||||
|
||||
output "bucket_arn" {
|
||||
value = module.s3.bucket_arn
|
||||
}
|
||||
|
||||
20
iac-template/terraform-standard/envs/dev-object/provider.tf
Normal file
20
iac-template/terraform-standard/envs/dev-object/provider.tf
Normal file
@ -0,0 +1,20 @@
|
||||
terraform {
|
||||
required_version = ">= 1.2"
|
||||
|
||||
required_providers {
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 5.92.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = local.account.region
|
||||
|
||||
assume_role {
|
||||
role_arn = "arn:aws:iam::730335654753:role/TerraformDeployRole-Dev"
|
||||
session_name = "TerraformDevSession"
|
||||
}
|
||||
}
|
||||
|
||||
24
iac-template/terraform-standard/modules/s3/main.tf
Normal file
24
iac-template/terraform-standard/modules/s3/main.tf
Normal file
@ -0,0 +1,24 @@
|
||||
resource "aws_s3_bucket" "this" {
|
||||
bucket = var.bucket_name
|
||||
|
||||
tags = merge(var.tags, {
|
||||
Name = var.bucket_name
|
||||
})
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_versioning" "this" {
|
||||
bucket = aws_s3_bucket.this.id
|
||||
|
||||
versioning_configuration {
|
||||
status = var.enable_versioning ? "Enabled" : "Suspended"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_public_access_block" "this" {
|
||||
bucket = aws_s3_bucket.this.id
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
}
|
||||
|
||||
8
iac-template/terraform-standard/modules/s3/outputs.tf
Normal file
8
iac-template/terraform-standard/modules/s3/outputs.tf
Normal file
@ -0,0 +1,8 @@
|
||||
output "bucket_id" {
|
||||
value = aws_s3_bucket.this.id
|
||||
}
|
||||
|
||||
output "bucket_arn" {
|
||||
value = aws_s3_bucket.this.arn
|
||||
}
|
||||
|
||||
16
iac-template/terraform-standard/modules/s3/variables.tf
Normal file
16
iac-template/terraform-standard/modules/s3/variables.tf
Normal file
@ -0,0 +1,16 @@
|
||||
variable "bucket_name" {
|
||||
description = "S3 bucket name (must be globally unique)"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "enable_versioning" {
|
||||
description = "Whether to enable S3 versioning"
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags"
|
||||
type = map(string)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user