Skip to content

Commit 5fa71f3

Browse files
author
Mykhailo Babych
committed
chore: Add custom policy creation for role
1 parent 1e30250 commit 5fa71f3

4 files changed

Lines changed: 46 additions & 11 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ In the above diagram, you can see the components and their relations (PostgreSQL
3434

3535
| Name | Source | Version |
3636
|------|--------|---------|
37+
| <a name="module_gitlab_policy"></a> [gitlab\_policy](#module\_gitlab\_policy) | terraform-aws-modules/iam/aws//modules/iam-policy | v5.34.0 |
3738
| <a name="module_gitlab_role"></a> [gitlab\_role](#module\_gitlab\_role) | terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc | v5.34.0 |
3839
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.1.0 |
3940

@@ -73,6 +74,8 @@ In the above diagram, you can see the components and their relations (PostgreSQL
7374
| <a name="input_release_max_history"></a> [release\_max\_history](#input\_release\_max\_history) | Maximum saved revisions per release | `number` | `10` | no |
7475
| <a name="input_release_name"></a> [release\_name](#input\_release\_name) | This is the name of the release which also used as a prefix or suffix for the resources | `string` | `"gitlab"` | no |
7576
| <a name="input_release_namespace"></a> [release\_namespace](#input\_release\_namespace) | Namespace name where you want to deploy the release. If empty, `release_name` will be used. | `string` | `""` | no |
77+
| <a name="input_role_policy"></a> [role\_policy](#input\_role\_policy) | Policy for GitLab role | `string` | `null` | no |
78+
| <a name="input_role_suffix"></a> [role\_suffix](#input\_role\_suffix) | Optional suffix for GitLab role | `string` | `"access-aws"` | no |
7679
| <a name="input_smtp_password"></a> [smtp\_password](#input\_smtp\_password) | SMTP Password | `string` | `""` | no |
7780
| <a name="input_smtp_user"></a> [smtp\_user](#input\_smtp\_user) | SMTP Username | `string` | `""` | no |
7881
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
@@ -82,7 +85,7 @@ In the above diagram, you can see the components and their relations (PostgreSQL
8285

8386
| Name | Description |
8487
|------|-------------|
85-
| <a name="output_arn"></a> [arn](#output\_arn) | ARN of IAM role |
8688
| <a name="output_buckets"></a> [buckets](#output\_buckets) | List of buckets created |
87-
| <a name="output_name"></a> [name](#output\_name) | Name of IAM role |
89+
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | ARN of IAM role |
90+
| <a name="output_role_name"></a> [role\_name](#output\_role\_name) | Name of IAM role |
8891
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

main.tf

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,34 @@ resource "helm_release" "gitlab" {
276276
]
277277
}
278278

279+
module "gitlab_policy" {
280+
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
281+
version = "v5.34.0"
282+
283+
name = "gitlab-role-policy"
284+
description = "Policy for GitLab role"
285+
policy = var.role_policy
286+
287+
tags = var.tags
288+
}
289+
279290
module "gitlab_role" {
280-
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
281-
version = "v5.34.0"
282-
create_role = true
283-
allow_self_assume_role = false
284-
role_description = "Gitlab Role to access S3"
285-
role_name = "${var.release_name}-access-s3"
291+
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
292+
version = "v5.34.0"
293+
create_role = true
294+
allow_self_assume_role = false
295+
role_description = "Gitlab Role to access AWS resources"
296+
role_name = "${var.release_name}-${var.role_suffix}"
297+
role_policy_arns = [
298+
module.gitlab_policy.arn
299+
]
300+
286301
provider_url = data.aws_eks_cluster.eks.identity[0].oidc[0].issuer
287302
oidc_subjects_with_wildcards = ["system:serviceaccount:${local.release_namespace}:gitlab*"]
288303
oidc_fully_qualified_audiences = ["sts.amazonaws.com"]
289304
tags = var.tags
290-
}
305+
306+
depends_on = [
307+
module.gitlab_policy
308+
]
309+
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
output "name" {
1+
output "role_name" {
22
description = "Name of IAM role"
33
value = module.gitlab_role.iam_role_name
44
}
55

6-
output "arn" {
6+
output "role_arn" {
77
description = "ARN of IAM role"
88
value = module.gitlab_role.iam_role_arn
99

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,16 @@ variable "tags" {
106106
type = map(string)
107107
default = {}
108108
}
109+
110+
variable "role_policy" {
111+
type = string
112+
description = "Policy for GitLab role"
113+
sensitive = true
114+
default = null
115+
}
116+
117+
variable "role_suffix" {
118+
type = string
119+
description = "Optional suffix for GitLab role"
120+
default = "access-aws"
121+
}

0 commit comments

Comments
 (0)