-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parameterize customer_managed_policies path
Make customer-managed policies configurable using a custom path instead of the current hard-coded "/" value. Retains the current behavior, so these entries can either be a set of strings or a set of objects with `name` and `path` (new behavior).
- Loading branch information
Showing
7 changed files
with
262 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
This directory contains examples of using the module to create users and groups and assign permissions with **Inline Policies**. | ||
|
||
**IMPORTANT:** Ensure that the name of your object matches the name of your principal (e.g. user name or group name). See the following example with object/principal names 'Admin' and 'nuzumaki': | ||
|
||
```hcl | ||
sso_groups = { | ||
Admin : { | ||
group_name = "Admin" | ||
group_description = "Admin IAM Identity Center Group" | ||
}, | ||
} | ||
// Create desired USERS in IAM Identity Center | ||
sso_users = { | ||
nuzumaki : { | ||
group_membership = ["Admin",] | ||
user_name = "nuzumaki" | ||
given_name = "Naruto" | ||
family_name = "Uzumaki" | ||
email = "[email protected]" | ||
}, | ||
} | ||
``` | ||
|
||
These names are referenced throughout the module. Failure to do this may lead to unintentional errors such as the following: | ||
|
||
``` | ||
Error: Invalid index | ||
│ | ||
│ on ../../main.tf line 141, in resource "aws_identitystore_group_membership" "sso_group_membership": | ||
│ 141: member_id = (contains(local.this_users, each.value.user_name) ? aws_identitystore_user.sso_users[each.value.user_name].user_id : data.aws_identitystore_user.existing_sso_users[each.value.user_name].id) | ||
│ ├──────────────── | ||
│ │ aws_identitystore_user.sso_users is object with 2 attributes | ||
│ │ each.value.user_name is "nuzumaki" | ||
│ | ||
│ The given key does not identify an element in this collection value. | ||
``` | ||
|
||
To resolve this, ensure your object and principal names are the same and re-run `terraform plan` and `terraform apply`. |
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,72 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
This directory contains examples of using the module to create users and groups and assign permissions with **Inline Policies**. | ||
|
||
**IMPORTANT:** Ensure that the name of your object matches the name of your principal (e.g. user name or group name). See the following example with object/principal names 'Admin' and 'nuzumaki': | ||
|
||
```hcl | ||
sso_groups = { | ||
Admin : { | ||
group_name = "Admin" | ||
group_description = "Admin IAM Identity Center Group" | ||
}, | ||
} | ||
// Create desired USERS in IAM Identity Center | ||
sso_users = { | ||
nuzumaki : { | ||
group_membership = ["Admin",] | ||
user_name = "nuzumaki" | ||
given_name = "Naruto" | ||
family_name = "Uzumaki" | ||
email = "[email protected]" | ||
}, | ||
} | ||
``` | ||
|
||
These names are referenced throughout the module. Failure to do this may lead to unintentional errors such as the following: | ||
|
||
``` | ||
Error: Invalid index | ||
│ | ||
│ on ../../main.tf line 141, in resource "aws_identitystore_group_membership" "sso_group_membership": | ||
│ 141: member_id = (contains(local.this_users, each.value.user_name) ? aws_identitystore_user.sso_users[each.value.user_name].user_id : data.aws_identitystore_user.existing_sso_users[each.value.user_name].id) | ||
│ ├──────────────── | ||
│ │ aws_identitystore_user.sso_users is object with 2 attributes | ||
│ │ each.value.user_name is "nuzumaki" | ||
│ | ||
│ The given key does not identify an element in this collection value. | ||
``` | ||
|
||
To resolve this, ensure your object and principal names are the same and re-run `terraform plan` and `terraform apply`. | ||
|
||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_aws-iam-identity-center"></a> [aws-iam-identity-center](#module\_aws-iam-identity-center) | ../.. | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_organizations_organization.org](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END_TF_DOCS --> |
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,14 @@ | ||
# Fetch Account Id from SSM Parameter Store | ||
data "aws_ssm_parameter" "account1_account_id" { | ||
name = "tf-aws-iam-idc-module-testing-account1-account-id" // replace with your SSM Parameter Key | ||
} | ||
|
||
locals { | ||
# Account IDs | ||
account1_account_id = nonsensitive(data.aws_ssm_parameter.account1_account_id.value) | ||
# account1_account_id = "111111111111" | ||
# account2_account_id = "222222222222" | ||
# account3_account_id = "333333333333" | ||
# account4_account_id = "444444444444" | ||
|
||
} |
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,112 @@ | ||
data "aws_organizations_organization" "org" {} | ||
|
||
module "aws-iam-identity-center" { | ||
source = "../.." // local example | ||
# source = "aws-ia/iam-identity-center/aws" // remote example | ||
|
||
existing_sso_groups = { | ||
AWSControlTowerAdmins : { | ||
group_name = "AWSControlTowerAdmins" # this must be the name of a sso group that already exists in your AWS account | ||
} | ||
} | ||
|
||
sso_groups = { | ||
Admin : { | ||
group_name = "Admin" | ||
group_description = "Admin Group" | ||
}, | ||
Dev : { | ||
group_name = "Dev" | ||
group_description = "Dev Group" | ||
}, | ||
} | ||
sso_users = { | ||
nuzumaki : { | ||
group_membership = ["Admin", "Dev", "AWSControlTowerAdmins"] | ||
user_name = "nuzumaki" | ||
given_name = "Naruto" | ||
family_name = "Uzumaki" | ||
email = "[email protected]" | ||
}, | ||
suchiha : { | ||
group_membership = ["Dev", "AWSControlTowerAdmins"] | ||
user_name = "suchiha" | ||
given_name = "Sasuke" | ||
family_name = "Uchiha" | ||
email = "[email protected]" | ||
}, | ||
} | ||
|
||
existing_permission_sets = { | ||
AWSAdministratorAccess : { | ||
permission_set_name = "AWSAdministratorAccess" # this must be the name of a permission set that already exists in your AWS account | ||
}, | ||
} | ||
|
||
permission_sets = { | ||
AdministratorAccess = { | ||
description = "Provides full access to AWS services and resources", | ||
session_duration = "PT3H", | ||
aws_managed_policies = ["arn:aws:iam::aws:policy/AdministratorAccess"] | ||
|
||
customer_managed_policies = [ | ||
"MyExampleOrgAdminAccess", | ||
] | ||
|
||
tags = { ManagedBy = "Terraform" } | ||
}, | ||
ViewOnlyAccess = { | ||
description = "This policy grants permissions to view resources and basic metadata across all AWS services", | ||
session_duration = "PT3H", | ||
aws_managed_policies = ["arn:aws:iam::aws:policy/job-function/ViewOnlyAccess"] | ||
managed_policy_arn = "arn:aws:iam::aws:policy/job-function/ViewOnlyAccess" | ||
|
||
customer_managed_policies = [ | ||
{ | ||
name = "MyExampleOrgViewOnlyAccess" | ||
path = "/foo/example/" | ||
} | ||
] | ||
|
||
permissions_boundary = { | ||
managed_policy_arn = "arn:aws:iam::aws:policy/job-function/ViewOnlyAccess" | ||
} | ||
tags = { ManagedBy = "Terraform" } | ||
}, | ||
} | ||
account_assignments = { | ||
Admin : { | ||
principal_name = "Admin" | ||
principal_type = "GROUP" | ||
principal_idp = "INTERNAL" | ||
permission_sets = [ | ||
"AdministratorAccess", | ||
"ViewOnlyAccess", | ||
// existing permission set | ||
"AWSAdministratorAccess", | ||
] | ||
account_ids = [ | ||
// replace with your own account id | ||
local.account1_account_id, | ||
# local.account2_account_id | ||
# local.account3_account_id | ||
# local.account4_account_id | ||
] | ||
}, | ||
Dev : { | ||
principal_name = "Dev" | ||
principal_type = "GROUP" | ||
principal_idp = "INTERNAL" | ||
permission_sets = [ | ||
"ViewOnlyAccess", | ||
] | ||
account_ids = [ | ||
// replace with your own account id | ||
local.account1_account_id, | ||
# local.account2_account_id | ||
# local.account3_account_id | ||
# local.account4_account_id | ||
] | ||
}, | ||
} | ||
} |
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,13 @@ | ||
run "unit_test" { | ||
command = plan | ||
module { | ||
source = "./examples/customer-managed-policies" | ||
} | ||
} | ||
|
||
run "e2e_test" { | ||
command = apply | ||
module { | ||
source = "./examples/customer-managed-policies" | ||
} | ||
} |