Skip to content

Commit 028370c

Browse files
authored
[accounts] Enforce consistent email convention and add new accounts (#61)
* Simplify account creation rules * Add additional accounts
1 parent 5fc8cab commit 028370c

15 files changed

+117
-90
lines changed

aws/accounts/audit.auto.tfvars.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

aws/accounts/audit.tf

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
variable "audit_account_name" {
2-
type = "string"
3-
description = "Audit account name"
4-
default = "audit"
5-
}
6-
7-
variable "audit_account_email" {
8-
type = "string"
9-
description = "Audit account email"
10-
}
11-
121
resource "aws_organizations_account" "audit" {
13-
name = "${var.audit_account_name}"
14-
email = "${var.audit_account_email}"
2+
count = "${contains(var.accounts_enabled, "audit") == true ? 1 : 0}"
3+
name = "audit"
4+
email = "${format(var.account_email, "audit")}"
155
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
166
role_name = "${var.account_role_name}"
177
}
188

199
output "audit_account_arn" {
20-
value = "${aws_organizations_account.audit.arn}"
10+
value = "${join("", aws_organizations_account.audit.*.arn)}"
2111
}
2212

2313
output "audit_account_id" {
24-
value = "${aws_organizations_account.audit.id}"
14+
value = "${join("", aws_organizations_account.audit.*.id)}"
2515
}
2616

2717
output "audit_organization_account_access_role" {
28-
value = "arn:aws:iam::${aws_organizations_account.audit.id}:role/OrganizationAccountAccessRole"
18+
value = "arn:aws:iam::${join("", aws_organizations_account.audit.*.id)}:role/OrganizationAccountAccessRole"
2919
}

aws/accounts/corp.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_organizations_account" "corp" {
2+
count = "${contains(var.accounts_enabled, "corp") == true ? 1 : 0}"
3+
name = "corp"
4+
email = "${format(var.account_email, "corp")}"
5+
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
6+
role_name = "${var.account_role_name}"
7+
}
8+
9+
output "corp_account_arn" {
10+
value = "${join("", aws_organizations_account.corp.*.arn)}"
11+
}
12+
13+
output "corp_account_id" {
14+
value = "${join("", aws_organizations_account.corp.*.id)}"
15+
}
16+
17+
output "corp_organization_account_access_role" {
18+
value = "arn:aws:iam::${join("", aws_organizations_account.corp.*.id)}:role/OrganizationAccountAccessRole"
19+
}

aws/accounts/data.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_organizations_account" "data" {
2+
count = "${contains(var.accounts_enabled, "data") == true ? 1 : 0}"
3+
name = "data"
4+
email = "${format(var.account_email, "data")}"
5+
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
6+
role_name = "${var.account_role_name}"
7+
}
8+
9+
output "data_account_arn" {
10+
value = "${join("", aws_organizations_account.data.*.arn)}"
11+
}
12+
13+
output "data_account_id" {
14+
value = "${join("", aws_organizations_account.data.*.id)}"
15+
}
16+
17+
output "data_organization_account_access_role" {
18+
value = "arn:aws:iam::${join("", aws_organizations_account.data.*.id)}:role/OrganizationAccountAccessRole"
19+
}

aws/accounts/dev.auto.tfvars.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

aws/accounts/dev.tf

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
variable "dev_account_name" {
2-
type = "string"
3-
description = "Dev account name"
4-
default = "dev"
5-
}
6-
7-
variable "dev_account_email" {
8-
type = "string"
9-
description = "Dev account email"
10-
}
11-
121
resource "aws_organizations_account" "dev" {
13-
name = "${var.dev_account_name}"
14-
email = "${var.dev_account_email}"
2+
count = "${contains(var.accounts_enabled, "dev") == true ? 1 : 0}"
3+
name = "dev"
4+
email = "${format(var.account_email, "dev")}"
155
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
166
role_name = "${var.account_role_name}"
177
}
188

199
output "dev_account_arn" {
20-
value = "${aws_organizations_account.dev.arn}"
10+
value = "${join("", aws_organizations_account.dev.*.arn)}"
2111
}
2212

2313
output "dev_account_id" {
24-
value = "${aws_organizations_account.dev.id}"
14+
value = "${join("", aws_organizations_account.dev.*.id)}"
2515
}
2616

2717
output "dev_organization_account_access_role" {
28-
value = "arn:aws:iam::${aws_organizations_account.dev.id}:role/OrganizationAccountAccessRole"
18+
value = "arn:aws:iam::${join("", aws_organizations_account.dev.*.id)}:role/OrganizationAccountAccessRole"
2919
}

aws/accounts/identity.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_organizations_account" "identity" {
2+
count = "${contains(var.accounts_enabled, "identity") == true ? 1 : 0}"
3+
name = "identity"
4+
email = "${format(var.account_email, "identity")}"
5+
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
6+
role_name = "${var.account_role_name}"
7+
}
8+
9+
output "identity_account_arn" {
10+
value = "${join("", aws_organizations_account.identity.*.arn)}"
11+
}
12+
13+
output "identity_account_id" {
14+
value = "${join("", aws_organizations_account.identity.*.id)}"
15+
}
16+
17+
output "identity_organization_account_access_role" {
18+
value = "arn:aws:iam::${join("", aws_organizations_account.identity.*.id)}:role/OrganizationAccountAccessRole"
19+
}

aws/accounts/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,23 @@ variable "account_role_name" {
1414
default = "OrganizationAccountAccessRole"
1515
}
1616

17+
variable "account_email" {
18+
type = "string"
19+
description = "Email address format for accounts (e.g. `%[email protected]`)"
20+
}
21+
1722
variable "account_iam_user_access_to_billing" {
1823
type = "string"
1924
description = "If set to `ALLOW`, the new account enables IAM users to access account billing information if they have the required permissions. If set to `DENY`, then only the root user of the new account can access account billing information"
2025
default = "DENY"
2126
}
2227

28+
variable "accounts_enabled" {
29+
type = "list"
30+
description = "Accounts to enable"
31+
default = ["dev", "staging", "prod", "testing", "audit"]
32+
}
33+
2334
provider "aws" {
2435
assume_role {
2536
role_arn = "${var.aws_assume_role_arn}"

aws/accounts/prod.auto.tfvars.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

aws/accounts/prod.tf

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
1-
variable "prod_account_name" {
2-
type = "string"
3-
description = "Production account name"
4-
default = "prod"
5-
}
6-
7-
variable "prod_account_email" {
8-
type = "string"
9-
description = "Production account email"
10-
}
11-
121
resource "aws_organizations_account" "prod" {
13-
name = "${var.prod_account_name}"
14-
email = "${var.prod_account_email}"
2+
count = "${contains(var.accounts_enabled, "prod") == true ? 1 : 0}"
3+
name = "prod"
4+
email = "${format(var.account_email, "prod")}"
155
iam_user_access_to_billing = "${var.account_iam_user_access_to_billing}"
166
role_name = "${var.account_role_name}"
177
}
188

199
output "prod_account_arn" {
20-
value = "${aws_organizations_account.prod.arn}"
10+
value = "${join("", aws_organizations_account.prod.*.arn)}"
2111
}
2212

2313
output "prod_account_id" {
24-
value = "${aws_organizations_account.prod.id}"
14+
value = "${join("", aws_organizations_account.prod.*.id)}"
2515
}
2616

2717
output "prod_organization_account_access_role" {
28-
value = "arn:aws:iam::${aws_organizations_account.prod.id}:role/OrganizationAccountAccessRole"
18+
value = "arn:aws:iam::${join("", aws_organizations_account.prod.*.id)}:role/OrganizationAccountAccessRole"
2919
}

0 commit comments

Comments
 (0)