Skip to content

Commit 9941680

Browse files
committed
Add GitHub Autolink References configuration block
1 parent 3808fcd commit 9941680

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ _Security related notice: Versions 4.7.0, 4.8.0, 4.9.0 and 4.9.1 of the Terrafor
3131
- [Projects Configuration](#projects-configuration)
3232
- [Webhooks Configuration](#webhooks-configuration)
3333
- [Secrets Configuration](#secrets-configuration)
34+
- [Autolink References](#autolink-references-configuration)
3435
- [Module Configuration](#module-configuration)
3536
- [Module Outputs](#module-outputs)
3637
- [External Documentation](#external-documentation)
@@ -831,6 +832,24 @@ This is due to some terraform limitation and we will update the module once terr
831832
This requirement matches Github's API, see the upstream documentation for more information.
832833
Default is no approving reviews are required.
833834

835+
#### Autolink References Configuration
836+
837+
- [**`autolink_references`**](#var-autolink-references): *(Optional `list(autolink_references)`)*<a name="var-autolink-references"></a>
838+
839+
This resource allows you to create and manage autolink references for GitHub repository.
840+
841+
Default is `[]`.
842+
843+
Each `autolink_reference` object in the list accepts the following attributes:
844+
845+
- [**`key_prefix`**](#attr-autolink-references-key_prefix): *(**Required** `string`)*<a name="attr-autolink-references-key_prefix"></a>
846+
847+
The prefix of the autolink reference.
848+
849+
- [**`target_url_template`**](#attr-autolink-references-target_url_template): *(**Required** `string`)*<a name="attr-autolink-references-target_url_template"></a>
850+
851+
The target url template of the autolink reference.
852+
834853
### Module Configuration
835854

836855
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(any)`)*<a name="var-module_depends_on"></a>

README.tfdoc.hcl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,34 @@ section {
10831083
}
10841084
}
10851085

1086+
section {
1087+
title = "Autolink References Configuration"
1088+
1089+
variable "autolink_references" {
1090+
type = list(autolink_reference)
1091+
default = []
1092+
description = <<-END
1093+
This resource allows you to create and manage autolink references for GitHub repository.
1094+
END
1095+
1096+
attribute "key_prefix" {
1097+
required = true
1098+
type = string
1099+
description = <<-END
1100+
The key prefix of the autolink reference.
1101+
END
1102+
}
1103+
1104+
attribute "target_url_template" {
1105+
type = string
1106+
default = ""
1107+
description = <<-END
1108+
The target url template of the autolink reference.
1109+
END
1110+
}
1111+
}
1112+
}
1113+
10861114
section {
10871115
title = "Module Configuration"
10881116

@@ -1209,6 +1237,7 @@ section {
12091237
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
12101238
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
12111239
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project
1240+
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_autolink_reference
12121241
END
12131242
}
12141243
}
@@ -1301,6 +1330,9 @@ references {
13011330
ref "`github_repository_project`" {
13021331
value = "https://www.terraform.io/docs/providers/github/r/repository_project.html#attributes-reference"
13031332
}
1333+
ref "`github_repository_autolink_reference`" {
1334+
value = "https://www.terraform.io/docs/providers/github/r/repository_autolink_reference.html#attributes-reference"
1335+
}
13041336
ref "homepage" {
13051337
value = "https://mineiros.io/?ref=terraform-github-repository"
13061338
}

main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,21 @@ resource "github_actions_secret" "repository_secret" {
467467
secret_name = each.key
468468
plaintext_value = each.value
469469
}
470+
471+
# ---------------------------------------------------------------------------------------------------------------------
472+
# Autolink References
473+
# ---------------------------------------------------------------------------------------------------------------------
474+
475+
locals {
476+
autolink_references = { for i in var.autolink_references : lookup(i, "id", lower(i.key_prefix)) => merge({
477+
target_url_template = null
478+
}, i) }
479+
}
480+
481+
resource "github_repository_autolink_reference" "repository_autolink_reference" {
482+
for_each = local.autolink_references
483+
484+
repository = github_repository.repository.name
485+
key_prefix = each.value.key_prefix
486+
target_url_template = each.value.target_url_template
487+
}

test/unit-complete/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ module "repository" {
117117
]
118118

119119
projects = var.projects
120+
121+
autolink_references = var.autolink_references
120122
}
121123

122124
resource "github_branch" "development" {

test/unit-complete/variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,16 @@ variable "webhook_events" {
230230
type = list(string)
231231
default = ["issues"]
232232
}
233+
234+
variable "autolink_references" {
235+
description = "A list of autolink references"
236+
type = list(object({
237+
key_prefix = string
238+
target_url_template = string
239+
}))
240+
241+
default = [{
242+
key_prefix = "TICKET-"
243+
target_url_template = "https://hello.there/TICKET?query=<num>"
244+
}]
245+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,24 @@ variable "plaintext_secrets" {
474474
default = {}
475475
}
476476

477+
variable "autolink_references" {
478+
description = "(Optional) Configuring autolink references. For details please check: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_autolink_reference"
479+
type = list(object({
480+
key_prefix = string
481+
target_url_template = string
482+
}))
483+
484+
# Example:
485+
# autolink_references = [
486+
# {
487+
# key_prefix = "TICKET-"
488+
# target_url_template = "https://hello.there/TICKET?query=<num>"
489+
# }
490+
# ]
491+
492+
default = []
493+
}
494+
477495
variable "vulnerability_alerts" {
478496
type = bool
479497
description = "(Optional) Set to `false` to disable security alerts for vulnerable dependencies. Enabling requires alerts to be enabled on the owner level."

0 commit comments

Comments
 (0)