You must be logged in to view saved presets
This comprehensive template includes setup for S3 buckets, IAM roles, policies, KMS keys, RDS instances, snapshots, and an RDS export task with specific configurations.
data "aws_iam_policy_document" "example" {
statement {
actions = ["s3:ListAllMyBuckets"]
resources = [*]
}
statement {
actions = ["s3:GetBucketLocation", "s3:ListBucket"]
resources = [aws_s3_bucket.example.arn]
}
statement {
actions = ["s3:GetObject", "s3:PutObject", "s3:DeleteObject"]
resources = ["${aws_s3_bucket.example.arn}/*"]
}
}
resource "aws_db_instance" "example" {
allocated_storage = 10
db_name = "test"
engine = "mysql"
engine_version = "5.7"
identifier = "example"
instance_class = "db.t3.micro"
parameter_group_name = "default.mysql5.7"
password = "foobarbaz"
skip_final_snapshot = true
username = "foo"
}
resource "aws_db_snapshot" "example" {
db_instance_identifier = aws_db_instance.example.identifier
db_snapshot_identifier = "example"
}
resource "aws_iam_policy" "example" {
name = "example"
policy = data.aws_iam_policy_document.example.json
}
resource "aws_iam_role" "example" {
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "export.rds.amazonaws.com"
}
},
]
})
name = "example"
}
resource "aws_iam_role_policy_attachment" "example" {
policy_arn = aws_iam_policy.example.arn
role = aws_iam_role.example.name
}
resource "aws_kms_key" "example" {
deletion_window_in_days = 10
}
resource "aws_rds_export_task" "example" {
export_only = ["database"]
export_task_identifier = "example"
iam_role_arn = aws_iam_role.example.arn
kms_key_id = aws_kms_key.example.arn
s3_bucket_name = aws_s3_bucket.example.id
s3_prefix = "my_prefix/example"
source_arn = aws_db_snapshot.example.db_snapshot_arn
}
resource "aws_s3_bucket" "example" {
bucket = "example"
force_destroy = true
}
resource "aws_s3_bucket_acl" "example" {
acl = "private"
bucket = aws_s3_bucket.example.id
}