-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to admin role for terraform and access
- Loading branch information
Showing
4 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Role to be used for any administrative tasks | ||
data "aws_iam_policy_document" "administrator_assume_role_policy" { | ||
statement { | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = [aws_iam_user.ckdake.arn] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "administrator" { | ||
name = "administrator" | ||
assume_role_policy = data.aws_iam_policy_document.administrator_assume_role_policy.json | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "administrator_gets_administrator" { | ||
role = aws_iam_role.administrator.id | ||
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" | ||
} | ||
|
||
# Group of users allowed to assume the administrator role | ||
resource "aws_iam_group" "administrators" { | ||
name = "administrators" | ||
} | ||
|
||
resource "aws_iam_group_membership" "administrators" { | ||
name = "administrators" | ||
group = aws_iam_group.administrators.name | ||
|
||
users = [ | ||
aws_iam_user.ckdake.name, | ||
] | ||
} | ||
|
||
resource "aws_iam_policy" "admin_assumption" { | ||
name = "admin-assumption" | ||
description = "allow assuming the admin role" | ||
policy = jsonencode({ | ||
Version = "2012-10-17", | ||
Statement = [ | ||
{ | ||
Effect = "Allow", | ||
Action = "sts:AssumeRole", | ||
Resource = "${aws_iam_role.administrator.arn}" | ||
}] | ||
}) | ||
} | ||
|
||
resource "aws_iam_group_policy_attachment" "admin_assumption" { | ||
group = aws_iam_group.administrators.name | ||
policy_arn = aws_iam_policy.admin_assumption.arn | ||
} | ||
|
||
# Single user that can only assume to the administrator role | ||
resource "aws_iam_user" "ckdake" { | ||
name = "ckdake" | ||
force_destroy = true | ||
depends_on = [aws_iam_group.administrators] | ||
} | ||
|
||
resource "aws_iam_user_login_profile" "ckdake" { | ||
user = aws_iam_user.ckdake.name | ||
password_length = 32 | ||
password_reset_required = true | ||
|
||
lifecycle { | ||
ignore_changes = [ | ||
password_length, | ||
password_reset_required, | ||
pgp_key, | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters