Last active
December 27, 2016 21:26
-
-
Save donovanmuller/23f902ffd637ce9f2022e6f4d7cfe756 to your computer and use it in GitHub Desktop.
Terraform plan file to provision GCE hosts for OpenShift Origin install with openshift-ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "master_instances" { | |
description = "How many OpenShift master instances do you need?" | |
default = 1 | |
} | |
variable "node_instances" { | |
description = "How many OpenShift node instances do you need?" | |
default = 2 | |
} | |
provider "google" { | |
credentials = "${file("xxx.json")}" | |
project = "${var.project}" | |
region = "${var.region}" | |
} | |
resource "google_compute_instance" "oso_masters" { | |
name = "oso-master-${format("%02d", count.index + 1)}" | |
description = "OpenShift 3 master node ${format("%02d", count.index + 1)}" | |
machine_type = "g1-small" | |
zone = "${var.region}" | |
tags = ["oso-master"] | |
count = "${var.master_instances}" | |
disk { | |
image = "centos-7-v20161212" | |
} | |
network_interface { | |
network = "default" | |
access_config { | |
// Ephemeral IP | |
} | |
} | |
scheduling { | |
preemptible = true | |
} | |
} | |
data "template_file" "master_host" { | |
template = "${file("templates/master_host.tpl")}" | |
count = "${var.master_instances}" | |
vars { | |
master_external_ip = "${element(google_compute_instance.oso_masters.*.network_interface.0.access_config.0.assigned_nat_ip, count.index)}" | |
} | |
} | |
resource "google_compute_instance" "oso_nodes" { | |
name = "oso-node-${format("%02d", count.index + 1)}" | |
description = "OpenShift 3 node ${format("%02d", count.index + 1)}" | |
machine_type = "g1-small" | |
zone = "${var.region}" | |
tags = ["oso-node"] | |
count = "${var.node_instances}" | |
disk { | |
image = "centos-7-v20161212" | |
} | |
network_interface { | |
network = "default" | |
access_config { | |
// Ephemeral IP | |
} | |
} | |
scheduling { | |
preemptible = true | |
} | |
} | |
data "template_file" "node_host" { | |
template = "${file("templates/node_host.tpl")}" | |
count = "${var.node_instances}" | |
vars { | |
node_external_ip = "${element(google_compute_instance.oso_nodes.*.network_interface.0.access_config.0.assigned_nat_ip, count.index)}" | |
} | |
} | |
data "template_file" "oso_inventory" { | |
template = "${file("templates/oso.tpl")}" | |
vars { | |
masters = "${join("", data.template_file.master_host.*.rendered)}" | |
master_count = "${var.master_instances}" | |
} | |
vars { | |
compute_nodes = "${join("", data.template_file.node_host.*.rendered)}" | |
compute_node_count = "${var.node_instances}" | |
} | |
} | |
output "rendered" { | |
value = "${data.template_file.oso_inventory.rendered}" | |
} | |
resource "null_resource" "inventory" { | |
provisioner "local-exec" { | |
command = "echo '${data.template_file.oso_inventory.rendered}' > ../gce/OSEv3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment