Skip to content

Commit

Permalink
OPENSHIFTP-124: Remove data.http.bastion_ip_retrieval logic and the h…
Browse files Browse the repository at this point in the history
…ttp server creation

Signed-off-by: Paul Bastide <[email protected]>
  • Loading branch information
prb112 committed Jun 13, 2024
1 parent a44a319 commit 3218b98
Showing 1 changed file with 1 addition and 105 deletions.
106 changes: 1 addition & 105 deletions modules/5_worker/worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,112 +54,8 @@ locals {
bastion_private_ip = [for lease in data.ibm_pi_dhcp.refresh_dhcp_server[0].leases : lease if lease.instance_mac == data.ibm_pi_instance.bastion_instance.networks[0].macaddress]
}

# Dev Note: the hypervisor does not report the internal interfaces ip correctly
# This resource works around that problem through a temporary setup of an http
resource "null_resource" "secondary_retrieval_ignition_ip" {
count = var.cicd ? 1 : 0
depends_on = [null_resource.nop]

connection {
type = "ssh"
user = "root"
private_key = file(var.private_key_file)
host = var.bastion_public_ip
agent = var.ssh_agent
}

provisioner "remote-exec" {
inline = [<<EOF
cat << EOFX > /etc/httpd/conf.d/extra.conf
Listen $(ip -j -4 -o address | jq -r '.[].addr_info[] | select(.dev == "env2").local'):443
<VirtualHost $(ip -j -4 -o address | jq -r '.[].addr_info[] | select(.dev == "env2").local'):443>
ServerName cicd
ServerAdmin cicd@localhost
DocumentRoot /var/www/vhosts/1/
<Directory /var/www/vhosts/1/>
AllowOverride None
</Directory>
ErrorLog /var/log/apache2-error.log
</VirtualHost>
EOFX
mkdir -p /var/www/vhosts/1
systemctl restart httpd
os_ver=$(cat /etc/os-release | egrep "^VERSION_ID=" | awk -F'"' '{print $2}')
if [[ $os_ver != "9"* ]]
then
# RHEL8
IFACES=$(nmcli device show 2>&1| grep GENERAL.DEVICE | grep -v env2 | grep -v lo | awk '{print $NF}')
else
# RHEL9
IFACES=$(nmcli device show 2>&1| grep GENERAL.DEVICE | grep -v eth1 | grep -v lo | awk '{print $NF}')
fi
for IFACE in $(echo $${IFACES})
do
IP_ADDR="$(nmcli device show $${IFACE} 2>&1 | grep IP4.ADDRESS | sed 's|/24||g' | awk '{print $NF}')"
if [ -n "$${IP_ADDR}" ]
then
echo "Interface: $${IFACE} $${IP_ADDR}"
echo "$${IP_ADDR}" > /var/www/vhosts/1/ip
echo "$${IP_ADDR}" > /var/www/vhosts/1/index.html
chmod -R 777 /var/www/vhosts/1/
fi
done
chown -R nobody:nobody /var/www/vhosts
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
EOF
]
}
}

data "http" "bastion_ip_retrieval" {
count = var.cicd ? 1 : 0
depends_on = [null_resource.secondary_retrieval_ignition_ip]
url = "http://${var.bastion_public_ip}:443/ip"
}

# Dev Note: at the end the https port shouldn't be active/listening
# resource "null_resource" "secondary_retrieval_shutdown" {
# count = var.cicd ? 1 : 0
# depends_on = [null_resource.nop, data.http.bastion_ip_retrieval, null_resource.secondary_retrieval_ignition_ip]
#
# triggers = {
# private_key = sensitive(file(var.private_key_file))
# host = var.bastion_public_ip
# agent = var.ssh_agent
# }
#
# connection {
# type = "ssh"
# user = "root"
# private_key = self.triggers.private_key
# host = self.triggers.host
# agent = self.triggers.agent
# }
#
# provisioner "remote-exec" {
# inline = [<<EOF
# rm -f /etc/httpd/conf.d/extra.conf
# systemctl restart httpd
# EOF
# ]
# }
# # Dev Note: When destroy, we need to recreate
# provisioner "remote-exec" {
# when = destroy
# on_failure = continue
# inline = [<<EOF
# echo "Listen 443" > /etc/httpd/conf.d/extra.conf
# systemctl restart httpd
# EOF
# ]
# }
# }

locals {
ignition_ip = length(var.ignition_ip) > 0 ? var.ignition_ip[0].instance_ip : length(local.bastion_private_ip) > 0 ? local.bastion_private_ip[0].instance_ip : chomp(data.http.bastion_ip_retrieval[0].response_body)
ignition_ip = length(var.ignition_ip) > 0 ? var.ignition_ip[0].instance_ip : length(local.bastion_private_ip) > 0 ? local.bastion_private_ip[0].instance_ip : "bad-ip"
}

# Modeled off the OpenShift Installer work for IPI PowerVS
Expand Down

0 comments on commit 3218b98

Please sign in to comment.