Skip to content

Commit 3cfe869

Browse files
GibbyGibbycloudpossebotnitrocode
authored
Add support for path and permissions_boundary to IAM role (#99)
* Add support for path and permissions_boundary to IAM role * Auto Format * Also need to support path for IAM policy * Auto Format * Update variables.tf * Auto Format Co-authored-by: Gibby <git@twoitguys> Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com> Co-authored-by: nitrocode <nitrocode@users.noreply.github.com>
1 parent 9a5a34f commit 3cfe869

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ Available targets:
239239
| <a name="input_git_clone_depth"></a> [git\_clone\_depth](#input\_git\_clone\_depth) | Truncate git history to this many commits. | `number` | `null` | no |
240240
| <a name="input_github_token"></a> [github\_token](#input\_github\_token) | (Optional) GitHub auth token environment variable (`GITHUB_TOKEN`) | `string` | `""` | no |
241241
| <a name="input_github_token_type"></a> [github\_token\_type](#input\_github\_token\_type) | Storage type of GITHUB\_TOKEN environment variable (`PARAMETER_STORE`, `PLAINTEXT`, `SECRETS_MANAGER`) | `string` | `"PARAMETER_STORE"` | no |
242+
| <a name="input_iam_permissions_boundary"></a> [iam\_permissions\_boundary](#input\_iam\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the role. | `string` | `null` | no |
243+
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path to the policy. | `string` | `"/service-role/"` | no |
244+
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the role. | `string` | `null` | no |
242245
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
243246
| <a name="input_image_repo_name"></a> [image\_repo\_name](#input\_image\_repo\_name) | (Optional) ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | `string` | `"UNSET"` | no |
244247
| <a name="input_image_tag"></a> [image\_tag](#input\_image\_tag) | (Optional) Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | `string` | `"latest"` | no |

docs/terraform.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
| <a name="input_git_clone_depth"></a> [git\_clone\_depth](#input\_git\_clone\_depth) | Truncate git history to this many commits. | `number` | `null` | no |
8080
| <a name="input_github_token"></a> [github\_token](#input\_github\_token) | (Optional) GitHub auth token environment variable (`GITHUB_TOKEN`) | `string` | `""` | no |
8181
| <a name="input_github_token_type"></a> [github\_token\_type](#input\_github\_token\_type) | Storage type of GITHUB\_TOKEN environment variable (`PARAMETER_STORE`, `PLAINTEXT`, `SECRETS_MANAGER`) | `string` | `"PARAMETER_STORE"` | no |
82+
| <a name="input_iam_permissions_boundary"></a> [iam\_permissions\_boundary](#input\_iam\_permissions\_boundary) | ARN of the policy that is used to set the permissions boundary for the role. | `string` | `null` | no |
83+
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path to the policy. | `string` | `"/service-role/"` | no |
84+
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the role. | `string` | `null` | no |
8285
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
8386
| <a name="input_image_repo_name"></a> [image\_repo\_name](#input\_image\_repo\_name) | (Optional) ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | `string` | `"UNSET"` | no |
8487
| <a name="input_image_tag"></a> [image\_tag](#input\_image\_tag) | (Optional) Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html | `string` | `"latest"` | no |

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ resource "aws_iam_role" "default" {
9999
name = module.this.id
100100
assume_role_policy = data.aws_iam_policy_document.role.json
101101
force_detach_policies = true
102+
path = var.iam_role_path
103+
permissions_boundary = var.iam_permissions_boundary
102104
tags = module.this.tags
103105
}
104106

@@ -122,7 +124,7 @@ data "aws_iam_policy_document" "role" {
122124
resource "aws_iam_policy" "default" {
123125
count = module.this.enabled ? 1 : 0
124126
name = module.this.id
125-
path = "/service-role/"
127+
path = var.iam_policy_path
126128
policy = data.aws_iam_policy_document.combined_permissions.json
127129
tags = module.this.tags
128130
}
@@ -131,7 +133,7 @@ resource "aws_iam_policy" "default_cache_bucket" {
131133
count = module.this.enabled && local.s3_cache_enabled ? 1 : 0
132134

133135
name = "${module.this.id}-cache-bucket"
134-
path = "/service-role/"
136+
path = var.iam_policy_path
135137
policy = join("", data.aws_iam_policy_document.permissions_cache_bucket.*.json)
136138
tags = module.this.tags
137139
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,24 @@ variable "extra_permissions" {
260260
description = "List of action strings which will be added to IAM service account permissions."
261261
}
262262

263+
variable "iam_role_path" {
264+
type = string
265+
default = null
266+
description = "Path to the role."
267+
}
268+
269+
variable "iam_policy_path" {
270+
type = string
271+
default = "/service-role/"
272+
description = "Path to the policy."
273+
}
274+
275+
variable "iam_permissions_boundary" {
276+
type = string
277+
default = null
278+
description = "ARN of the policy that is used to set the permissions boundary for the role."
279+
}
280+
263281
variable "encryption_enabled" {
264282
type = bool
265283
default = false

0 commit comments

Comments
 (0)