Skip to content

Commit 97b4dda

Browse files
committed
Skip bastion_host provision when puppetservers are bastion
1 parent 49c8542 commit 97b4dda

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

common/configuration/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ output "terraform_facts" {
142142
}
143143

144144
output "puppetservers" {
145-
value = { for host, values in local.final_inventory : host => values.local_ip if contains(values.tags, "puppet") }
145+
value = { for host, values in local.final_inventory : host => { local_ip = values.local_ip, public_ip = values.public_ip } if contains(values.tags, "puppet") }
146146
}
147147

148148
output "guest_passwd" {

common/provision/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ data "archive_file" "puppetserver_files" {
6060
}
6161

6262
locals {
63-
bastion_host = length(var.configuration.bastions) > 0 ? var.configuration.bastions[keys(var.configuration.bastions)[0]] : null
63+
puppetservers_are_bastion = length(setintersection(keys(var.configuration.bastions), keys(var.configuration.puppetservers))) == length(var.configuration.puppetservers)
64+
bastion_host = length(var.configuration.bastions) > 0 ? var.configuration.bastions[keys(var.configuration.bastions)[0]] : null
6465
}
6566

6667
resource "terraform_data" "deploy_puppetserver_files" {
@@ -69,11 +70,11 @@ resource "terraform_data" "deploy_puppetserver_files" {
6970
connection {
7071
type = "ssh"
7172
agent = false
72-
bastion_host = contains(local.bastion_host.tags, "public") ? local.bastion_host.public_ip : local.bastion_host.local_ip
73+
bastion_host = local.puppetservers_are_bastion ? null : (contains(local.bastion_host.tags, "public") ? local.bastion_host.public_ip : local.bastion_host.local_ip)
7374
bastion_user = "tf"
7475
bastion_private_key = var.configuration.ssh_key.private
7576
user = "tf"
76-
host = each.value
77+
host = local.puppetservers_are_bastion && each.value.public_ip != "" ? each.value.public_ip : each.value.local_ip
7778
private_key = var.configuration.ssh_key.private
7879
}
7980

0 commit comments

Comments
 (0)