diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-07-24 12:53:07 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-07-24 12:53:07 +0200 |
commit | 77f494aade651e755ab2a9236beeb6d7d135ebd3 (patch) | |
tree | 351b4f9191a03bb63f89f546d6f1edb9c3c35902 | |
parent | 80feac92f77b92455be6573de731bf4921022dd4 (diff) | |
download | k8s-sandbox-77f494aade651e755ab2a9236beeb6d7d135ebd3.tar.gz k8s-sandbox-77f494aade651e755ab2a9236beeb6d7d135ebd3.tar.bz2 k8s-sandbox-77f494aade651e755ab2a9236beeb6d7d135ebd3.tar.xz k8s-sandbox-77f494aade651e755ab2a9236beeb6d7d135ebd3.zip |
wip
-rwxr-xr-x[-rw-r--r--] | terraform/ansible/inventory | 23 | ||||
-rw-r--r-- | terraform/master.tf | 2 | ||||
-rw-r--r-- | terraform/node.tf | 12 |
3 files changed, 32 insertions, 5 deletions
diff --git a/terraform/ansible/inventory b/terraform/ansible/inventory index 95f5046..24bbc2e 100644..100755 --- a/terraform/ansible/inventory +++ b/terraform/ansible/inventory @@ -1,5 +1,24 @@ #!/bin/bash -set -euo pipefail +read -r -d '' script <<'EOF' +to_entries|map({(.key|tostring):.value.value})|add as $input | + +$input.k8s_node_names|to_entries|map({(.value):{ + ansible_host:$input.k8s_node_public_ips[.key], + private_ip:$input.k8s_node_private_ips[.key]} + }) as $nodes | + +{ + ansible_host:$input.k8s_master_ip.public_ip, + private_ip:$input.k8s_master_ip.private_ip, +} as $master | -(cd .. && terraform output -json) | jq 'to_entries|map({(.key|tostring):.value.value})|add as $input | $input.k8s_node_ips|to_entries|map({("k8s-node"+(.key|tostring)):{ansible_host:.value}})|add + {"k8s-master":{ansible_host:$input.k8s_master_ip}}|{_meta:{hostvars:.}, all:(["k8s-master"] + ($input.k8s_node_ips|to_entries|map("k8s-node"+(.key|tostring)))) }' +{_meta:{ + hostvars:([{"k8s-master": $master}]+$nodes|add)}, + all:(["k8s-master"] + ($input.k8s_node_names)), + "k8s-nodes":$input.k8s_node_names, +} +EOF + +set -euo pipefail +(cd .. && terraform output -json) | jq "$script" diff --git a/terraform/master.tf b/terraform/master.tf index 34e8e43..0f8a675 100644 --- a/terraform/master.tf +++ b/terraform/master.tf @@ -18,5 +18,5 @@ resource "scaleway_server" "k8s_master" { } output "k8s_master_ip" { - value = scaleway_server.k8s_master.public_ip + value = {public_ip: scaleway_server.k8s_master.public_ip, private_ip: scaleway_server.k8s_master.private_ip} } diff --git a/terraform/node.tf b/terraform/node.tf index 538cada..eeb3fc6 100644 --- a/terraform/node.tf +++ b/terraform/node.tf @@ -8,7 +8,7 @@ resource "scaleway_server" "k8s_node" { type = "${var.k8s_master_server_type}" public_ip = "${element(scaleway_ip.k8s_node_ips.*.ip, count.index)}" - count = "${var.node_count}" + count = var.node_count tags = ["k8s", "k8s-node"] @@ -20,6 +20,14 @@ resource "scaleway_server" "k8s_node" { ] } -output "k8s_node_ips" { +output "k8s_node_names" { + value = scaleway_server.k8s_node.*.name +} + +output "k8s_node_public_ips" { value = scaleway_server.k8s_node.*.public_ip } + +output "k8s_node_private_ips" { + value = scaleway_server.k8s_node.*.private_ip +} |