provider "aws" { profile = "default" region = var.region } terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 5.46" } } backend "remote" { organization = "nyahdev" workspaces { name = "nyah-dot-dev-workspace" } } } resource "aws_s3_bucket" "ses-bucket" { bucket = var.bucket force_destroy = true tags = { Name = var.bucket Environment = "personal" } } resource "aws_s3_bucket_versioning" "ses-bucket-versioning" { bucket = aws_s3_bucket.ses-bucket.id versioning_configuration { status = "Enabled" } } resource "aws_s3_bucket_policy" "ses-bucket" { bucket = aws_s3_bucket.ses-bucket.id policy = jsonencode({ Version = "2012-10-17" Id = "SESBucketPolicy" Statement = [ { Sid = "SesWriteToBucket" Effect = "Allow" Principal = "*" Action = "s3:PutObject" Resource = ["${aws_s3_bucket.ses-bucket.arn}/*"] }, ] }) } data "aws_iam_policy_document" "ses_email_forward_policy_document" { statement { sid = "1" actions = [ "ses:SendEmail", "ses:SendRawEmail", ] resources = [ "*" ] } statement { sid = "2" actions = [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", ] resources = [ "arn:aws:logs:*:*:*", ] } } resource "aws_iam_policy" "ses-email-policy" { name = "ses-forward-email-policy" path = "/" policy = data.aws_iam_policy_document.ses_email_forward_policy_document.json } data "aws_iam_policy_document" "ses_email_assume_role_document" { statement { sid = "3" actions = ["sts:AssumeRole"] principals { type = "Service" identifiers = ["lambda.amazonaws.com"] } } } resource "aws_iam_role" "ses-email-role" { name = "ses-email-forward-lambda-invoke-role" assume_role_policy = data.aws_iam_policy_document.ses_email_assume_role_document.json managed_policy_arns = [aws_iam_policy.ses-email-policy.arn] } resource "aws_sns_topic" "ses-email-topic" { name = var.topic delivery_policy = <