diff --git a/README.md b/README.md index f6a75c4..dbd0bbb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A Terraform module that creates an IAM role. | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 4.0.0 | +| [aws](#provider\_aws) | 5.78.0 | ## Modules @@ -33,12 +33,13 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| [name](#input\_name) | The name of the role | `string` | n/a | yes | | [assume\_policy](#input\_assume\_policy) | The assume policy to attach to the role | `string` | `null` | no | | [create\_policy](#input\_create\_policy) | Overrule whether the IAM role policy has to be created | `bool` | `null` | no | | [description](#input\_description) | The description of the role | `string` | `null` | no | | [force\_detach\_policies](#input\_force\_detach\_policies) | Force detaching any policies the role has before destroying it | `bool` | `false` | no | | [max\_session\_duration](#input\_max\_session\_duration) | The maximum session duration (in seconds) for the role | `number` | `3600` | no | +| [name](#input\_name) | The name of the role. Conflicts with `name_prefix`. | `string` | `null` | no | +| [name\_prefix](#input\_name\_prefix) | Creates a unique role and policy name beginning with the specified prefix. Conflicts with `name`. | `string` | `null` | no | | [path](#input\_path) | Path to the role | `string` | `"/"` | no | | [permissions\_boundary](#input\_permissions\_boundary) | The permissions boundary to set on the role | `string` | `null` | no | | [policy\_arns](#input\_policy\_arns) | A set of policy ARNs to attach to the user | `set(string)` | `[]` | no | @@ -56,4 +57,4 @@ No modules. | [id](#output\_id) | ID of the role | | [name](#output\_name) | The name of the role | | [unique\_id](#output\_unique\_id) | Unique ID of the role | - \ No newline at end of file + diff --git a/examples/basic/.terraform.lock.hcl b/examples/basic/.terraform.lock.hcl new file mode 100644 index 0000000..3d167e1 --- /dev/null +++ b/examples/basic/.terraform.lock.hcl @@ -0,0 +1,25 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/aws" { + version = "5.78.0" + constraints = ">= 4.0.0" + hashes = [ + "h1:o7jz+dFixEcwjfdubken5ldmDJm1tkvM2adPtNDei3g=", + "zh:0ae7d41b96441d0cf7ce2e1337657bdb2e1e5c9f1c2227b0642e1dcec2f9dfba", + "zh:21f8f1edf477681ea3b095c02cad6b8e85262e45015de58e84e0c7b2bfe9a1f6", + "zh:2bdc335e341bf98445255549ae93d66cfb9bca706e62b949da98fe467c182cad", + "zh:2fe4096e260367a225a9faf4a424d62b87e5498f12cb43bdb6f4e713d11b82c3", + "zh:3c63bb7a7925d65118d17461f4691a22dbb55ea39a7404e4d71f6ccca8765f8b", + "zh:6609a28a1c638a1901d8007b5386868ccfd313b4df2e98b35d9fdef436974e3b", + "zh:7ae3aef43bc4b365824cca4659cf92459d766800656e354bdbf83feabab835e8", + "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", + "zh:c314efe454adc6ca483261c6906e64315aeb9db0c0332818714e9b81e07df0f0", + "zh:cd3e30396b554bbc1d260252db8a0f344065d619038fe60ea870689cd32c6aa9", + "zh:d1ba48fd9d8a1cb1daa927fb9e8bb708b857f2792d796e110460c6fdcd896a47", + "zh:d31c8abe75cb9cdc1c59ad9d356a1c3ae1ba8cd29ac15eb7e01b6cd01221ab04", + "zh:dc27c5c2116b4d9b404753f73bccaa635bce21f3bfb4bb7bc8e63225c36c98fe", + "zh:de491f0d05408378413187475c815d8cb2ac6bfa63d0b42a30ad5ee492e51c07", + "zh:eb44b45a40f80a309dd5b0eb7d7fcb2cbfe588fe2f18b173ef5851346898a662", + ] +} diff --git a/main.tf b/main.tf index e45f29a..031ae6b 100644 --- a/main.tf +++ b/main.tf @@ -17,6 +17,7 @@ data "aws_iam_policy_document" "default" { resource "aws_iam_role" "default" { name = "${var.name}${var.postfix ? "Role" : ""}" + name_prefix = var.name_prefix assume_role_policy = local.assume_policy description = var.description force_detach_policies = var.force_detach_policies @@ -29,9 +30,10 @@ resource "aws_iam_role" "default" { resource "aws_iam_role_policy" "default" { count = local.create_policy ? 1 : 0 - name = "${var.name}${var.postfix ? "Policy" : ""}" - role = aws_iam_role.default.id - policy = var.role_policy + name = "${var.name}${var.postfix ? "Policy" : ""}" + name_prefix = var.name_prefix + role = aws_iam_role.default.id + policy = var.role_policy } resource "aws_iam_role_policy_attachment" "default" { diff --git a/variables.tf b/variables.tf index 5a8be95..953af9b 100644 --- a/variables.tf +++ b/variables.tf @@ -1,6 +1,23 @@ variable "name" { type = string - description = "The name of the role" + default = null + description = "The name of the role. Conflicts with `name_prefix`." + + validation { + condition = var.name != null ? length(var.name) <= 63 : true + error_message = "The name must be less than or equal to 63 characters in length" + } +} + +variable "name_prefix" { + type = string + default = null + description = "Creates a unique role and policy name beginning with the specified prefix. Conflicts with `name`." + + validation { + condition = var.name_prefix != null ? length(var.name_prefix) <= 37 : true + error_message = "The name prefix must be less than or equal to 37 characters in length" + } } variable "assume_policy" {