|
| 1 | +# Copyright 2017, 2019, Oracle Corporation and/or affiliates. All rights reserved. |
| 2 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl |
| 3 | + |
| 4 | +# kubectl |
| 5 | +data "template_file" "install_kubectl" { |
| 6 | + template = file("${path.module}/scripts/install_kubectl.template.sh") |
| 7 | +} |
| 8 | + |
| 9 | +resource "null_resource" "install_kubectl_operator" { |
| 10 | + connection { |
| 11 | + host = var.oke_operator.operator_private_ip |
| 12 | + private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 13 | + timeout = "40m" |
| 14 | + type = "ssh" |
| 15 | + user = "opc" |
| 16 | + |
| 17 | + bastion_host = var.oke_operator.bastion_public_ip |
| 18 | + bastion_user = "opc" |
| 19 | + bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 20 | + } |
| 21 | + |
| 22 | + provisioner "file" { |
| 23 | + content = data.template_file.install_kubectl.rendered |
| 24 | + destination = "~/install_kubectl.sh" |
| 25 | + } |
| 26 | + |
| 27 | + provisioner "remote-exec" { |
| 28 | + inline = [ |
| 29 | + "chmod +x $HOME/install_kubectl.sh", |
| 30 | + "bash $HOME/install_kubectl.sh", |
| 31 | + "rm -f $HOME/install_kubectl.sh" |
| 32 | + ] |
| 33 | + } |
| 34 | + |
| 35 | + count = var.oke_operator.bastion_enabled == true && var.oke_operator.operator_enabled == true ? 1 : 0 |
| 36 | +} |
| 37 | + |
| 38 | +# wait for 1. operator being ready 2. kubectl is installed (the script will create the .kube directory) |
| 39 | +resource null_resource "wait_for_operator" { |
| 40 | + connection { |
| 41 | + host = var.oke_operator.operator_private_ip |
| 42 | + private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 43 | + timeout = "40m" |
| 44 | + type = "ssh" |
| 45 | + user = "opc" |
| 46 | + |
| 47 | + bastion_host = var.oke_operator.bastion_public_ip |
| 48 | + bastion_user = "opc" |
| 49 | + bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 50 | + } |
| 51 | + |
| 52 | + depends_on = [null_resource.install_kubectl_operator] |
| 53 | + |
| 54 | + provisioner "remote-exec" { |
| 55 | + inline = [ |
| 56 | + "while [ ! -f /home/opc/operator.finish ]; do sleep 10; done", |
| 57 | + ] |
| 58 | + } |
| 59 | + |
| 60 | + count = var.oke_operator.bastion_enabled == true && var.oke_operator.operator_enabled == true ? 1 : 0 |
| 61 | +} |
| 62 | + |
| 63 | +# helm |
| 64 | +data "template_file" "install_helm" { |
| 65 | + template = file("${path.module}/scripts/install_helm.template.sh") |
| 66 | + |
| 67 | + count = var.oke_operator.operator_enabled == true ? 1 : 0 |
| 68 | +} |
| 69 | + |
| 70 | +resource null_resource "install_helm_operator" { |
| 71 | + connection { |
| 72 | + host = var.oke_operator.operator_private_ip |
| 73 | + private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 74 | + timeout = "40m" |
| 75 | + type = "ssh" |
| 76 | + user = "opc" |
| 77 | + |
| 78 | + bastion_host = var.oke_operator.bastion_public_ip |
| 79 | + bastion_user = "opc" |
| 80 | + bastion_private_key = file(var.oke_ssh_keys.ssh_private_key_path) |
| 81 | + } |
| 82 | + |
| 83 | + depends_on = [null_resource.install_kubectl_operator, null_resource.write_kubeconfig_on_operator] |
| 84 | + |
| 85 | + provisioner "file" { |
| 86 | + content = data.template_file.install_helm[0].rendered |
| 87 | + destination = "~/install_helm.sh" |
| 88 | + } |
| 89 | + |
| 90 | + provisioner "remote-exec" { |
| 91 | + inline = [ |
| 92 | + "chmod +x $HOME/install_helm.sh", |
| 93 | + "bash $HOME/install_helm.sh", |
| 94 | + "rm -f $HOME/install_helm.sh" |
| 95 | + ] |
| 96 | + } |
| 97 | + |
| 98 | + count = var.oke_operator.bastion_enabled == true && var.oke_operator.operator_enabled == true ? 1 : 0 |
| 99 | +} |
0 commit comments