Skip to content

Commit bd7bbf4

Browse files
authored
Merge pull request #10 from infraspecdev/feat/permission_sets
feat: Permission sets
2 parents 3df107b + de0afd0 commit bd7bbf4

File tree

16 files changed

+387
-0
lines changed

16 files changed

+387
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
locals {
2+
aws_region = "us-east-1"
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module "permission_sets" {
2+
source = "../../modules/permission_sets"
3+
4+
permission_sets = var.permission_sets
5+
}

examples/create-permission-set/outputs.tf

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = local.aws_region
3+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
variable "permission_sets" {
2+
description = <<EOF
3+
(Required)A map of permission set objects with key as the permission set name. Each object contains:
4+
- name: The name of the permission set.
5+
- description: A brief description of the permission set.
6+
- session_duration: Optional session duration for the permission set (default is null).
7+
- relay_state: Optional relay state for the permission set (default is null).
8+
- tags: Optional map of tags to associate with the permission set.
9+
- inline_policy: The inline policy content in JSON format.
10+
- managed_policies: A list of ARNs of managed policies to attach to the permission set.
11+
- customer_managed_policies: A list of customer-managed policies to attach to the permission set. Each policy includes:
12+
- name: The name of the customer-managed policy.
13+
- path: The path of the customer-managed policy (default is "/").
14+
EOF
15+
type = map(object({
16+
name = string
17+
description = string
18+
session_duration = optional(string, null)
19+
relay_state = optional(string, null)
20+
tags = optional(map(string))
21+
inline_policy = string
22+
managed_policies = list(string)
23+
customer_managed_policies = list(object({
24+
name = string
25+
path = optional(string, "/")
26+
}))
27+
}))
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.4.6"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.65.0"
8+
}
9+
}
10+
}

modules/permission_sets/.header.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Terraform AWS Organizations Permission-Sets Module
2+
A Terraform module for creating and managing AWS SSO (Single Sign-On) Permission Sets within AWS Organizations

modules/permission_sets/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Requirements
2+
3+
| Name | Version |
4+
|------|---------|
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.4.6 |
6+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.65.0 |
7+
8+
## Providers
9+
10+
| Name | Version |
11+
|------|---------|
12+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.58.0 |
13+
14+
## Modules
15+
16+
No modules.
17+
18+
## Resources
19+
20+
| Name | Type |
21+
|------|------|
22+
| [aws_ssoadmin_customer_managed_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_customer_managed_policy_attachment) | resource |
23+
| [aws_ssoadmin_managed_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_managed_policy_attachment) | resource |
24+
| [aws_ssoadmin_permission_set.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_permission_set) | resource |
25+
| [aws_ssoadmin_permission_set_inline_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssoadmin_permission_set_inline_policy) | resource |
26+
| [aws_ssoadmin_instances.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssoadmin_instances) | data source |
27+
28+
## Inputs
29+
30+
| Name | Description | Type | Default | Required |
31+
|------|-------------|------|---------|:--------:|
32+
| <a name="input_permission_sets"></a> [permission\_sets](#input\_permission\_sets) |(Required) A map of permission set objects with permission set name as the key. Each object contains:<br> - name: The name of the permission set.<br> - description: A brief description of the permission set.<br> - session\_duration: Optional session duration for the permission set (default is PT1H).<br> - relay\_state: Optional relay state for the permission set (default is null).<br> - tags: Optional map of tags to associate with the permission set.<br> - inline\_policy: The inline policy content in JSON format.<br> - managed\_policies: A list of ARNs of managed policies to attach to the permission set.<br> - customer\_managed\_policies: A list of customer-managed policies to attach to the permission set. Each policy includes:<br> - name: The name of the customer-managed policy.<br> - path: The path of the customer-managed policy (default is "/"). | <pre>map(object({<br> name = string<br> description = string<br> session_duration = optional(string, null)<br> relay_state = optional(string, null)<br> tags = optional(map(string))<br> inline_policy = string # Inline policy <br> managed_policies = list(string) # list of ARN's of managed policies<br> customer_managed_policies = list(object({<br> name = string<br> path = optional(string, "/") # list of customer-managed policies with their names and paths to be attached to each.<br> }))<br> }))</pre> | n/a | yes |
33+
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) Key-value map of resource tags. | `map(string)` | `null` | no |
34+
35+
## Outputs
36+
37+
| Name | Description |
38+
|------|-------------|
39+
| <a name="output_permission_sets"></a> [permission\_sets](#output\_permission\_sets) | A map of the permission sets that were created. Each key is the name of the permission set, and the value contains the details of the created permission set. |

modules/permission_sets/data.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "aws_ssoadmin_instances" "default" {}

modules/permission_sets/locals.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
locals {
2+
sso_instance_arn = tolist(data.aws_ssoadmin_instances.default.arns)[0]
3+
permission_set_map = { for ps_name, ps in var.permission_sets : ps_name => ps }
4+
inline_policies_map = { for ps_name, ps in var.permission_sets : ps_name => ps.inline_policy if ps.inline_policy != "" }
5+
managed_policy_map = { for ps_name, ps in var.permission_sets : ps_name => ps.managed_policies if length(ps.managed_policies) > 0 }
6+
managed_policy_attachments = flatten([
7+
for ps_name, policy_list in local.managed_policy_map : [
8+
for policy_arn in policy_list : {
9+
ps_name = ps_name
10+
policy_arn = policy_arn
11+
}
12+
]
13+
])
14+
managed_policy_attachments_map = {
15+
for policy in local.managed_policy_attachments : "${policy.ps_name}.${policy.policy_arn}" => policy
16+
}
17+
customer_managed_policy_map = { for ps_name, ps in var.permission_sets : ps_name => ps.customer_managed_policies if length(ps.customer_managed_policies) > 0 }
18+
customer_managed_policy_attachments = flatten([
19+
for ps_name, policy_list in local.customer_managed_policy_map : [
20+
for policy in policy_list : {
21+
ps_name = ps_name
22+
policy_name = policy.name
23+
policy_path = policy.path
24+
}
25+
]
26+
])
27+
customer_managed_policy_attachments_map = {
28+
for policy in local.customer_managed_policy_attachments : "${policy.ps_name}.${policy.policy_path}${policy.policy_name}" => policy
29+
}
30+
}

0 commit comments

Comments
 (0)