Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform AWS SES credential resource

I've searched but no information found. Can we create AWS SES credential by using terraform?

like image 881
db099u Avatar asked Oct 17 '18 08:10

db099u


People also ask

Where do you put credentials in 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.

How do you make SES with Terraform?

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 ...

How do I authenticate AWS using Terraform?

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.


2 Answers

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
}
like image 127
mellifluous Avatar answered Nov 02 '22 05:11

mellifluous


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

like image 23
Kevin Duterne Avatar answered Nov 02 '22 06:11

Kevin Duterne