Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URLs for switching roles #15

Merged
merged 3 commits into from
Jan 2, 2019
Merged
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Available targets:
| readonly_name | Name for the readonly group and role (e.g. `readonly`) | string | `readonly` | no |
| readonly_user_names | Optional list of IAM user names to add to the readonly group | list | `<list>` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| switchrole_url | URL to the IAM console to switch to a role | string | `https://signin.aws.amazon.com/switchrole?account=%s&roleName=%s&displayName=%s` | no |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |

## Outputs
Expand All @@ -106,6 +107,8 @@ Available targets:
| role_admin_name | Admin role name |
| role_readonly_arn | Readonly role ARN |
| role_readonly_name | Readonly role name |
| switchrole_admin_url | URL to the IAM console to switch to the admin role |
| switchrole_readonly_url | URL to the IAM console to switch to the readonly role |



Expand Down Expand Up @@ -192,7 +195,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down
3 changes: 3 additions & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| readonly_name | Name for the readonly group and role (e.g. `readonly`) | string | `readonly` | no |
| readonly_user_names | Optional list of IAM user names to add to the readonly group | list | `<list>` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| switchrole_url | URL to the IAM console to switch to a role | string | `https://signin.aws.amazon.com/switchrole?account=%s&roleName=%s&displayName=%s` | no |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |

## Outputs
Expand All @@ -27,4 +28,6 @@
| role_admin_name | Admin role name |
| role_readonly_arn | Readonly role ARN |
| role_readonly_name | Readonly role name |
| switchrole_admin_url | URL to the IAM console to switch to the admin role |
| switchrole_readonly_url | URL to the IAM console to switch to the readonly role |

5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,8 @@ resource "aws_iam_group_membership" "readonly" {
group = "${join("", aws_iam_group.readonly.*.id)}"
users = ["${var.readonly_user_names}"]
}

locals {
role_readonly_name = "${join("", aws_iam_role.readonly.*.name)}"
role_admin_name = "${join("", aws_iam_role.admin.*.name)}"
}
16 changes: 14 additions & 2 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Group outputs
#
output "group_admin_id" {
Expand Down Expand Up @@ -30,6 +31,7 @@ output "group_readonly_name" {
description = "Readonly group name"
}

#
# Role outputs
#
output "role_admin_arn" {
Expand All @@ -38,7 +40,7 @@ output "role_admin_arn" {
}

output "role_admin_name" {
value = "${join("", aws_iam_role.admin.*.name)}"
value = "${local.role_admin_name}"
description = "Admin role name"
}

Expand All @@ -48,6 +50,16 @@ output "role_readonly_arn" {
}

output "role_readonly_name" {
value = "${join("", aws_iam_role.readonly.*.name)}"
value = "${local.role_readonly_name}"
description = "Readonly role name"
}

output "switchrole_admin_url" {
description = "URL to the IAM console to switch to the admin role"
value = "${local.enabled ? format(var.switchrole_url, data.aws_caller_identity.current.account_id, local.role_admin_name, local.role_admin_name) : ""}"
}

output "switchrole_readonly_url" {
description = "URL to the IAM console to switch to the readonly role"
value = "${local.enabled ? format(var.switchrole_url, data.aws_caller_identity.current.account_id, local.role_readonly_name, local.role_readonly_name) : ""}"
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ variable "readonly_user_names" {
default = []
description = "Optional list of IAM user names to add to the readonly group"
}

variable "switchrole_url" {
type = "string"
description = "URL to the IAM console to switch to a role"
default = "https://signin.aws.amazon.com/switchrole?account=%s&roleName=%s&displayName=%s"
}