Skip to content

Commit 651c95f

Browse files
Merge pull request #30 from puppetlabs/custom_metadata
Allow user to provide custom labels and metadata
2 parents a93e1b1 + 5f9bf9a commit 651c95f

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ locals {
9090
create_network = var.subnet == null ? true : false
9191
fetch_existing = var.subnet == null ? 0 : 1
9292
has_lb = var.disable_lb ? false : data.hiera5_bool.has_compilers.value ? true : false
93-
labels = merge(var.labels, { "stack" = var.stack_name })
9493
}
9594

9695
# If we didn't create a network then we need to know the network of our
@@ -136,7 +135,8 @@ module "instances" {
136135
compiler_count = local.compiler_count
137136
node_count = var.node_count
138137
instance_image = var.instance_image
139-
labels = local.labels
138+
labels = var.labels
139+
metadata = var.metadata
140140
project = var.project
141141
server_count = data.hiera5.server_count.value
142142
database_count = data.hiera5.database_count.value

modules/instances/main.tf

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
locals {
2+
metadata = merge({
3+
"ssh-keys" = "${var.user}:${file(var.ssh_key)}"
4+
"VmDnsSetting" = "ZonalPreferred"
5+
}, var.metadata)
6+
}
7+
18
# PE server instance(s) depending on if a replica is provisioned or not
29
resource "google_compute_instance" "server" {
310
name = "pe-server-${var.id}-${count.index}"
@@ -8,11 +15,9 @@ resource "google_compute_instance" "server" {
815
# Constructing an FQDN from GCP convention for Zonal DNS and storing it as
916
# metadata so it is a property of the instance, making it easy to use later in
1017
# Bolt
11-
metadata = {
12-
"ssh-keys" = "${var.user}:${file(var.ssh_key)}"
13-
"VmDnsSetting" = "ZonalPreferred"
18+
metadata = merge({
1419
"internalDNS" = "pe-server-${var.id}-${count.index}.${element(var.zones, count.index)}.c.${var.project}.internal"
15-
}
20+
}, local.metadata)
1621

1722
labels = var.labels
1823

@@ -51,11 +56,9 @@ resource "google_compute_instance" "psql" {
5156
count = var.database_count
5257
zone = element(var.zones, count.index)
5358

54-
metadata = {
55-
"ssh-keys" = "${var.user}:${file(var.ssh_key)}"
56-
"VmDnsSetting" = "ZonalPreferred"
59+
metadata = merge({
5760
"internalDNS" = "pe-psql-${var.id}-${count.index}.${element(var.zones, count.index)}.c.${var.project}.internal"
58-
}
61+
}, local.metadata)
5962

6063
labels = var.labels
6164

@@ -88,11 +91,9 @@ resource "google_compute_instance" "compiler" {
8891
count = var.compiler_count
8992
zone = element(var.zones, count.index)
9093

91-
metadata = {
92-
"ssh-keys" = "${var.user}:${file(var.ssh_key)}"
93-
"VmDnsSetting" = "ZonalPreferred"
94+
metadata = merge({
9495
"internalDNS" = "pe-compiler-${var.id}-${count.index}.${element(var.zones, count.index)}.c.${var.project}.internal"
95-
}
96+
}, local.metadata)
9697

9798
labels = var.labels
9899

@@ -124,11 +125,9 @@ resource "google_compute_instance" "node" {
124125
count = var.node_count
125126
zone = element(var.zones, count.index)
126127

127-
metadata = {
128-
"ssh-keys" = "${var.user}:${file(var.ssh_key)}"
129-
"VmDnsSetting" = "ZonalPreferred"
130-
"internalDNS" = "pe-node-${var.id}-${count.index}.${element(var.zones, count.index)}.c.${var.project}.internal"
131-
}
128+
metadata = merge({
129+
"internalDNS" = "pe-compiler-${var.id}-${count.index}.${element(var.zones, count.index)}.c.${var.project}.internal"
130+
}, local.metadata)
132131

133132
labels = var.labels
134133

modules/instances/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ variable "instance_image" {
3636
type = string
3737
}
3838
variable "labels" {
39-
description = "A map of labels to apply to the instances"
39+
description = "A list of labels that will be applied to virtual instances"
4040
type = map
41+
default = {}
42+
}
43+
variable "metadata" {
44+
description = "A map of user supplied metadata that will be applied to virtual instances"
45+
type = map
46+
default = {}
4147
}
4248
variable "project" {
4349
description = "Name of GCP project that will be used for housing require infrastructure"

variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ variable "instance_image" {
3131
type = string
3232
default = "almalinux-cloud/almalinux-8"
3333
}
34-
variable "stack_name" {
35-
description = "A name that'll help the user identify which instances are are part of a specific PE deployment"
36-
type = string
37-
default = "puppet-enterprise"
38-
}
3934
variable "firewall_allow" {
4035
description = "List of permitted IP subnets, list most include the internal network and single addresses must be passed as a /32"
4136
type = list(string)
@@ -72,7 +67,12 @@ variable "cluster_profile" {
7267
}
7368
}
7469
variable "labels" {
75-
description = "A map of labels that will be applied to the instances"
70+
description = "A list of labels that will be applied to virtual instances"
71+
type = map
72+
default = {}
73+
}
74+
variable "metadata" {
75+
description = "A map of user supplied metadata that will be applied to virtual instances"
7676
type = map
7777
default = {}
7878
}

0 commit comments

Comments
 (0)