Skip to content

Commit 9650fed

Browse files
committed
using random name suffix
1 parent 8c75b4e commit 9650fed

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

main.tf

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@ locals {
55
private_key_file = "private-key.pem"
66
# adding the null_resource to prevent evaluating this until the openvpn_update_users has executed
77
refetch_user_ovpn = null_resource.openvpn_update_users_script.id != "" ? !alltrue([for x in var.users : fileexists("${var.output_dir}/${x}.ovpn")]) : false
8+
name = "${var.name_prefix}-${random_string.name_suffix.result}"
9+
}
10+
11+
resource "random_string" "name_suffix" {
12+
length = 8
13+
special = false
14+
upper = false
815
}
916

1017
resource "google_compute_firewall" "allow-ingress-to-openvpn-server" {
11-
name = "openvpn-${var.name}-allow-ingress"
18+
name = "openvpn-allow-ingress-${local.name}"
1219
project = var.project_id
1320
network = var.network
1421
description = "Creates firewall rule targeting the openvpn instance"
@@ -24,11 +31,11 @@ resource "google_compute_firewall" "allow-ingress-to-openvpn-server" {
2431
}
2532

2633
source_ranges = ["0.0.0.0/0"]
27-
target_tags = ["openvpn-${var.name}"]
34+
target_tags = ["openvpn-${local.name}"]
2835
}
2936

3037
resource "google_compute_address" "default" {
31-
name = "openvpn-${var.name}-global-ip"
38+
name = "openvpn-global-ip-${local.name}"
3239
project = var.project_id
3340
region = var.region
3441
network_tier = var.network_tier
@@ -46,14 +53,9 @@ resource "local_sensitive_file" "private_key" {
4653
file_permission = "0400"
4754
}
4855

49-
resource "random_string" "openvpn_server_suffix" {
50-
length = 8
51-
special = false
52-
upper = false
53-
}
5456

5557
resource "google_compute_instance" "openvpn_server" {
56-
name = "openvpn-${var.name}-${random_string.openvpn_server_suffix.id}"
58+
name = "openvpn-${local.name}"
5759
project = var.project_id
5860
machine_type = var.machine_type
5961
labels = var.labels

variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ variable "project_id" {
33
default = null
44
}
55

6-
variable "name" {
6+
variable "name_prefix" {
77
type = string
88
description = "The name to use when generating resources"
99
}

0 commit comments

Comments
 (0)