From e25ea09ed41b17f35fd5d5871809d1814c0a2213 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Fri, 27 Oct 2023 18:18:20 +0100 Subject: [PATCH] Add juju initial bits, and increase multi instances --- juju/home-maas/00-init.tf | 1 + juju/home-maas/00-variables.tf | 10 ++ juju/home-maas/01-cloud.tf | 20 +++ juju/home-maas/03-machines.tf | 9 ++ juju/home-maas/05-ceph.tf | 124 ++++++++++++++++++ juju/home-maas/terraform.tfvars | 21 +++ juju/home-maas/user-data.yaml | 43 ++++++ juju/init.tf | 8 ++ init.tf => maas/init.tf | 0 .../create-multiple-instances.tf | 2 +- 10 files changed, 237 insertions(+), 1 deletion(-) create mode 120000 juju/home-maas/00-init.tf create mode 100644 juju/home-maas/00-variables.tf create mode 100644 juju/home-maas/01-cloud.tf create mode 100644 juju/home-maas/03-machines.tf create mode 100644 juju/home-maas/05-ceph.tf create mode 100644 juju/home-maas/terraform.tfvars create mode 100644 juju/home-maas/user-data.yaml create mode 100644 juju/init.tf rename init.tf => maas/init.tf (100%) diff --git a/juju/home-maas/00-init.tf b/juju/home-maas/00-init.tf new file mode 120000 index 0000000..50b2494 --- /dev/null +++ b/juju/home-maas/00-init.tf @@ -0,0 +1 @@ +../init.tf \ No newline at end of file diff --git a/juju/home-maas/00-variables.tf b/juju/home-maas/00-variables.tf new file mode 100644 index 0000000..211966f --- /dev/null +++ b/juju/home-maas/00-variables.tf @@ -0,0 +1,10 @@ +variable openstack-origin { + type = string + default = "distro" +} + +variable osd-devices { + type = string + default = "" +} + diff --git a/juju/home-maas/01-cloud.tf b/juju/home-maas/01-cloud.tf new file mode 100644 index 0000000..df17b7c --- /dev/null +++ b/juju/home-maas/01-cloud.tf @@ -0,0 +1,20 @@ +resource "juju_model" "cpe-focal" { + name = "cpe-focal" + + cloud { + name = "home-maas" + } + + config = { + cloudinit-userdata = file("user-data.yaml") + + apt-mirror = "http://192.168.1.12/archive.ubuntu.com/ubuntu" + lxd-snap-channel = "5.0/stable" + + container-image-metadata-url = "http://192.168.1.12/lxd/" + container-image-stream = "released" + + agent-metadata-url = "http://192.168.1.12/juju/tools/" + agent-stream = "released" + } +} diff --git a/juju/home-maas/03-machines.tf b/juju/home-maas/03-machines.tf new file mode 100644 index 0000000..fa312b5 --- /dev/null +++ b/juju/home-maas/03-machines.tf @@ -0,0 +1,9 @@ +resource "juju_machine" "all_machines" { + for_each = { + for index, machine in var.machines: + machine.machine_id => machine + } + model = juju_model.cpe-focal.name + name = each.value.machine_id + constraints = each.value.constraints +} diff --git a/juju/home-maas/05-ceph.tf b/juju/home-maas/05-ceph.tf new file mode 100644 index 0000000..5c94616 --- /dev/null +++ b/juju/home-maas/05-ceph.tf @@ -0,0 +1,124 @@ + +resource "juju_application" "ceph-osd" { + name = "ceph-osd" + + model = juju_model.cpe-focal.name + + charm { + name = "ceph-osd" + channel = "octopus/stable" + } + + units = 8 + #placement = "1000,1002,1003,1004,1005,1006,1007" + + config = { + osd-devices = var.osd-devices + source = var.openstack-origin + autotune = "false" + aa-profile-mode = "complain" + bluestore = "true" + osd-encrypt = "true" + osd-encrypt-keymanager = "vault" + } +} + + +resource "juju_application" "ceph-mon" { + name = "ceph-mon" + + model = juju_model.cpe-focal.name + + charm { + name = "ceph-mon" + channel = "octopus/stable" + } + + units = 3 + + config = { + expected-osd-count = 12 + source = var.openstack-origin + monitor-count = 3 + customize-failure-domain = true + } +} + +resource "juju_application" "ceph-radosgw" { + name = "ceph-radosgw" + + model = juju_model.cpe-focal.name + + charm { + name = "ceph-radosgw" + channel = "octopus/stable" + } + + units = 3 + + config = { + source: var.openstack-origin + vip = "10.0.1.224" + region = "RegionOne" + operator-roles = "Member,admin" # Contrail requires admin and not Admin + } +} + +resource "juju_application" "hacluster-radosgw" { + name = "hacluster-radosgw" + + model = juju_model.cpe-focal.name + + charm { + name = "hacluster" + channel = "2.0.3/stable" + } + +} + +resource "juju_integration" "osd-mon" { + + model = juju_model.cpe-focal.name + + application { + name = juju_application.ceph-osd.name + endpoint = "mon" + } + + application { + name = juju_application.ceph-mon.name + endpoint = "osd" + } +} + + +resource "juju_integration" "rgw-mon" { + + model = juju_model.cpe-focal.name + + application { + name = juju_application.ceph-radosgw.name + endpoint = "mon" + } + + application { + name = juju_application.ceph-mon.name + endpoint = "radosgw" + } +} + + +resource "juju_integration" "rgw-ha" { + + model = juju_model.cpe-focal.name + + application { + name = juju_application.ceph-radosgw.name + endpoint = "ha" + } + + application { + name = juju_application.hacluster-radosgw.name + endpoint = "ha" + } +} diff --git a/juju/home-maas/terraform.tfvars b/juju/home-maas/terraform.tfvars new file mode 100644 index 0000000..4b20ae8 --- /dev/null +++ b/juju/home-maas/terraform.tfvars @@ -0,0 +1,21 @@ +machines = [ + {machine_id=100,constraints="tags=control,asrock01"}, + {machine_id=101,constraints="tags=control,asrock02"}, + {machine_id=102,constraints="tags=control,asrock03"}, + {machine_id=103,constraints="tags=control,asrock04 spaces=oam"}, + {machine_id=104,constraints="tags=control,asrock02"}, + {machine_id=105,constraints="tags=control,asrock01"}, # needs to be asrock03 + {machine_id=400,constraints="tags=compute,asrock01"}, + {machine_id=401,constraints="tags=compute,asrock02"}, + {machine_id=402,constraints="tags=compute,asrock03"}, + {machine_id=1000,constraints="tags=compute,asrock01"}, + {machine_id=1001,constraints="tags=compute,asrock01"}, + {machine_id=1002,constraints="tags=compute,asrock02"}, + {machine_id=1003,constraints="tags=compute,asrock02"}, + {machine_id=1004,constraints="tags=compute,asrock03"}, + {machine_id=1005,constraints="tags=compute,asrock03"}, + {machine_id=1006,constraints="tags=compute,asrock04"}, + {machine_id=1007,constraints="tags=compute,asrock04"}, +] + +osd-devices = "/dev/sdb /dev/sdc" diff --git a/juju/home-maas/user-data.yaml b/juju/home-maas/user-data.yaml new file mode 100644 index 0000000..a2a3e78 --- /dev/null +++ b/juju/home-maas/user-data.yaml @@ -0,0 +1,43 @@ +apt: + primary: + - arches: [amd64] + uri: http://192.168.1.12/archive.ubuntu.com/ubuntu +write_files: +- owner: root:root + path: /root/99-post-juju.yaml + permissions: '0644' + content: | + network: + version: 2 + ethernets: + ens3: + link-local: [] + ens4: + link-local: [] + ens5: + link-local: [] + ens6: + link-local: [] + ens7: + link-local: [] + ens8: + link-local: [] + ens9: + link-local: [] +- owner: root:root + path: /etc/systemd/network/99-default.link + permissions: '0644' + content: | + [Link] + NamePolicy=keep kernel database onboard path slot +preruncmd: + - locale-gen en_GB.UTF-8; update-locale + - "systemd-detect-virt --container && rm -rf /root/99-post-juju.yaml" + - "systemd-detect-virt --container && sudo snap remove --purge lxd" + - "! systemd-detect-virt --container && mv /root/99-post-juju.yaml /etc/netplan/99-post-juju.yaml" + - "! systemd-detect-virt --container && sudo lxc profile set default security.nesting true" + - sudo netplan apply + - "! systemd-detect-virt --container && update-initramfs -u -k all" +snap: + commands: + "00": systemctl restart snapd diff --git a/juju/init.tf b/juju/init.tf new file mode 100644 index 0000000..cfdf05f --- /dev/null +++ b/juju/init.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + juju = { + version = "~> 0.10.0" + source = "juju/juju" + } + } +} diff --git a/init.tf b/maas/init.tf similarity index 100% rename from init.tf rename to maas/init.tf diff --git a/openstack/multi-instances/create-multiple-instances.tf b/openstack/multi-instances/create-multiple-instances.tf index 868e254..483a117 100644 --- a/openstack/multi-instances/create-multiple-instances.tf +++ b/openstack/multi-instances/create-multiple-instances.tf @@ -8,7 +8,7 @@ data "openstack_images_image_v2" "bionic-raw" { } resource "openstack_compute_instance_v2" "test_servers" { - count = 3 + count = 7 name = format("%s_%02d", "test_server", count.index+1) flavor_id = data.openstack_compute_flavor_v2.m1_small.id key_pair = "arif-key"