出ましたterraformの自動化してみたシリーズ!!
前回(上記)はなんと2017/08/26とかあれから1年経ってる!(ひさしぶりか!)
また毎度のようにterraformのドキュメントが分かりづらいので、
今回はSESをterraformで実装してみました。
■aws_ses_domain_identity
https://www.terraform.io/docs/providers/aws/r/ses_domain_identity.html
とりあえず適当にadachin.comでメール受信できればOK!
■aws_ses.tf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" alias = "us-east-1" region = "us-east-1" } resource "aws_ses_domain_identity" "adachin-ses" { provider = "aws.us-east-1" domain = "adachin.com" } resource "aws_route53_record" "adachin-ses-verification-record" { provider = "aws.us-east-1" zone_id = "${aws_route53_zone.adachin-com.id}" name = "_amazonses.${aws_ses_domain_identity.adachin-ses.id}" type = "TXT" ttl = "600" records = ["${aws_ses_domain_identity.adachin-ses.verification_token}"] } resource "aws_ses_domain_identity_verification" "adachin-ses-identify-verification" { provider = "aws.us-east-1" domain = "${aws_ses_domain_identity.adachin-ses.id}" depends_on = ["aws_route53_record.adachin-ses-verification-record"] } resource "aws_ses_domain_dkim" "adachin-domain-dkim" { provider = "aws.us-east-1" domain = "${aws_ses_domain_identity.adachin-ses.domain}" } resource "aws_route53_record" "adachin-ses-amazonses-verification-record" { provider = "aws.us-east-1" count = 3 zone_id = "${aws_route53_zone.adachin-com.id}" name = "${element(aws_ses_domain_dkim.adachin-domain-dkim.dkim_tokens, count.index)}._domainkey.adachin.com" type = "CNAME" ttl = "600" records = ["${element(aws_ses_domain_dkim.adachin-domain-dkim.dkim_tokens, count.index)}.dkim.amazonses.com"] } |
とりあえずレコード(TXT,CNAME)とDKIMの設定を自動化しています。
SESはTokyoリージョンが使えないのでproviderでus-east-1を指定しています。
■Route53
1 2 3 4 5 6 7 8 9 10 11 |
resource "aws_route53_zone" "adachin-com" { name = "adachin.com" } resource "aws_route53_record" "mx-record-primary" { zone_id = "${aws_route53_zone.adachin-com.id}" name = "adachin.com" type = "MX" ttl = "60" records = ["10 xxxxxxxxxxxsv.jp"] } |
Route53では転送設定でメールが受信できるようMXレコードを追記します。
$ terraform apply!!!!!
terraformによりレコードが追加されてます!!
メールも受信できてました!!!
■まとめ
terraformやっぱ神!!
0件のコメント