Skip to content

Commit 6f904c9

Browse files
authored
feat(refs): Add possibility to link optional ref_type (#41)
* feat(refs): Add possibility link another ref_type instead of only branch * tests: Add new refs to docs and complete tests for pre-commit
1 parent 615f47a commit 6f904c9

File tree

8 files changed

+52
-32
lines changed

8 files changed

+52
-32
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,18 @@ module "gitlab_oidc" {
2424
2525
attach_read_only_policy = true
2626
gitlab_organisation = "saidsef"
27-
gitlab_repositories = [{
28-
name = "terraform-aws-gitlab-oidc",
29-
branches = ["main", "pr-*", "*pull*", "*"]
30-
}]
27+
gitlab_repositories = [
28+
{
29+
name = "terraform-aws-gitlab-oidc",
30+
refs = ["main", "pr-*", "*pull*", "*"]
31+
ref_type = "branch"
32+
},
33+
{
34+
name = "terraform-aws-gitlab-oidc",
35+
refs = ["*"]
36+
ref_type = "tag"
37+
}
38+
]
3139
tags = var.tags
3240
}
3341
```

TERRAFORM.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
| Name | Version |
44
|------|---------|
55
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1 |
6-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4 |
7-
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4 |
6+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4, < 6 |
7+
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4, < 6 |
88

99
## Providers
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.47.0 |
14-
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.4 |
13+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.61.0 |
14+
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.5 |
1515

1616
## Modules
1717

@@ -41,7 +41,7 @@ No modules.
4141
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Enable creation of resources | `bool` | `true` | no |
4242
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Force detachment of policies attached to the IAM role | `string` | `false` | no |
4343
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | n/a | yes |
44-
| <a name="input_gitlab_repositories"></a> [gitlab\_repositories](#input\_gitlab\_repositories) | List of GitLab repository name(s) and branche names or patterns | <pre>list(object({<br> name = string<br> branches = list(string)<br> }))</pre> | <pre>[<br> {<br> "branches": null,<br> "name": null<br> }<br>]</pre> | no |
44+
| <a name="input_gitlab_repositories"></a> [gitlab\_repositories](#input\_gitlab\_repositories) | List of GitLab repository name(s) and refs names or patterns | <pre>list(object({<br> name = string<br> refs = list(string)<br> ref_type = string<br> }))</pre> | <pre>[<br> {<br> "name": "",<br> "ref_type": "",<br> "refs": []<br> }<br>]</pre> | no |
4545
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"gitlab-runner"` | no |
4646
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the IAM role | `string` | `"/"` | no |
4747
| <a name="input_iam_role_permissions_boundary"></a> [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | ARN of the permissions boundary to be used by the IAM role | `string` | `""` | no |
@@ -54,7 +54,7 @@ No modules.
5454

5555
| Name | Description |
5656
|------|-------------|
57-
| <a name="output_repositories"></a> [repositories](#output\_repositories) | List of GitLab repositories and branches |
57+
| <a name="output_repositories"></a> [repositories](#output\_repositories) | List of GitLab repositories and refs |
5858
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | AWS IAM role ARN |
5959
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | AWS IAM role ID |
6060
| <a name="output_thumbprint"></a> [thumbprint](#output\_thumbprint) | GitLab certificates thumbprints |

current.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
data "aws_partition" "current" {}
22

33
locals {
4-
repositories_branches = flatten([
4+
repositories_refs = flatten([
55
for repo in var.gitlab_repositories : [
6-
for branch in repo.branches : {
7-
branch = branch
8-
name = repo.name
6+
for ref in repo.refs : {
7+
ref = ref
8+
name = repo.name
9+
ref_type = repo.ref_type
910
}
1011
]
1112
])
@@ -18,7 +19,7 @@ data "aws_iam_policy_document" "assume_role" {
1819

1920
condition {
2021
test = "ForAnyValue:StringLike"
21-
values = [for repo in local.repositories_branches : format("project_path:%s/%s:ref_type:branch:ref:%s", var.gitlab_organisation, repo.name, repo.branch)]
22+
values = [for repo in local.repositories_refs : format("project_path:%s/%s:ref_type:%s:ref:%s", var.gitlab_organisation, repo.name, repo.ref_type, repo.ref)]
2223
variable = format("%s:sub", var.url)
2324
}
2425

examples/complete/terraform.tfvars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ enabled = true
55
force_detach_policies = false
66
gitlab_organisation = "saidsef"
77
gitlab_repositories = [
8-
{ name = "terraform-aws-gitlab-oidc",
9-
branches = ["main", "pr-*", "*pull*", "*"]
8+
{
9+
name = "example-repo"
10+
refs = ["main", "develop"] # Example list of refs
11+
ref_type = "branch" # Example ref_type
1012
}
1113
]
1214
iam_role_name = "gitlab-runner"

examples/complete/variables.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,18 @@ variable "gitlab_organisation" {
4343
variable "gitlab_repositories" {
4444
type = list(object({
4545
name = string
46-
branches = list(string)
46+
refs = list(string)
47+
ref_type = string
4748
}))
48-
default = [{
49-
branches = null
50-
name = null
51-
}]
52-
description = "List of GitLab repository name(s) and branche names or patterns"
49+
default = [
50+
{
51+
name = ""
52+
refs = []
53+
ref_type = ""
54+
}
55+
]
56+
57+
description = "List of GitLab repository name(s) and refs names or patterns"
5358
}
5459

5560
variable "iam_role_name" {

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ output "role_arn" {
1111
}
1212

1313
output "repositories" {
14-
value = local.repositories_branches
14+
value = local.repositories_refs
1515
sensitive = false
16-
description = "List of GitLab repositories and branches"
16+
description = "List of GitLab repositories and refs"
1717
}
1818

1919
output "thumbprint" {

variables.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ variable "gitlab_organisation" {
3636
variable "gitlab_repositories" {
3737
type = list(object({
3838
name = string
39-
branches = list(string)
39+
refs = list(string)
40+
ref_type = string
4041
}))
41-
default = [{
42-
branches = null
43-
name = null
44-
}]
45-
description = "List of GitLab repository name(s) and branche names or patterns"
42+
default = [
43+
{
44+
name = ""
45+
refs = []
46+
ref_type = ""
47+
}
48+
]
49+
description = "List of GitLab repository name(s) and refs names or patterns"
4650
}
4751

4852
variable "iam_role_name" {

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ terraform {
1111
}
1212
}
1313

14-
required_version = "~> 1"
14+
required_version = ">= 1.0.0"
1515
}

0 commit comments

Comments
 (0)