Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions master-account/accounts.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
// | |- testing
// | |- development
// | |- forensics



// TODO loop over local.subaccounts
// Docs: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_create.html
// To set password go to root sign up and enter email
resource "aws_organizations_account" "main" {
count = "${length(var.sub_accounts)}"
name = "${var.sub_accounts[count.index]}"
email = "${local.account_email_local_part}+${var.sub_accounts[count.index]}@${local.account_email_domain}"
iam_user_access_to_billing = "DENY"
count = "${length(var.sub_accounts)}"
name = "${var.sub_accounts[count.index]}"
email = "${local.account_email_local_part}+${var.sub_accounts[count.index]}@${local.account_email_domain}"

#iam_user_access_to_billing = "DENY"
}

# Org Units - TODO https://github.com/terraform-providers/terraform-provider-aws/pull/4207



// https://www.terraform.io/docs/providers/aws/r/organizations_policy_attachment.html
//resource "aws_organizations_policy_attachment" "environments" {
// policy_id = "${aws_organizations_policy.environments.id}"
Expand All @@ -44,3 +39,4 @@ resource "aws_organizations_account" "main" {
//}
//POLICY
//}

10 changes: 4 additions & 6 deletions master-account/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

resource "aws_organizations_organization" "account" {
feature_set = "ALL"
}
# resource "aws_organizations_organization" "account" {
# feature_set = "ALL"
# }

resource "aws_iam_account_alias" "alias" {
count = "${var.account_alias == "" ? 0 : 1}"
count = "${var.account_alias == "" ? 0 : 1}"
account_alias = "${var.account_alias}"
}

11 changes: 6 additions & 5 deletions master-account/variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
variable "name" {}

variable "account_alias" {
type = "string"
type = "string"
default = ""
}

//
variable "roles" {
type = "list"
default = ["admin","developer"]
type = "list"
default = ["admin", "developer"]
}

// {username:[role,role]}
Expand All @@ -20,19 +21,19 @@ variable "roles" {
// type = "string"
//}


variable "account_email" {
description = "Organization account email"
}

variable "sub_accounts" {
type = "list"

default = [
"operations",
"production",
"staging",
"testing",
"development",
"forensics"
"forensics",
]
}
8 changes: 5 additions & 3 deletions user/send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ ENC_PASSWORD="$5" # PGP encrypted password
# Uncomment following if using keybase
# PASSWORD=$(base64 --decode | keybase pgp decrypt)

# Create a temporary file to store the encrypted binary data.
password_file=$(mktemp "password.${USERNAME}.gpg")
# Create a temporary file to store the encrypted binary data.
#.XXXXX is needed due to a an error on ubuntu - "mktemp: too few X's in template" - rtomayko/shocco#5
password_file=$(mktemp "password.${USERNAME}.gpg.XXXXX")

# Decode the Base64 password and store it in password file.
echo "$ENC_PASSWORD" | base64 --decode > "$password_file"
Expand All @@ -40,7 +41,8 @@ PASSWORD=$(gpg -q --decrypt "$password_file")
rm "$password_file"

# Create a temporary file to store the HTML email body.
message_file=$(mktemp "message.${USERNAME}.html")
#.XXXXX is needed due to a an error on ubuntu - "mktemp: too few X's in template" - rtomayko/shocco#5
message_file=$(mktemp "message.${USERNAME}.html.XXXXX")

# Replace username and passwords with correct values.
cat "$DIR/send-email.html.tpl" > ${message_file}
Expand Down