Skip to content

Commit

Permalink
Merge pull request #10 from ministryofjustice/random-email-address
Browse files Browse the repository at this point in the history
Generate random email address for: uniqueness and a managed character length
  • Loading branch information
jakemulley authored Jan 22, 2021
2 parents 4d3dbf6 + e22d3be commit d494041
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ locals {
}
}

# Generate a random string to use for an email address for each account
resource "random_string" "email-address" {
for_each = {
for account in local.applications.accounts : account.name => account
}

length = 16
special = false
upper = false
}

# Create each application an Organizational Unit
resource "aws_organizations_organizational_unit" "applications" {
for_each = toset(local.applications.organization_units)
Expand All @@ -33,10 +44,12 @@ resource "aws_organizations_organizational_unit" "applications" {
# Create each application's environments an account within their own Organizational Unit
resource "aws_organizations_account" "accounts" {
for_each = {
for account in local.applications.accounts : account.name => account
for account in local.applications.accounts : account.name => merge(account, {
email = "aws+mp+${random_string.email-address[account.name].result}@digital.justice.gov.uk"
})
}
name = each.value.name
email = "aws+mp+${each.value.name}@digital.justice.gov.uk"
email = each.value.email
iam_user_access_to_billing = "ALLOW"
parent_id = aws_organizations_organizational_unit.applications[each.value.part_of].id
tags = each.value.tags
Expand Down

0 comments on commit d494041

Please sign in to comment.