Skip to content

Commit

Permalink
Mg/ses terraform (#214)
Browse files Browse the repository at this point in the history
* add ses domain and email address verification
  • Loading branch information
matthewgeng authored Dec 24, 2021
1 parent 70e0587 commit 4ec96c2
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions terraform/environments/production/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
email = "info@${var.email_domain}"
}
12 changes: 12 additions & 0 deletions terraform/environments/production/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ provider "aws" {
region = "us-west-2"
}

# ------------------------------------------------------------------
module "iam" {
source = "../../modules/iam"
cloudwatch_lambda_logs_policy_name = var.cloudwatch_lambda_logs_policy_name
}

# ------------------------------------------------------------------
module "s3" {
source = "../../modules/s3"
allowed_origins = [var.sdc_domain]
Expand All @@ -38,6 +40,7 @@ module "s3" {
s3_images_bucket_name = var.s3_images_bucket_name
}

# ------------------------------------------------------------------
module "parameter_store" {
source = "../../modules/parameter_store"

Expand All @@ -54,6 +57,7 @@ module "parameter_store" {
lambda_secret_key_name = var.lambda_secret_key_name
}

# ------------------------------------------------------------------
# Lambda functions, could encapsulate in another module for all lambda functions
module "cronMailing" {
source = "../../modules/lambda" # essentially wraps around a lambda
Expand All @@ -76,3 +80,11 @@ module "cronMailing_eventbridge" {
target_arn = module.cronMailing.lambda_function_arn
target_id = module.cronMailing.lambda_function_name
}
# ------------------------------------------------------------------
# SES
module "ses" {
env = var.env
source = "../../modules/ses"
email = local.email
email_domain = var.email_domain
}
12 changes: 12 additions & 0 deletions terraform/environments/production/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ variable "sdc_domain" {
type = string
}

variable "email_domain" {
description = "Email address for SES"
default = "socialdiversity.org"
type = string
}

# should add variable condition checks to limit configuration discrepencies
# ------------------------------------------------------------------
# IAM
Expand Down Expand Up @@ -110,3 +116,9 @@ variable "lambda_secret_key_name" {
default = "LAMBDA_SECRET_KEY"
type = string
}

variable "env" {
description = "environment value for internal terraform use"
default = "production"
type = string
}
3 changes: 3 additions & 0 deletions terraform/environments/staging/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
email = "socialdiversity@${var.email_domain}"
}
14 changes: 14 additions & 0 deletions terraform/environments/staging/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ provider "aws" {
region = "us-east-1"
}

# ------------------------------------------------------------------
module "iam" {
source = "../../modules/iam"
cloudwatch_lambda_logs_policy_name = var.cloudwatch_lambda_logs_policy_name
}

# ------------------------------------------------------------------
module "s3" {
source = "../../modules/s3"
allowed_origins = ["http://localhost:3000", var.sdc_domain, var.sdc_pr_domain]
Expand All @@ -38,6 +40,7 @@ module "s3" {
s3_images_bucket_name = var.s3_images_bucket_name
}

# ------------------------------------------------------------------
module "parameter_store" {
source = "../../modules/parameter_store"

Expand All @@ -54,6 +57,7 @@ module "parameter_store" {
lambda_secret_key_name = var.lambda_secret_key_name
}

# ------------------------------------------------------------------
# Lambda functions, could encapsulate in another module for all lambda functions
module "cronMailing" {
source = "../../modules/lambda" # essentially wraps around a lambda
Expand All @@ -76,3 +80,13 @@ module "cronMailing_eventbridge" {
target_arn = module.cronMailing.lambda_function_arn
target_id = module.cronMailing.lambda_function_name
}

# ------------------------------------------------------------------
# SES

module "ses" {
env = var.env
source = "../../modules/ses"
email = local.email
email_domain = var.email_domain
}
14 changes: 14 additions & 0 deletions terraform/environments/staging/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ variable "sdc_pr_domain" {
type = string
}

# ------------------------------------------------------------------
# SES
variable "email_domain" {
description = "Email address for SES"
default = "uwblueprint.org"
type = string
}

# should add variable condition checks to limit configuration discrepencies
# ------------------------------------------------------------------
# IAM
Expand Down Expand Up @@ -116,3 +124,9 @@ variable "lambda_secret_key_name" {
default = "LAMBDA_SECRET_KEY"
type = string
}

variable "env" {
description = "environment value for internal terraform use"
default = "staging"
type = string
}
14 changes: 14 additions & 0 deletions terraform/modules/ses/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "email" {
description = "Email for ses identity"
type = string
}

variable "email_domain" {
description = "Email domain"
type = string
}

variable "env" {
description = "environment variable (staging or production)"
type = string
}
13 changes: 13 additions & 0 deletions terraform/modules/ses/ses.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "aws_ses_email_identity" "sdc" {
email = var.email
}

resource "aws_ses_domain_identity" "sdc_domain" {
count = var.env == "production" ? 1 : 0
domain = var.email_domain
}

resource "aws_ses_domain_dkim" "sdc_dkim" {
count = var.env == "production" ? 1 : 0
domain = var.email_domain
}

0 comments on commit 4ec96c2

Please sign in to comment.