I've searched but no information found. Can we create AWS SES credential by using terraform?
Credentials can be provided by using the AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY , and optionally AWS_SESSION_TOKEN environment variables. The region can be set using the AWS_REGION or AWS_DEFAULT_REGION environment variables.
In order to configure SES using Terraform, we first need to reference an existing domain on AWS Route 53 (technically we could also create the domain in the same Terraform configuration, but generally we use a domain for many things so I think it is often preferable to configure domains manually and references them in ...
Set the AWS_PROFILE environment variable. For example, in Linux, you'd run export AWS_PROFILE=user2 . After that, you can run any AWS CLI tool (e.g., terraform apply ), and it should use your Named Profile. Some tools let you specify the profile as a command-line parameter or an argument in code.
Use the following terraform code to get SES credentials -
resource "aws_iam_user" "smtp_user" {
name = "smtp_user"
}
resource "aws_iam_access_key" "smtp_user" {
user = aws_iam_user.smtp_user.name
}
data "aws_iam_policy_document" "ses_sender" {
statement {
actions = ["ses:SendRawEmail"]
resources = ["*"]
}
}
resource "aws_iam_policy" "ses_sender" {
name = "ses_sender"
description = "Allows sending of e-mails via Simple Email Service"
policy = data.aws_iam_policy_document.ses_sender.json
}
resource "aws_iam_user_policy_attachment" "test-attach" {
user = aws_iam_user.smtp_user.name
policy_arn = aws_iam_policy.ses_sender.arn
}
output "smtp_username" {
value = aws_iam_access_key.smtp_user.id
}
output "smtp_password" {
value = aws_iam_access_key.smtp_user.ses_smtp_password_v4
}
aws ses smtp credentials are iam credentials converted to smtp credentials. You should create a iam user and output them as smtp credentials like with the module below https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/examples/iam-user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With