From 47b58e8c65862db76bade346ebe89d9e196ef7d6 Mon Sep 17 00:00:00 2001
From: Arif Ali <arif.ali@canonical.com>
Date: Wed, 29 Nov 2023 08:13:37 +0000
Subject: [PATCH] More terraform plans

* Add all the ceph juju resources
* Initial start of the MAAS resources
* test of a local-lxd juju environment
---
 juju/home-maas/05-ceph.tf     | 22 ++++++++++++++++------
 juju/local-lxd/00-init.tf     |  1 +
 juju/local-lxd/01-cloud.tf    | 21 +++++++++++++++++++++
 juju/local-lxd/user-data.yaml |  4 ++++
 maas/arif-home/00-init.tf     |  1 +
 maas/arif-home/00-spaces.tf   | 16 ++++++++++++++++
 6 files changed, 59 insertions(+), 6 deletions(-)
 create mode 120000 juju/local-lxd/00-init.tf
 create mode 100644 juju/local-lxd/01-cloud.tf
 create mode 100644 juju/local-lxd/user-data.yaml
 create mode 120000 maas/arif-home/00-init.tf
 create mode 100644 maas/arif-home/00-spaces.tf

diff --git a/juju/home-maas/05-ceph.tf b/juju/home-maas/05-ceph.tf
index 5c94616..6969a90 100644
--- a/juju/home-maas/05-ceph.tf
+++ b/juju/home-maas/05-ceph.tf
@@ -1,4 +1,3 @@
-
 resource "juju_application" "ceph-osd" {
   name = "ceph-osd"
 
@@ -10,16 +9,24 @@ resource "juju_application" "ceph-osd" {
   }
 
   units = 8
-  #placement = "1000,1002,1003,1004,1005,1006,1007"
+  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,
+   ]))}"
 
   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"
+    customize-failure-domain = "true"
   }
 }
 
@@ -52,6 +59,7 @@ resource "juju_application" "ceph-radosgw" {
   charm {
     name     = "ceph-radosgw"
     channel  = "octopus/stable"
+
   }
 
   units = 3
@@ -59,8 +67,10 @@ resource "juju_application" "ceph-radosgw" {
   config = {
       source: var.openstack-origin
       vip = "10.0.1.224"
-      region = "RegionOne"
-      operator-roles = "Member,admin" # Contrail requires admin and not Admin
+      operator-roles = "Member,admin"
+      os-admin-hostname    = "swift-internal.example.com"
+      os-internal-hostname = "swift-internal.example.com"
+      os-public-hostname   = "swift.example.com"
   }
 }
 
diff --git a/juju/local-lxd/00-init.tf b/juju/local-lxd/00-init.tf
new file mode 120000
index 0000000..50b2494
--- /dev/null
+++ b/juju/local-lxd/00-init.tf
@@ -0,0 +1 @@
+../init.tf
\ No newline at end of file
diff --git a/juju/local-lxd/01-cloud.tf b/juju/local-lxd/01-cloud.tf
new file mode 100644
index 0000000..bb5114a
--- /dev/null
+++ b/juju/local-lxd/01-cloud.tf
@@ -0,0 +1,21 @@
+resource "juju_model" "default" {
+  name = "default"
+
+  cloud {
+    name   = "localhost"
+    region = "localhost"
+  }
+
+  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/local-lxd/user-data.yaml b/juju/local-lxd/user-data.yaml
new file mode 100644
index 0000000..2a860c9
--- /dev/null
+++ b/juju/local-lxd/user-data.yaml
@@ -0,0 +1,4 @@
+apt:
+  primary:
+    - arches: [amd64]
+      uri: http://192.168.1.12/archive.ubuntu.com/ubuntu
diff --git a/maas/arif-home/00-init.tf b/maas/arif-home/00-init.tf
new file mode 120000
index 0000000..50b2494
--- /dev/null
+++ b/maas/arif-home/00-init.tf
@@ -0,0 +1 @@
+../init.tf
\ No newline at end of file
diff --git a/maas/arif-home/00-spaces.tf b/maas/arif-home/00-spaces.tf
new file mode 100644
index 0000000..e3de6b6
--- /dev/null
+++ b/maas/arif-home/00-spaces.tf
@@ -0,0 +1,16 @@
+locals {
+  spaces = ["external","oam","ceph-access","ceph-replica","overlay","admin","internal"]
+}
+
+resource "maas_space" "maas_spaces" {
+
+  for_each = toset(local.spaces)
+  name = each.value
+
+}
+
+resource "maas_fabric" "fabric-0" {
+
+  name = "fabric-0"
+
+}