Skip to content

Commit 3914d3b

Browse files
joshmyersosterman
authored andcommitted
[iam] Use account remote state to fetch sub account IDs (#63)
* Use account remote state to fetch sub account IDs So that we don’t need to hardcode these as vars in the top root Dockerfile. * avoid sprawl of variable names. upgrde org module. * add accounts and enabled flag * fix typo * Fix descriptions
1 parent 0aaa1d4 commit 3914d3b

16 files changed

+128
-64
lines changed

aws/iam/audit.auto.tfvars.example

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

aws/iam/audit.tf

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
variable "audit_account_id" {
2-
type = "string"
3-
description = "Audit account ID"
4-
}
5-
61
variable "audit_account_user_names" {
72
type = "list"
8-
description = "IAM user names to grant access to Audit account"
3+
description = "IAM user names to grant access to the `audit` account"
4+
default = []
95
}
106

117
# Provision group access to audit account. Careful! Very few people, if any should have access to this account.
128
module "organization_access_group_audit" {
13-
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.3"
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "audit") == true ? "true" : "false"}"
1411
namespace = "${var.namespace}"
1512
stage = "audit"
1613
name = "admin"
17-
user_names = ["${var.audit_account_user_names}"]
18-
member_account_id = "${var.audit_account_id}"
14+
user_names = "${var.audit_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.audit_account_id}"
1916
require_mfa = "true"
2017
}

aws/iam/corp.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "corp_account_user_names" {
2+
type = "list"
3+
description = "IAM user names to grant access to the `corp` account"
4+
default = []
5+
}
6+
7+
# Provision group access to corp account
8+
module "organization_access_group_corp" {
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "corp") == true ? "true" : "false"}"
11+
namespace = "${var.namespace}"
12+
stage = "corp"
13+
name = "admin"
14+
user_names = "${var.corp_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.corp_account_id}"
16+
require_mfa = "true"
17+
}

aws/iam/data.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "data_account_user_names" {
2+
type = "list"
3+
description = "IAM user names to grant access to the `data` account"
4+
default = []
5+
}
6+
7+
# Provision group access to data account
8+
module "organization_access_group_data" {
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "data") == true ? "true" : "false"}"
11+
namespace = "${var.namespace}"
12+
stage = "data"
13+
name = "admin"
14+
user_names = "${var.data_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.data_account_id}"
16+
require_mfa = "true"
17+
}

aws/iam/dev.auto.tfvars.example

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

aws/iam/dev.tf

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
variable "dev_account_id" {
2-
type = "string"
3-
description = "Dev account ID"
4-
}
5-
61
variable "dev_account_user_names" {
72
type = "list"
8-
description = "IAM user names to grant access to Dev account"
3+
description = "IAM user names to grant access to the `dev` account"
4+
default = []
95
}
106

117
# Provision group access to dev account
128
module "organization_access_group_dev" {
13-
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.3"
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "dev") == true ? "true" : "false"}"
1411
namespace = "${var.namespace}"
1512
stage = "dev"
1613
name = "admin"
17-
user_names = ["${var.dev_account_user_names}"]
18-
member_account_id = "${var.dev_account_id}"
14+
user_names = "${var.dev_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.dev_account_id}"
1916
require_mfa = "true"
2017
}

aws/iam/identity.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "identity_account_user_names" {
2+
type = "list"
3+
description = "IAM user names to grant access to the `identity` account"
4+
default = []
5+
}
6+
7+
# Provision group access to identity account
8+
module "organization_access_group_identity" {
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "identity") == true ? "true" : "false"}"
11+
namespace = "${var.namespace}"
12+
stage = "identity"
13+
name = "admin"
14+
user_names = "${var.identity_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.identity_account_id}"
16+
require_mfa = "true"
17+
}

aws/iam/main.tf

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ terraform {
44
backend "s3" {}
55
}
66

7-
variable "aws_assume_role_arn" {
8-
type = "string"
9-
}
10-
11-
variable "namespace" {
12-
type = "string"
13-
description = "Namespace (e.g. `cp` or `cloudposse`)"
14-
}
15-
167
provider "aws" {
178
assume_role {
189
role_arn = "${var.aws_assume_role_arn}"
1910
}
2011
}
12+
13+
data "terraform_remote_state" "accounts" {
14+
backend = "s3"
15+
16+
config {
17+
bucket = "${var.namespace}-${var.stage}-terraform-state"
18+
key = "accounts/terraform.tfstate"
19+
}
20+
}
21+
22+
locals {}

aws/iam/prod.auto.tfvars.example

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

aws/iam/prod.tf

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
variable "prod_account_id" {
2-
type = "string"
3-
description = "Production account ID"
4-
}
5-
61
variable "prod_account_user_names" {
72
type = "list"
8-
description = "IAM user names to grant access to Production account"
3+
description = "IAM user names to grant access to the `prod` account"
4+
default = []
95
}
106

117
# Provision group access to production account
128
module "organization_access_group_prod" {
13-
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.1.3"
9+
source = "git::https://github.com/cloudposse/terraform-aws-organization-access-group.git?ref=tags/0.2.1"
10+
enabled = "${contains(var.accounts_enabled, "prod") == true ? "true" : "false"}"
1411
namespace = "${var.namespace}"
1512
stage = "prod"
1613
name = "admin"
17-
user_names = ["${var.prod_account_user_names}"]
18-
member_account_id = "${var.prod_account_id}"
14+
user_names = "${var.prod_account_user_names}"
15+
member_account_id = "${data.terraform_remote_state.accounts.prod_account_id}"
1916
require_mfa = "true"
2017
}

0 commit comments

Comments
 (0)