Skip to content

Commit d72f5de

Browse files
authored
Bootstrapping (#64)
* Add script to facilitate bootstrapping temporary roles * Add makefiles * Update docs * optional root admin names * Update aws/root-iam/README.md Co-Authored-By: osterman <[email protected]>
1 parent 3914d3b commit d72f5de

File tree

17 files changed

+130
-14
lines changed

17 files changed

+130
-14
lines changed

aws/account-settings/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/accounts/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/bootstrap/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
AWS_DEFAULT_REGION := us-east-1
2+
IAM_ROLE ?= bootstrap
3+
IAM_POLICY_ARN ?= arn:aws:iam::aws:policy/AdministratorAccess
4+
5+
export AWS_ROOT_ACCOUNT_ID=$(shell aws sts get-caller-identity --output text --query 'Account')
6+
7+
export ASSUME_ROLE_POLICY=$(shell envsubst < assume-role.json > /tmp/assume-role.json; echo file:///tmp/assume-role.json)
8+
9+
## Provision a temporary IAM role for bootstrapping
10+
create/iam-role:
11+
@aws iam create-role --role-name "$(IAM_ROLE)" --assume-role-policy-document "$(ASSUME_ROLE_POLICY)" >/dev/null
12+
@aws iam attach-role-policy --role-name "$(IAM_ROLE)" --policy-arn $(IAM_POLICY_ARN) >/dev/null
13+
@echo "The '$(IAM_ROLE) role has been created. Use '$(IAM_ROLE)' anywhere an assumed role is required."
14+
15+
## Destroy the temporary IAM role for bootstrapping
16+
delete/iam-role:
17+
@aws iam detach-role-policy --role-name "$(IAM_ROLE)" --policy-arn $(IAM_POLICY_ARN) >/dev/null
18+
@aws iam delete-role --role-name "$(IAM_ROLE)" > /dev/null
19+
@echo "The '$(IAM_ROLE)' role has been deleted"
20+
21+
list/iam-role:
22+
@aws iam list-roles | jq -r '.Roles | .[] | .RoleName + " " + .Arn' | xargs -n 2 printf '%-40s %s\n'

aws/bootstrap/assume-role.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Principal": { "AWS": "arn:aws:iam::$AWS_ACCOUNT_ID:root" },
7+
"Action": "sts:AssumeRole"
8+
}
9+
]
10+
}

aws/chamber/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/cloudtrail/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/iam/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/root-dns/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/root-iam/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
init:
2+
init-terraform
3+
4+
plan:
5+
terraform $@
6+
7+
apply:
8+
terraform $@
9+
10+
clean:
11+
rm -rf .terraform

aws/root-iam/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# root-iam
2+
3+
This module is responsible for setting up the access groups in the root account.
4+
5+
If provisioning this during a cold-start process, make sure you have `TF_VAR_aws_assume_role_arn` set to nil.

0 commit comments

Comments
 (0)