Skip to content

Commit dce9c9d

Browse files
Merge pull request #21 from infraspecdev/refactor/account-id-assignment
chore: Update account id assignment using data source
2 parents fe70fd0 + 1f95600 commit dce9c9d

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

modules/account_users_and_groups_assignments/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ No modules.
3131
| [null_resource.sso_user_dependency](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
3232
| [aws_identitystore_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/identitystore_group) | data source |
3333
| [aws_identitystore_user.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/identitystore_user) | data source |
34+
| [aws_organizations_organization.o](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
3435
| [aws_ssoadmin_instances.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssoadmin_instances) | data source |
3536
| [aws_ssoadmin_permission_set.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssoadmin_permission_set) | data source |
3637

3738
## Inputs
3839

3940
| Name | Description | Type | Default | Required |
4041
|------|-------------|------|---------|:--------:|
41-
| <a name="input_account_assignments"></a> [account\_assignments](#input\_account\_assignments) | A list of objects representing permission assignments for AWS SSO. Each object contains the following attributes:<br> - account\_id: The AWS account ID where the permissions will be applied.<br> - permission\_sets: List of permission-set to be assigned to the specified principals.<br> - principal\_names: An identifier for an object in AWS SSO, such as the names of groups or users .<br> - principal\_type:The entity type for which the assignment will be created. Valid values: USER, GROUP. | <pre>list(object({<br> account_id = string<br> permission_sets = list(string)<br> principal_names = list(string)<br> principal_type = string<br> }))</pre> | n/a | yes |
42+
| <a name="input_account_assignments"></a> [account\_assignments](#input\_account\_assignments) | A list of objects representing permission assignments for AWS SSO. Each object contains the following attributes:<br> - account\_name: The AWS account where the permissions will be applied.<br> - permission\_sets: List of permission-set to be assigned to the specified principals.<br> - principal\_names: An identifier for an object in AWS SSO, such as the names of groups or users .<br> - principal\_type:The entity type for which the assignment will be created. Valid values: USER, GROUP. | <pre>list(object({<br> account_name = string<br> permission_sets = list(string)<br> principal_names = list(string)<br> principal_type = string<br> }))</pre> | n/a | yes |
4243
| <a name="input_identitystore_group_depends_on"></a> [identitystore\_group\_depends\_on](#input\_identitystore\_group\_depends\_on) | A list of parameters (For example group IDs)to use for data resources to depend on. This is to avoid module depends\_on as that will unnecessarily create the module resources | `list(string)` | `[]` | no |
4344
| <a name="input_identitystore_permission_set_depends_on"></a> [identitystore\_permission\_set\_depends\_on](#input\_identitystore\_permission\_set\_depends\_on) | A list of parameters (For example permission set ARNs)to use for data resources to depend on. This is to avoid module depends\_on as that will unnecessarily create the module resources | `list(string)` | `[]` | no |
4445
| <a name="input_identitystore_user_depends_on"></a> [identitystore\_user\_depends\_on](#input\_identitystore\_user\_depends\_on) | A list of parameters (For example user IDs)to use for data resources to depend on. This is to avoid module depends\_on as that will unnecessarily create the module resources | `list(string)` | `[]` | no |

modules/account_users_and_groups_assignments/data.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
data "aws_organizations_organization" "o" {}
2+
13
resource "null_resource" "sso_group_dependency" {
24
triggers = {
35
dependency_id = join(",", var.identitystore_group_depends_on)

modules/account_users_and_groups_assignments/locals.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

22
locals {
3+
4+
account_map = {
5+
for account in data.aws_organizations_organization.o.accounts : account.name => account.id
6+
}
7+
38
target_type = "AWS_ACCOUNT"
49
flatten_account_group_permission = flatten([
510
for acc_assignment in var.account_assignments : [
611
for ps_name in acc_assignment.permission_sets : [
712
for pr_name in acc_assignment.principal_names : {
8-
acc_id = acc_assignment.account_id
13+
acc_id = account_map[acc_assignment.account_name]
914
principal_name = pr_name
1015
ps_name = ps_name
1116
principal_type = acc_assignment.principal_type

modules/account_users_and_groups_assignments/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
variable "account_assignments" {
22
description = <<EOF
33
A list of objects representing permission assignments for AWS SSO. Each object contains the following attributes:
4-
- account_id: The AWS account ID where the permissions will be applied.
4+
- account_name: The AWS account where the permissions will be applied.
55
- permission_sets: List of permission-set to be assigned to the specified principals.
66
- principal_names: An identifier for an object in AWS SSO, such as the names of groups or users .
77
- principal_type:The entity type for which the assignment will be created. Valid values: USER, GROUP.
88
EOF
99
type = list(object({
10-
account_id = string
10+
account_name = string
1111
permission_sets = list(string)
1212
principal_names = list(string)
1313
principal_type = string
1414
}))
1515

1616
validation {
17-
condition = alltrue([for a in var.account_assignments : can(regex("^\\d{12}$", a.account_id))])
18-
error_message = "Each account_id must be a valid 12-digit number."
17+
condition = alltrue([for a in var.account_assignments : length(a.account_name) > 0])
18+
error_message = "Account name cannot be empty"
1919
}
2020
validation {
2121
condition = alltrue([for a in var.account_assignments : length(a.permission_sets) > 0])

0 commit comments

Comments
 (0)