-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeconfig.tf
69 lines (54 loc) · 1.94 KB
/
kubeconfig.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
data "remote_file" "ocp_kubeconfig" {
depends_on = [
null_resource.ocp_install,
]
conn {
host = var.kvm_host_ip_address
user = var.kvm_host_username
private_key = file(var.path_to_kvm_host_login_ssh_key)
}
path = "/aicli/kubeconfig.${var.ocp_cluster_name}"
}
data "remote_file" "ocp_kubeadmin_password" {
depends_on = [
null_resource.ocp_install,
]
conn {
host = var.kvm_host_ip_address
user = var.kvm_host_username
private_key = file(var.path_to_kvm_host_login_ssh_key)
}
path = "/aicli/kubeadmin-password.${var.ocp_cluster_name}"
}
resource "local_file" "ocp_kubeconfig" {
content = data.remote_file.ocp_kubeconfig.content
filename = "${path.module}/output/ocp-kubeconfig"
}
resource "local_file" "ocp_kubeadmin_password" {
content = data.remote_file.ocp_kubeadmin_password.content
filename = "${abspath(path.module)}/output/ocp-kubeadmin-password"
}
output "ocp_path_to_kubeconfig_file" {
description = "ocp kubeconfig location to access the k8s api server"
value = local_file.ocp_kubeconfig.filename
}
resource "null_resource" "post_install_script" {
count = var.kube_api_server_ip != "" ? 1 : 0
depends_on = [local_file.ocp_kubeconfig]
provisioner "local-exec" {
command = <<-EOT
sudo sed -i "/$API_FQDN/d" /etc/hosts;
sudo sed -i "/$CONSOLE_FQDN/d" /etc/hosts;
sudo sed -i "/$AUTH_FQDN/d" /etc/hosts;
echo $IP $API_FQDN | sudo tee -a /etc/hosts;
echo $IP $CONSOLE_FQDN | sudo tee -a /etc/hosts;
echo $IP $AUTH_FQDN | sudo tee -a /etc/hosts;
EOT
environment = {
API_FQDN = "api.${var.ocp_cluster_name}.${var.ocp_base_domain}"
CONSOLE_FQDN = "console-openshift-console.apps.${var.ocp_cluster_name}.${var.ocp_base_domain}"
AUTH_FQDN = "oauth-openshift.apps.${var.ocp_cluster_name}.${var.ocp_base_domain}"
IP = var.kube_api_server_ip
}
}
}