├── .gitignore ├── LICENSE ├── README.md ├── main.tf ├── outputs.tf ├── r53.tf ├── variables.tf └── versions.tf /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled files 2 | *.tfstate 3 | *.tfstate.backup 4 | 5 | # Module directory 6 | .terraform/ 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Skyscrapers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-ses 2 | 3 | Terraform module to setup AWS SES. 4 | 5 | This module creates an AWS SES resource and adds DKIM records to the provided Route53 zone ID. 6 | 7 | ## Available variables 8 | 9 | * \[`domain`\]: String(required): Domain to use for SES. 10 | * \[`zone_id`\]: String(optional): Route 53 zone ID for the SES domain verification. If the `zone_id` is not set, we do not create verification record in R53. 11 | * \[`ses_records`\]: List(optional): Additional entries which are added to the _amazonses record 12 | 13 | ## Output 14 | 15 | * \[`domain_identity_arn`\]: String: ARN of the SES domain identity. 16 | 17 | ## Example 18 | 19 | ```terraform 20 | module "ses" { 21 | source = "../../modules/ses" 22 | domain = "${var.domain_name}" 23 | zone_id = "${aws_route53_zone.zone.zone_id}" 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_ses_domain_identity" "domain" { 2 | domain = var.domain 3 | } 4 | 5 | resource "aws_ses_domain_dkim" "dkim" { 6 | domain = aws_ses_domain_identity.domain.domain 7 | } 8 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "domain_identity_arn" { 2 | description = "ARN of the SES domain identity" 3 | value = aws_ses_domain_identity.domain.arn 4 | } 5 | -------------------------------------------------------------------------------- /r53.tf: -------------------------------------------------------------------------------- 1 | resource "aws_route53_record" "domain_amazonses_verification_record" { 2 | count = var.zone_id != null ? 1 : 0 3 | zone_id = var.zone_id 4 | name = "_amazonses.${var.domain}" 5 | type = "TXT" 6 | ttl = "3600" 7 | records = concat([aws_ses_domain_identity.domain.verification_token], var.ses_records) 8 | } 9 | 10 | resource "aws_route53_record" "domain_amazonses_dkim_record" { 11 | count = var.zone_id != null ? 3 : 0 12 | zone_id = var.zone_id 13 | name = "${element(aws_ses_domain_dkim.dkim.dkim_tokens, count.index)}._domainkey.${var.domain}" 14 | type = "CNAME" 15 | ttl = "3600" 16 | records = ["${element(aws_ses_domain_dkim.dkim.dkim_tokens, count.index)}.dkim.amazonses.com"] 17 | } 18 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "domain" { 2 | type = string 3 | description = "Domain to use for SES" 4 | } 5 | 6 | variable "zone_id" { 7 | type = string 8 | description = "Route 53 zone ID for the SES domain verification" 9 | default = null 10 | } 11 | 12 | variable "ses_records" { 13 | type = list(string) 14 | description = "Additional entries which are added to the _amazonses record" 15 | default = [] 16 | } 17 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.12" 3 | } 4 | --------------------------------------------------------------------------------