Skip to content

Commit dbab816

Browse files
authored
Merge pull request #6 from Perun-Engineering/chore/add-role-policy-support
chore: Add role custom policy creation support chore: Update modules
2 parents 067db11 + 8f56a86 commit dbab816

9 files changed

Lines changed: 126 additions & 41 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.86.0
3+
rev: v1.105.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ This module was created to simplify deploying Gitlab into the EKS with storage o
1010

1111
In the above diagram, you can see the components and their relations (PostgreSQL and Redis are not deployed with this module).
1212

13-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13+
<!-- BEGIN_TF_DOCS -->
1414
## Requirements
1515

1616
| Name | Version |
1717
|------|---------|
18-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
19-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | 5.36.0 |
18+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
19+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
2020
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | 2.11.0 |
2121
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | ~> 2.0 |
2222
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.20 |
@@ -26,16 +26,17 @@ In the above diagram, you can see the components and their relations (PostgreSQL
2626

2727
| Name | Version |
2828
|------|---------|
29-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.36.0 |
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.36.0 |
3030
| <a name="provider_helm"></a> [helm](#provider\_helm) | 2.11.0 |
3131
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 3.0.1 |
3232

3333
## Modules
3434

3535
| Name | Source | Version |
3636
|------|--------|---------|
37-
| <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 |
38-
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.1.0 |
37+
| <a name="module_gitlab_policy"></a> [gitlab\_policy](#module\_gitlab\_policy) | terraform-aws-modules/iam/aws//modules/iam-policy | v6.4.0 |
38+
| <a name="module_gitlab_role"></a> [gitlab\_role](#module\_gitlab\_role) | terraform-aws-modules/iam/aws//modules/iam-role | v6.4.0 |
39+
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 5.10.0 |
3940

4041
## Resources
4142

@@ -51,9 +52,9 @@ In the above diagram, you can see the components and their relations (PostgreSQL
5152
| [kubernetes_secret_v1.redis](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
5253
| [kubernetes_secret_v1.registry_postgres](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
5354
| [kubernetes_secret_v1.smtp](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret_v1) | resource |
54-
| [aws_eks_cluster.eks](https://registry.terraform.io/providers/hashicorp/aws/5.36.0/docs/data-sources/eks_cluster) | data source |
55-
| [aws_iam_policy_document.s3_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/5.36.0/docs/data-sources/iam_policy_document) | data source |
56-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/5.36.0/docs/data-sources/region) | data source |
55+
| [aws_eks_cluster.eks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
56+
| [aws_iam_policy_document.s3_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
57+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
5758

5859
## Inputs
5960

@@ -73,12 +74,18 @@ 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 |
7982
| <a name="input_values"></a> [values](#input\_values) | Custom values.yaml file for the Helm chart | `any` | `[]` | no |
8083

8184
## Outputs
8285

83-
No outputs.
84-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
86+
| Name | Description |
87+
|------|-------------|
88+
| <a name="output_buckets"></a> [buckets](#output\_buckets) | List of buckets created |
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 |
91+
<!-- END_TF_DOCS -->

examples/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1+
<!-- BEGIN_TF_DOCS -->
22
## Requirements
33

44
| Name | Version |
55
|------|---------|
6-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
6+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
8+
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | 2.11.0 |
9+
| <a name="requirement_kubectl"></a> [kubectl](#requirement\_kubectl) | ~> 2.0 |
10+
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >= 2.20 |
11+
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9 |
712

813
## Providers
914

@@ -26,4 +31,4 @@ No inputs.
2631
## Outputs
2732

2833
No outputs.
29-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
34+
<!-- END_TF_DOCS -->

examples/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module "gitlab" {
4040
"lifecycle_rule": [
4141
{
4242
"id": "log",
43-
"enabled": true,
43+
"status": "Enabled",
4444
"expiration": {
4545
"days": 30
4646
}
@@ -53,7 +53,7 @@ EOF
5353
"lifecycle_rule": [
5454
{
5555
"id": "log",
56-
"enabled": true,
56+
"status": "Enabled",
5757
"noncurrent_version_transition": [
5858
{
5959
"days": 30,

examples/versions.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.5.7"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 6.0"
8+
}
9+
helm = {
10+
source = "hashicorp/helm"
11+
version = "2.11.0"
12+
}
13+
kubernetes = {
14+
source = "hashicorp/kubernetes"
15+
version = ">= 2.20"
16+
}
17+
time = {
18+
source = "hashicorp/time"
19+
version = ">= 0.9"
20+
}
21+
kubectl = {
22+
source = "alekc/kubectl"
23+
version = "~> 2.0"
24+
}
25+
}
326
}

main.tf

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
147147
effect = "Allow"
148148
principals {
149149
type = "AWS"
150-
identifiers = [module.gitlab_role.iam_role_arn]
150+
identifiers = [module.gitlab_role.arn]
151151
}
152152
actions = ["s3:ListBucket"]
153153
resources = ["arn:aws:s3:::${each.value}"]
@@ -158,7 +158,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
158158
effect = "Allow"
159159
principals {
160160
type = "AWS"
161-
identifiers = [module.gitlab_role.iam_role_arn]
161+
identifiers = [module.gitlab_role.arn]
162162
}
163163
actions = ["s3:PutObject", "s3:GetObject"]
164164
resources = ["arn:aws:s3:::${each.value}/*"]
@@ -169,7 +169,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
169169
effect = "Allow"
170170
principals {
171171
type = "AWS"
172-
identifiers = [module.gitlab_role.iam_role_arn]
172+
identifiers = [module.gitlab_role.arn]
173173
}
174174
actions = ["s3:DeleteObject"]
175175
resources = ["arn:aws:s3:::${each.value}/*"]
@@ -180,7 +180,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
180180
effect = "Allow"
181181
principals {
182182
type = "AWS"
183-
identifiers = [module.gitlab_role.iam_role_arn]
183+
identifiers = [module.gitlab_role.arn]
184184
}
185185
actions = ["s3:PutObjectAcl"]
186186
resources = ["arn:aws:s3:::${each.value}/*"]
@@ -191,7 +191,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
191191
effect = "Allow"
192192
principals {
193193
type = "AWS"
194-
identifiers = [module.gitlab_role.iam_role_arn]
194+
identifiers = [module.gitlab_role.arn]
195195
}
196196
actions = ["s3:GetObjectAcl"]
197197
resources = ["arn:aws:s3:::${each.value}/*"]
@@ -202,7 +202,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
202202
effect = "Allow"
203203
principals {
204204
type = "AWS"
205-
identifiers = [module.gitlab_role.iam_role_arn]
205+
identifiers = [module.gitlab_role.arn]
206206
}
207207
actions = ["s3:ListBucketMultipartUploads"]
208208
resources = ["arn:aws:s3:::${each.value}"]
@@ -213,7 +213,7 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
213213
effect = "Allow"
214214
principals {
215215
type = "AWS"
216-
identifiers = [module.gitlab_role.iam_role_arn]
216+
identifiers = [module.gitlab_role.arn]
217217
}
218218
actions = ["s3:ListMultipartUploadParts"]
219219
resources = ["arn:aws:s3:::${each.value}/*"]
@@ -223,10 +223,9 @@ data "aws_iam_policy_document" "s3_bucket_policy" {
223223
module "s3_bucket" {
224224
for_each = local.buckets_list
225225
source = "terraform-aws-modules/s3-bucket/aws"
226-
version = "4.1.0"
226+
version = "5.10.0"
227227

228228
bucket = each.value
229-
acl = null
230229
force_destroy = false
231230

232231
versioning = {
@@ -265,7 +264,7 @@ resource "helm_release" "gitlab" {
265264

266265
set {
267266
name = "global.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
268-
value = module.gitlab_role.iam_role_arn
267+
value = module.gitlab_role.arn
269268
}
270269

271270
depends_on = [
@@ -276,15 +275,37 @@ resource "helm_release" "gitlab" {
276275
]
277276
}
278277

279-
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"
286-
provider_url = data.aws_eks_cluster.eks.identity[0].oidc[0].issuer
287-
oidc_subjects_with_wildcards = ["system:serviceaccount:${local.release_namespace}:gitlab*"]
288-
oidc_fully_qualified_audiences = ["sts.amazonaws.com"]
289-
tags = var.tags
278+
module "gitlab_policy" {
279+
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
280+
version = "v6.4.0"
281+
282+
name = "gitlab-role-policy"
283+
description = "Policy for GitLab role"
284+
policy = var.role_policy
285+
286+
tags = var.tags
290287
}
288+
289+
module "gitlab_role" {
290+
source = "terraform-aws-modules/iam/aws//modules/iam-role"
291+
version = "v6.4.0"
292+
293+
enable_oidc = true
294+
name = "${var.release_name}-${var.role_suffix}"
295+
use_name_prefix = false
296+
description = "Gitlab Role to access AWS resources"
297+
298+
oidc_provider_urls = [data.aws_eks_cluster.eks.identity[0].oidc[0].issuer]
299+
oidc_wildcard_subjects = ["system:serviceaccount:${local.release_namespace}:gitlab*"]
300+
oidc_audiences = ["sts.amazonaws.com"]
301+
302+
policies = {
303+
gitlab-role-policy = module.gitlab_policy.arn
304+
}
305+
306+
tags = var.tags
307+
308+
depends_on = [
309+
module.gitlab_policy
310+
]
311+
}

outputs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
output "role_name" {
2+
description = "Name of IAM role"
3+
value = module.gitlab_role.arn
4+
}
15

6+
output "role_arn" {
7+
description = "ARN of IAM role"
8+
value = module.gitlab_role.arn
9+
10+
}
11+
12+
output "buckets" {
13+
description = "List of buckets created"
14+
value = tomap({
15+
for k, v in module.s3_bucket : k => v.s3_bucket_arn
16+
})
17+
}

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+
}

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.5.7"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = "5.36.0"
7+
version = ">= 6.0"
88
}
99
helm = {
1010
source = "hashicorp/helm"

0 commit comments

Comments
 (0)