diff --git a/juju/home-maas/00-variables.tf b/juju/home-maas/00-variables.tf index dd31ceb..455903a 100644 --- a/juju/home-maas/00-variables.tf +++ b/juju/home-maas/00-variables.tf @@ -1,3 +1,32 @@ +######## vars to change as per env +variable "cloud" { + type = string + default = "home-maas" +} + +variable "num_units" { + type = number + default = 3 +} + +variable "controller_ids" { + type = list(string) + default = ["100", "101", "102", + "103", "104", "105"] +} + +variable "compute_ids" { + type = list(string) + default = ["1000", "1001", "1002", "1003", + "1004", "1005", "1006", "1007"] +} + +variable "apt_mirror" { + type = string + default = "192.168.1.12" +} + +######## vars unlikely to be changed variable "machines" { type = list(object({ machine_id = number @@ -35,6 +64,71 @@ variable mysql-channel { default = "8.0/stable" } +variable mysql-router-channel { + type = string + default = "8.0/stable" +} + +variable "hacluster-channel" { + type = string + default = "2.0.3/stable" +} + +variable "rabbitmq-server-channel" { + type = string + default = "3.8/stable" +} + +variable "ceph-channel" { + type = string + default = "octopus/stable" +} + +variable "lxd_snap_channel" { + type = string + default = "5.0/stable" +} + +variable "sysconfig_compute_channel" { + type = string + default = "latest/stable" +} + +variable "sysconfig_compute_revision" { + type = string + default = "19" +} + +variable "ubuntu_channel" { + type = string + default = "latest/stable" +} + +variable "ubuntu_revision" { + type = string + default = "24" +} + +variable "vault_channel" { + type = string + default = "1.7/stable" +} + +variable "etcd_channel" { + type = string + default = "latest/stable" +} + +variable "etcd_revision" { + type = string + default = "583" +} + +variable "easyrsa_channel" { + type = string + default = "latest/stable" +} + variable osd-devices { type = string default = "" diff --git a/juju/home-maas/01-cloud.tf b/juju/home-maas/01-cloud.tf index 4c393e7..01e057e 100644 --- a/juju/home-maas/01-cloud.tf +++ b/juju/home-maas/01-cloud.tf @@ -2,19 +2,19 @@ resource "juju_model" "openstack" { name = var.model-name cloud { - name = "home-maas" + name = var.cloud } config = { cloudinit-userdata = file("user-data.yaml") - apt-mirror = "http://192.168.1.12/archive.ubuntu.com/ubuntu" - lxd-snap-channel = "5.0/stable" + apt-mirror = "http://${var.apt_mirror}/archive.ubuntu.com/ubuntu" + lxd-snap-channel = var.lxd_snap_channel - container-image-metadata-url = "http://192.168.1.12/lxd/" + container-image-metadata-url = "http://${var.apt_mirror}/lxd/" container-image-stream = "released" - agent-metadata-url = "http://192.168.1.12/juju/tools/" + agent-metadata-url = "http://${var.apt_mirror}/juju/tools/" agent-stream = "released" } } diff --git a/juju/home-maas/04-keystone.tf b/juju/home-maas/04-keystone.tf index 42a0321..449586b 100644 --- a/juju/home-maas/04-keystone.tf +++ b/juju/home-maas/04-keystone.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "keystone-1" { +resource "juju_machine" "keystone" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "keystone-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "keystone-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index+var.num_units]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "keystone" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.keystone-1.machine_id, - juju_machine.keystone-2.machine_id, - juju_machine.keystone-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.keystone[index].machine_id ]))}" endpoint_bindings = [{ @@ -66,7 +56,7 @@ resource "juju_application" "keystone-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -93,7 +83,7 @@ resource "juju_application" "hacluster-keystone" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/04-mysql.tf b/juju/home-maas/04-mysql.tf index 2e0f3e1..0b41852 100644 --- a/juju/home-maas/04-mysql.tf +++ b/juju/home-maas/04-mysql.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "mysql-1" { +resource "juju_machine" "mysql" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "mysql-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "mysql-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -25,12 +16,11 @@ resource "juju_application" "mysql-innodb-cluster" { base = var.default-base } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.mysql-1.machine_id, - juju_machine.mysql-2.machine_id, - juju_machine.mysql-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.mysql[index].machine_id ]))}" endpoint_bindings = [{ diff --git a/juju/home-maas/04-rmq.tf b/juju/home-maas/04-rmq.tf index 3b485b2..a577516 100644 --- a/juju/home-maas/04-rmq.tf +++ b/juju/home-maas/04-rmq.tf @@ -1,19 +1,9 @@ -resource "juju_machine" "rmq-1" { +resource "juju_machine" "rmq" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids_high[count.index+var.num_units]].machine_id]) constraints = "spaces=oam" } -resource "juju_machine" "rmq-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "rmq-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) - constraints = "spaces=oam" -} - resource "juju_application" "rabbitmq-server" { name = "rabbitmq-server" @@ -22,15 +12,14 @@ resource "juju_application" "rabbitmq-server" { charm { name = "rabbitmq-server" - channel = "3.8/stable" + channel = var.rabbitmq-server-channel } units = 3 - placement = "${join(",",sort([ - juju_machine.rmq-1.machine_id, - juju_machine.rmq-2.machine_id, - juju_machine.rmq-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.rmq[index].machine_id ]))}" endpoint_bindings = [{ diff --git a/juju/home-maas/05-ceilometer.tf b/juju/home-maas/05-ceilometer.tf index 15f0cf6..18d0751 100644 --- a/juju/home-maas/05-ceilometer.tf +++ b/juju/home-maas/05-ceilometer.tf @@ -1,19 +1,9 @@ -resource "juju_machine" "ceilometer-1" { +resource "juju_machine" "ceilometer" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids_high[count.index+var.num_units]].machine_id]) constraints = "spaces=oam" } -resource "juju_machine" "ceilometer-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "ceilometer-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) - constraints = "spaces=oam" -} - resource "juju_application" "ceilometer" { name = "ceilometer" @@ -27,10 +17,9 @@ resource "juju_application" "ceilometer" { units = 3 - placement = "${join(",",sort([ - juju_machine.ceilometer-1.machine_id, - juju_machine.ceilometer-2.machine_id, - juju_machine.ceilometer-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.ceilometer[index].machine_id ]))}" endpoint_bindings = [{ diff --git a/juju/home-maas/05-ceph.tf b/juju/home-maas/05-ceph.tf index 45cf302..3451a42 100644 --- a/juju/home-maas/05-ceph.tf +++ b/juju/home-maas/05-ceph.tf @@ -5,20 +5,15 @@ resource "juju_application" "ceph-osd" { charm { name = "ceph-osd" - channel = "octopus/stable" + channel = var.ceph-osd-channel } - units = 8 - placement = "${join(",",sort([ - juju_machine.all_machines["1000"].machine_id, - juju_machine.all_machines["1001"].machine_id, - juju_machine.all_machines["1002"].machine_id, - juju_machine.all_machines["1003"].machine_id, - juju_machine.all_machines["1004"].machine_id, - juju_machine.all_machines["1005"].machine_id, - juju_machine.all_machines["1006"].machine_id, - juju_machine.all_machines["1007"].machine_id, - ]))}" + units = length(var.compute_ids) + + placement = "${join(",", sort([ + for index, _ in var.compute_ids : + juju_machine.all_machines[index].machine_id + ]))}" config = { osd-devices = var.osd-devices @@ -32,19 +27,10 @@ resource "juju_application" "ceph-osd" { } } -resource "juju_machine" "ceph-mon-1" { +resource "juju_machine" "ceph-mon" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam,ceph-access,ceph-replica" -} -resource "juju_machine" "ceph-mon-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam,ceph-access,ceph-replica" -} -resource "juju_machine" "ceph-mon-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam,ceph-access,ceph-replica" } @@ -55,15 +41,14 @@ resource "juju_application" "ceph-mon" { charm { name = "ceph-mon" - channel = "octopus/stable" + channel = var.ceph-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.ceph-mon-1.machine_id, - juju_machine.ceph-mon-2.machine_id, - juju_machine.ceph-mon-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.ceph-mon[index].machine_id ]))}" endpoint_bindings = [{ @@ -93,19 +78,10 @@ resource "juju_application" "ceph-mon" { } } -resource "juju_machine" "ceph-rgw-1" { +resource "juju_machine" "ceph-rgw" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam,ceph-access" -} -resource "juju_machine" "ceph-rgw-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam,ceph-access" -} -resource "juju_machine" "ceph-rgw-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam,ceph-access" } @@ -116,15 +92,14 @@ resource "juju_application" "ceph-radosgw" { charm { name = "ceph-radosgw" - channel = "octopus/stable" + channel = var.ceph-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.ceph-rgw-1.machine_id, - juju_machine.ceph-rgw-2.machine_id, - juju_machine.ceph-rgw-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.ceph-rgw[index].machine_id ]))}" endpoint_bindings = [{ @@ -161,7 +136,7 @@ resource "juju_application" "hacluster-radosgw" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-cinder.tf b/juju/home-maas/05-cinder.tf index 8848173..bc0fd3e 100644 --- a/juju/home-maas/05-cinder.tf +++ b/juju/home-maas/05-cinder.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "cinder-1" { +resource "juju_machine" "cinder" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "cinder-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "cinder-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "cinder" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.cinder-1.machine_id, - juju_machine.cinder-2.machine_id, - juju_machine.cinder-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.cinder[index].machine_id ]))}" endpoint_bindings = [{ @@ -85,7 +75,7 @@ resource "juju_application" "cinder-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -112,7 +102,7 @@ resource "juju_application" "hacluster-cinder" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-glance.tf b/juju/home-maas/05-glance.tf index 9dd8396..9b382ec 100644 --- a/juju/home-maas/05-glance.tf +++ b/juju/home-maas/05-glance.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "glance-1" { +resource "juju_machine" "glance" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "glance-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "glance-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "glance" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.glance-1.machine_id, - juju_machine.glance-2.machine_id, - juju_machine.glance-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.glance[index].machine_id ]))}" endpoint_bindings = [{ @@ -65,7 +55,7 @@ resource "juju_application" "glance-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -92,7 +82,7 @@ resource "juju_application" "hacluster-glance" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-gnocchi.tf b/juju/home-maas/05-gnocchi.tf index 412d36a..bba71cd 100644 --- a/juju/home-maas/05-gnocchi.tf +++ b/juju/home-maas/05-gnocchi.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "gnocchi-1" { +resource "juju_machine" "gnocchi" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) - constraints = "spaces=oam,ceph-access" -} -resource "juju_machine" "gnocchi-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam,ceph-access" -} -resource "juju_machine" "gnocchi-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index+var.num_units]].machine_id]) constraints = "spaces=oam,ceph-access" } @@ -24,12 +15,11 @@ resource "juju_application" "gnocchi" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.gnocchi-1.machine_id, - juju_machine.gnocchi-2.machine_id, - juju_machine.gnocchi-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.gnocchi[index].machine_id ]))}" endpoint_bindings = [{ @@ -70,7 +60,7 @@ resource "juju_application" "gnocchi-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -97,7 +87,7 @@ resource "juju_application" "hacluster-gnocchi" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-heat.tf b/juju/home-maas/05-heat.tf index 7e08620..95b7464 100644 --- a/juju/home-maas/05-heat.tf +++ b/juju/home-maas/05-heat.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "heat-1" { +resource "juju_machine" "heat" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "heat-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "heat-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "heat" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.heat-1.machine_id, - juju_machine.heat-2.machine_id, - juju_machine.heat-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.heat[index].machine_id ]))}" endpoint_bindings = [{ @@ -65,7 +55,7 @@ resource "juju_application" "heat-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -92,7 +82,7 @@ resource "juju_application" "hacluster-heat" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-memcache.tf b/juju/home-maas/05-memcache.tf index 3a70f88..b6f82de 100644 --- a/juju/home-maas/05-memcache.tf +++ b/juju/home-maas/05-memcache.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "memcache-1" { +resource "juju_machine" "memcache" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "memcache-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "memcache-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -25,14 +16,14 @@ resource "juju_application" "memcached" { base = var.default-base } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.memcache-1.machine_id, - juju_machine.memcache-2.machine_id, - juju_machine.memcache-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.memcached[index].machine_id ]))}" + endpoint_bindings = [{ space = var.internal-space },{ diff --git a/juju/home-maas/05-nova.tf b/juju/home-maas/05-nova.tf index 5ea3c57..0e99924 100644 --- a/juju/home-maas/05-nova.tf +++ b/juju/home-maas/05-nova.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "ncc-1" { +resource "juju_machine" "ncc" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "ncc-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "ncc-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index+var.num_units]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "nova-cloud-controller" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.ncc-1.machine_id, - juju_machine.ncc-2.machine_id, - juju_machine.ncc-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.ncc[index].machine_id ]))}" endpoint_bindings = [{ @@ -73,7 +63,7 @@ resource "juju_application" "nova-cloud-controller-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -100,7 +90,7 @@ resource "juju_application" "hacluster-nova" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/05-placement.tf b/juju/home-maas/05-placement.tf index e6a0de8..d15278c 100644 --- a/juju/home-maas/05-placement.tf +++ b/juju/home-maas/05-placement.tf @@ -1,16 +1,7 @@ -resource "juju_machine" "placement-1" { +resource "juju_machine" "placement" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["103"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "placement-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["104"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "placement-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["105"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index+var.num_units]].machine_id]) constraints = "spaces=oam" } @@ -24,12 +15,11 @@ resource "juju_application" "placement" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.placement-1.machine_id, - juju_machine.placement-2.machine_id, - juju_machine.placement-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, var.num_units, length(var.controller_ids)) : + juju_machine.placement[index].machine_id ]))}" endpoint_bindings = [{ @@ -62,7 +52,7 @@ resource "juju_application" "placement-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -89,7 +79,7 @@ resource "juju_application" "hacluster-placement" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/06-nova-compute.tf b/juju/home-maas/06-nova-compute.tf index 4a48a28..6b2c383 100644 --- a/juju/home-maas/06-nova-compute.tf +++ b/juju/home-maas/06-nova-compute.tf @@ -8,17 +8,12 @@ resource "juju_application" "nova-compute-kvm" { channel = var.openstack-channel } - units = 8 - placement = "${join(",",sort([ - juju_machine.all_machines["1000"].machine_id, - juju_machine.all_machines["1001"].machine_id, - juju_machine.all_machines["1002"].machine_id, - juju_machine.all_machines["1003"].machine_id, - juju_machine.all_machines["1004"].machine_id, - juju_machine.all_machines["1005"].machine_id, - juju_machine.all_machines["1006"].machine_id, - juju_machine.all_machines["1007"].machine_id, - ]))}" + units = length(var.compute_ids) + + placement = "${join(",", sort([ + for index, _ in var.compute_ids : + juju_machine.all_machines[index].machine_id + ]))}" endpoint_bindings = [{ space = var.oam-space @@ -109,8 +104,8 @@ resource "juju_application" "sysconfig-compute" { charm { name = "sysconfig" - channel = "latest/stable" - revision = "19" + channel = var.sysconfig_compute_channel + revision = var.sysconfig_compute_revision } units = 0 diff --git a/juju/home-maas/07-controllers.tf b/juju/home-maas/07-controllers.tf index 9ce1cfc..b4ae5d1 100644 --- a/juju/home-maas/07-controllers.tf +++ b/juju/home-maas/07-controllers.tf @@ -5,20 +5,17 @@ resource "juju_application" "controller-server" { charm { name = "ubuntu" - channel = "latest/stable" - revision = "24" + channel = var.ubuntu_channel + revision = var.ubuntu_revision base = var.default-base } - units = 6 - placement = "${join(",",sort([ - juju_machine.all_machines["100"].machine_id, - juju_machine.all_machines["101"].machine_id, - juju_machine.all_machines["102"].machine_id, - juju_machine.all_machines["103"].machine_id, - juju_machine.all_machines["104"].machine_id, - juju_machine.all_machines["105"].machine_id, - ]))}" + units = length(var.controller_ids) + + placement = "${join(",", sort([ + for index, _ in var.controller_ids : + juju_machine.all_machines[index].machine_id + ]))}" } resource "juju_application" "sysconfig-control" { @@ -28,8 +25,8 @@ resource "juju_application" "sysconfig-control" { charm { name = "sysconfig" - channel = "latest/stable" - revision = "22" + channel = var.sysconfig_compute_channel + revision = var.sysconfig_compute_revision } units = 0 diff --git a/juju/home-maas/08-neutron.tf b/juju/home-maas/08-neutron.tf index 6e1df0e..c5b9b3f 100644 --- a/juju/home-maas/08-neutron.tf +++ b/juju/home-maas/08-neutron.tf @@ -8,12 +8,12 @@ resource "juju_application" "neutron-gateway" { channel = var.openstack-channel } - units = 3 - placement = "${join(",",sort([ - juju_machine.all_machines["100"].machine_id, - juju_machine.all_machines["101"].machine_id, - juju_machine.all_machines["102"].machine_id, - ]))}" + units = var.num_units + + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.neutron-api[index].machine_id + ]))}" config = { @@ -27,19 +27,10 @@ resource "juju_application" "neutron-gateway" { } } -resource "juju_machine" "neutron-api-1" { +resource "juju_machine" "neutron-api" { + count = var.num_units model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["100"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "neutron-api-2" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["101"].machine_id]) - constraints = "spaces=oam" -} -resource "juju_machine" "neutron-api-3" { - model = var.model-name - placement = join(":",["lxd",juju_machine.all_machines["102"].machine_id]) + placement = join(":", ["lxd", juju_machine.all_machines[var.controller_ids[count.index]].machine_id]) constraints = "spaces=oam" } @@ -53,12 +44,11 @@ resource "juju_application" "neutron-api" { channel = var.openstack-channel } - units = 3 + units = var.num_units - placement = "${join(",",sort([ - juju_machine.neutron-api-1.machine_id, - juju_machine.neutron-api-2.machine_id, - juju_machine.neutron-api-3.machine_id, + placement = "${join(",", sort([ + for index, _ in slice(var.controller_ids, 0, var.num_units+1) : + juju_machine.neutron-api[index].machine_id ]))}" endpoint_bindings = [{ @@ -106,7 +96,7 @@ resource "juju_application" "neutron-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -133,7 +123,7 @@ resource "juju_application" "hacluster-neutron" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 diff --git a/juju/home-maas/10-vault.tf b/juju/home-maas/10-vault.tf index f95d9e7..8e245aa 100644 --- a/juju/home-maas/10-vault.tf +++ b/juju/home-maas/10-vault.tf @@ -21,7 +21,7 @@ resource "juju_application" "vault" { charm { name = "vault" - channel = "1.7/stable" + channel = var.vault_channel base = var.default-base } @@ -47,7 +47,7 @@ resource "juju_application" "vault-mysql-router" { charm { name = "mysql-router" - channel = "8.0/stable" + channel = var.mysql-router-channel } units = 0 @@ -76,7 +76,7 @@ resource "juju_application" "hacluster-vault" { charm { name = "hacluster" - channel = "2.0.3/stable" + channel = var.hacluster-channel } units = 0 @@ -106,9 +106,9 @@ resource "juju_application" "etcd" { charm { name = "etcd" - channel = "latest/stable" + channel = var.etcd_channel base = var.default-base - revision = 583 + revision = var.etcd_revision } placement = "${join(",",sort([ @@ -127,7 +127,7 @@ resource "juju_application" "etcd" { endpoint = "db" }] - units = 3 + units = var.num_units config = { channel = "3.2/stable" @@ -147,7 +147,7 @@ resource "juju_application" "easyrsa" { charm { name = "easyrsa" - channel = "latest/stable" + channel = var.easyrsa_channel base = var.default-base }