Skip to content

Commit 059d845

Browse files
authored
Merge pull request #101 from mineiros-io/feature-auto-link-references
Add GitHub Autolink References configuration block
2 parents 3808fcd + d17a89c commit 059d845

File tree

9 files changed

+116
-5
lines changed

9 files changed

+116
-5
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.13.0]
11+
12+
### Added
13+
14+
- Add GitHub Autolink References configuration block (thanks to @0x46616c6b)
15+
1016
## [0.12.0]
1117

1218
### BREAKING CHANGES
@@ -334,7 +340,8 @@ Please review plans and report regressions and issues asap so we can improve doc
334340
- This is the initial release of our GitHub Repository module with support for
335341
creating and managing GitHub Repositories for Organizations.
336342

337-
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.12.0...HEAD
343+
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.13.0...HEAD
344+
[0.13.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.12.0...v0.13.0
338345
[0.12.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.11.0...v0.12.0
339346
[0.11.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.10.1...v0.11.0
340347
[0.10.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.10.0...v0.10.1

README.md

+22-1
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 Configuration](#autolink-references-configuration)
3435
- [Module Configuration](#module-configuration)
3536
- [Module Outputs](#module-outputs)
3637
- [External Documentation](#external-documentation)
@@ -82,7 +83,7 @@ Most basic usage creating a new private github repository.
8283
```hcl
8384
module "repository" {
8485
source = "mineiros-io/repository/github"
85-
version = "~> 0.11.0"
86+
version = "~> 0.13.0"
8687
8788
name = "terraform-github-repository"
8889
license_template = "apache-2.0"
@@ -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_reference)`)*<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+
This prefix appended by a number will generate a link any time it is found in an issue, pull request, or commit.
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 template of the target URL used for the links; must be a valid URL and contain `<num>` for the reference number.
852+
834853
### Module Configuration
835854

836855
- [**`module_depends_on`**](#var-module_depends_on): *(Optional `list(any)`)*<a name="var-module_depends_on"></a>
@@ -911,6 +930,7 @@ The following attributes are exported by the module:
911930
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_collaborator
912931
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_deploy_key
913932
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_project
933+
- https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_autolink_reference
914934

915935
## Module Versioning
916936

@@ -970,6 +990,7 @@ Copyright &copy; 2020-2022 [Mineiros GmbH][homepage]
970990
[`github_repository_collaborator`]: https://www.terraform.io/docs/providers/github/r/repository_collaborator.html#attribute-reference
971991
[`github_repository_deploy_key`]: https://www.terraform.io/docs/providers/github/r/repository_deploy_key.html#attributes-reference
972992
[`github_repository_project`]: https://www.terraform.io/docs/providers/github/r/repository_project.html#attributes-reference
993+
[`github_repository_autolink_reference`]: https://www.terraform.io/docs/providers/github/r/repository_autolink_reference.html#attributes-reference
973994
[homepage]: https://mineiros.io/?ref=terraform-github-repository
974995
975996
[badge-build]: https://github.com/mineiros-io/terraform-github-repository/workflows/CI/CD%20Pipeline/badge.svg

README.tfdoc.hcl

+33-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ section {
8989
```hcl
9090
module "repository" {
9191
source = "mineiros-io/repository/github"
92-
version = "~> 0.11.0"
92+
version = "~> 0.13.0"
9393
9494
name = "terraform-github-repository"
9595
license_template = "apache-2.0"
@@ -1081,6 +1081,34 @@ section {
10811081
END
10821082
}
10831083
}
1084+
1085+
section {
1086+
title = "Autolink References Configuration"
1087+
1088+
variable "autolink_references" {
1089+
type = list(autolink_reference)
1090+
default = []
1091+
description = <<-END
1092+
This resource allows you to create and manage autolink references for GitHub repository.
1093+
END
1094+
1095+
attribute "key_prefix" {
1096+
required = true
1097+
type = string
1098+
description = <<-END
1099+
This prefix appended by a number will generate a link any time it is found in an issue, pull request, or commit.
1100+
END
1101+
}
1102+
1103+
attribute "target_url_template" {
1104+
required = true
1105+
type = string
1106+
description = <<-END
1107+
The template of the target URL used for the links; must be a valid URL and contain `<num>` for the reference number.
1108+
END
1109+
}
1110+
}
1111+
}
10841112
}
10851113

10861114
section {
@@ -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
}

examples/public-repository/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ branch protection.
1515
```hcl
1616
module "repository" {
1717
source = "mineiros-io/repository/github"
18-
version = "~> 0.11.0"
18+
version = "~> 0.13.0"
1919
2020
module_depends_on = [
2121
github_team.team

examples/public-repository/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module "repository" {
99
source = "mineiros-io/repository/github"
10-
version = "~> 0.11.0"
10+
version = "~> 0.13.0"
1111

1212
module_depends_on = [
1313
module.team

main.tf

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

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

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

+18
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)