Skip to content

Commit 4eabaab

Browse files
committed
Use all potential bastion tag instead of only the first match
1 parent 2df3f2c commit 4eabaab

8 files changed

Lines changed: 14 additions & 24 deletions

File tree

aws/infrastructure.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module "configuration" {
2424
sudoer_username = var.sudoer_username
2525
public_keys = var.public_keys
2626
domain_name = module.design.domain_name
27-
bastion_tag = module.design.bastion_tag
27+
bastion_tags = module.design.bastion_tags
2828
cluster_name = var.cluster_name
2929
guest_passwd = var.guest_passwd
3030
nb_users = var.nb_users

azure/infrastructure.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module "configuration" {
2424
sudoer_username = var.sudoer_username
2525
public_keys = var.public_keys
2626
domain_name = module.design.domain_name
27-
bastion_tag = module.design.bastion_tag
27+
bastion_tags = module.design.bastion_tags
2828
cluster_name = var.cluster_name
2929
guest_passwd = var.guest_passwd
3030
nb_users = var.nb_users

common/configuration/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ variable "public_keys" {}
2424

2525
variable "skip_upgrade" {}
2626
variable "puppetfile" {}
27-
variable "bastion_tag" {}
27+
variable "bastion_tags" {}
2828

2929
resource "tls_private_key" "ssh" {
3030
algorithm = "ED25519"
@@ -162,7 +162,7 @@ output "ssh_key" {
162162
output "bastions" {
163163
value = {
164164
for host, values in local.final_inventory : host => values
165-
if contains(values.tags, var.bastion_tag) && contains(values.tags, "public") && (!contains(values.tags, "pool"))
165+
if length(setintersection(values.tags, var.bastion_tags)) > 0 && contains(values.tags, "public") && (!contains(values.tags, "pool"))
166166
}
167167
}
168168

common/design/main.tf

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,11 @@ locals {
5252

5353
volume_per_instance = transpose({ for key, value in local.instance_per_volume : key => value["instances"] })
5454

55-
# We look for a firewall rule that allow SSH connection from the Terraform agent's ip
56-
# and we memorize the corresponding tag so we can determine which instances can be used as a
55+
# We look for firewall rules that allow SSH connection from the Terraform agent's ip
56+
# and we memorize the corresponding tags so we can determine which instances can be used as a
5757
# first hop when transferring files or executing remote commands with Terraform.
58-
# There are room for improvements, but we don't expect users to be very creative with
59-
# firewall rules, so we are keeping the algorithm simple for now. One aspect
60-
# that could be improved:
61-
# 1. We don't validate if the tag is actually present in any instance, we simply take the
62-
# first value, so if there are more than one firewall rules that matches the criteria
63-
# but only one that is actually active, we might select the wrong tag. It would be better
64-
# to keep all firewall tags that match the criteria, then identify the intersection with
65-
# instance tags and select any tag that matches.
6658
agent_ip = chomp(data.http.agent_ip.response_body)
67-
bastion_tag = try(
68-
element([
59+
bastion_tags = try([
6960
for rule, values in var.firewall_rules :
7061
values.tag
7162
if values.ethertype == "IPv4" &&
@@ -75,9 +66,8 @@ locals {
7566
tonumber(split(".", strcontains(values.cidr, "/") ? cidrhost(values.cidr, 0) : values.cidr)[i]) <= tonumber(v) &&
7667
tonumber(split(".", strcontains(values.cidr, "/") ? cidrhost(values.cidr, -1) : values.cidr)[i]) >= tonumber(v)
7768
])
78-
],
79-
0),
80-
"")
69+
],
70+
[])
8171
}
8272

8373
check "disk_space_per_tag" {

common/design/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ output "domain_name" {
1818
value = local.domain_name
1919
}
2020

21-
output "bastion_tag" {
22-
value = local.bastion_tag
21+
output "bastion_tags" {
22+
value = local.bastion_tags
2323
}

gcp/infrastructure.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module "configuration" {
2323
sudoer_username = var.sudoer_username
2424
public_keys = var.public_keys
2525
domain_name = module.design.domain_name
26-
bastion_tag = module.design.bastion_tag
26+
bastion_tags = module.design.bastion_tags
2727
cluster_name = var.cluster_name
2828
guest_passwd = var.guest_passwd
2929
nb_users = var.nb_users

incus/infrastructure.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "configuration" {
1919
sudoer_username = var.sudoer_username
2020
public_keys = var.public_keys
2121
domain_name = module.design.domain_name
22-
bastion_tag = module.design.bastion_tag
22+
bastion_tags = module.design.bastion_tags
2323
cluster_name = var.cluster_name
2424
guest_passwd = var.guest_passwd
2525
nb_users = var.nb_users

openstack/infrastructure.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "configuration" {
1919
sudoer_username = var.sudoer_username
2020
public_keys = var.public_keys
2121
domain_name = module.design.domain_name
22-
bastion_tag = module.design.bastion_tag
22+
bastion_tags = module.design.bastion_tags
2323
cluster_name = var.cluster_name
2424
guest_passwd = var.guest_passwd
2525
nb_users = var.nb_users

0 commit comments

Comments
 (0)