Skip to content

Revert "chore: Update account id assignment using data source" #22

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions modules/account_users_and_groups_assignments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ No modules.
| [null_resource.sso_user_dependency](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource |
| [aws_identitystore_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/identitystore_group) | data source |
| [aws_identitystore_user.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/identitystore_user) | data source |
| [aws_organizations_organization.o](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/organizations_organization) | data source |
| [aws_ssoadmin_instances.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssoadmin_instances) | data source |
| [aws_ssoadmin_permission_set.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssoadmin_permission_set) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
2 changes: 0 additions & 2 deletions modules/account_users_and_groups_assignments/data.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
data "aws_organizations_organization" "o" {}

resource "null_resource" "sso_group_dependency" {
triggers = {
dependency_id = join(",", var.identitystore_group_depends_on)
Expand Down
7 changes: 1 addition & 6 deletions modules/account_users_and_groups_assignments/locals.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@

locals {

account_map = {
for account in data.aws_organizations_organization.o.accounts : account.name => account.id
}

target_type = "AWS_ACCOUNT"
flatten_account_group_permission = flatten([
for acc_assignment in var.account_assignments : [
for ps_name in acc_assignment.permission_sets : [
for pr_name in acc_assignment.principal_names : {
acc_id = account_map[acc_assignment.account_name]
acc_id = acc_assignment.account_id
principal_name = pr_name
ps_name = ps_name
principal_type = acc_assignment.principal_type
Expand Down
8 changes: 4 additions & 4 deletions modules/account_users_and_groups_assignments/variables.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
variable "account_assignments" {
description = <<EOF
A list of objects representing permission assignments for AWS SSO. Each object contains the following attributes:
- account_name: The AWS account where the permissions will be applied.
- account_id: The AWS account ID where the permissions will be applied.
- permission_sets: List of permission-set to be assigned to the specified principals.
- principal_names: An identifier for an object in AWS SSO, such as the names of groups or users .
- principal_type:The entity type for which the assignment will be created. Valid values: USER, GROUP.
EOF
type = list(object({
account_name = string
account_id = string
permission_sets = list(string)
principal_names = list(string)
principal_type = string
}))

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