Skip to content

Commit 62871df

Browse files
committed
fix: added random number suffix to service_account_prefix local variable
1 parent 5275d76 commit 62871df

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

modules/instance_template/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,19 @@ locals {
7575
)
7676
create_service_account = var.create_service_account ? var.service_account == null : false
7777

78-
service_account_prefix = substr("${var.name_prefix}-${var.region}", 0, 27)
78+
service_account_prefix = "${substr("${var.name_prefix}-${var.region}", 0, 23)}-${random_integer.sa_suffix.result}"
7979
service_account_output = local.create_service_account ? {
8080
id = google_service_account.sa[0].account_id,
8181
email = google_service_account.sa[0].email,
8282
member = google_service_account.sa[0].member
8383
} : {}
8484
}
8585

86+
resource "random_integer" "sa_suffix" {
87+
min = 1000
88+
max = 9999
89+
}
90+
8691
# Service account
8792
resource "google_service_account" "sa" {
8893
provider = google-beta

modules/instance_template/versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ terraform {
2121
source = "hashicorp/google-beta"
2222
version = ">= 5.36, < 8"
2323
}
24+
random = {
25+
source = "hashicorp/random"
26+
version = "< 4.0"
27+
}
2428
}
2529
provider_meta "google" {
2630
module_name = "blueprints/terraform/terraform-google-vm:instance_template/v13.6.1"

0 commit comments

Comments
 (0)