Skip to content

Commit 16635b0

Browse files
committed
chore: add a random suffix to gh repos created via aks starterkit
also includes making archive_on_destroy configurable in GH repo building block
1 parent 6e683a0 commit 16635b0

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

modules/aks/starterkit/buildingblock/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ No modules.
3434
| [meshstack_project_user_binding.creator_prod_admin](https://registry.terraform.io/providers/meshcloud/meshstack/0.15.0/docs/resources/project_user_binding) | resource |
3535
| [meshstack_tenant_v4.dev](https://registry.terraform.io/providers/meshcloud/meshstack/0.15.0/docs/resources/tenant_v4) | resource |
3636
| [meshstack_tenant_v4.prod](https://registry.terraform.io/providers/meshcloud/meshstack/0.15.0/docs/resources/tenant_v4) | resource |
37+
| [random_id.repo_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
3738

3839
## Inputs
3940

4041
| Name | Description | Type | Default | Required |
4142
|------|-------------|------|---------|:--------:|
43+
| <a name="input_archive_repo_on_destroy"></a> [archive\_repo\_on\_destroy](#input\_archive\_repo\_on\_destroy) | Whether to archive github repository when destroying the terraform resource, or delete it. Defaults to true (archive). | `bool` | `true` | no |
4244
| <a name="input_creator"></a> [creator](#input\_creator) | Information about the creator of the resources who will be assigned Project Admin role | <pre>object({<br> type = string<br> identifier = string<br> displayName = string<br> username = optional(string)<br> email = optional(string)<br> euid = optional(string)<br> })</pre> | n/a | yes |
4345
| <a name="input_full_platform_identifier"></a> [full\_platform\_identifier](#input\_full\_platform\_identifier) | Full platform identifier of the AKS Namespace platform. | `string` | n/a | yes |
4446
| <a name="input_github_actions_connector_definition_version_uuid"></a> [github\_actions\_connector\_definition\_version\_uuid](#input\_github\_actions\_connector\_definition\_version\_uuid) | UUID of the GitHub Actions connector building block definition version. | `string` | n/a | yes |

modules/aks/starterkit/buildingblock/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ locals {
55

66
# Decode project tags YAML configuration
77
project_tags_config = yamldecode(var.project_tags_yaml)
8+
9+
repo_name = "${local.identifier}-${random_id.repo_suffix.hex}"
10+
}
11+
12+
# Generate a random suffix for the repository name to ensure uniqueness
13+
resource "random_id" "repo_suffix" {
14+
byte_length = 4 // 8 hex characters
815
}
916

1017
resource "meshstack_project" "dev" {
@@ -109,7 +116,10 @@ resource "meshstack_building_block_v2" "repo" {
109116

110117
inputs = {
111118
repo_name = {
112-
value_string = local.identifier
119+
value_string = local.repo_name
120+
}
121+
archive_repo_on_destroy = {
122+
value_bool = var.archive_repo_on_destroy
113123
}
114124
repo_owner = {
115125
value_string = var.repo_admin != null ? var.repo_admin : "null"

modules/aks/starterkit/buildingblock/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ variable "github_repo_input_repo_visibility" {
4343
default = "private"
4444
}
4545

46+
variable "archive_repo_on_destroy" {
47+
type = bool
48+
description = "Whether to archive github repository when destroying the terraform resource, or delete it. Defaults to true (archive)."
49+
default = true
50+
}
51+
4652
variable "github_org" {
4753
type = string
4854
description = "GitHub organization name. Used only for display purposes."

modules/github/repository/buildingblock/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ No modules.
3232

3333
| Name | Description | Type | Default | Required |
3434
|------|-------------|------|---------|:--------:|
35+
| <a name="input_archive_repo_on_destroy"></a> [archive\_repo\_on\_destroy](#input\_archive\_repo\_on\_destroy) | Whether to archive github repository when destroying the terraform resource, or delete it. Defaults to true (archive). | `bool` | `true` | no |
3536
| <a name="input_repo_description"></a> [repo\_description](#input\_repo\_description) | Description of the GitHub repository | `string` | `"created by github-repo-building-block"` | no |
3637
| <a name="input_repo_name"></a> [repo\_name](#input\_repo\_name) | Name of the GitHub repository | `string` | `"github-repo"` | no |
3738
| <a name="input_repo_owner"></a> [repo\_owner](#input\_repo\_owner) | Username of the GitHub user who will be set as the owner/admin of the repository. If not set, no collaborator will be added. | `string` | `null` | no |

modules/github/repository/buildingblock/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resource "github_repository" "repository" {
44
visibility = var.repo_visibility
55
auto_init = false
66
vulnerability_alerts = true
7-
archive_on_destroy = true
7+
archive_on_destroy = var.archive_repo_on_destroy
88

99
dynamic "template" {
1010
for_each = var.use_template ? [1] : []

modules/github/repository/buildingblock/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
variable "archive_repo_on_destroy" {
2+
type = bool
3+
default = true
4+
description = "Whether to archive github repository when destroying the terraform resource, or delete it. Defaults to true (archive)."
5+
}
6+
17
variable "repo_description" {
28
type = string
39
default = "created by github-repo-building-block"

0 commit comments

Comments
 (0)