diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 2962f391eddd7300bc3978690da294fa8d7b0d87..06588c9b4667f1ec797bf29ab724b418f542bb21 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -1,6 +1,23 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/hashicorp/template" { + version = "2.2.0" + hashes = [ + "h1:94qn780bi1qjrbC3uQtjJh3Wkfwd5+tTtJHOb7KTg9w=", + "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", + "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", + "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", + "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", + "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", + "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", + "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", + "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", + "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", + "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", + ] +} + provider "registry.terraform.io/terraform-provider-openstack/openstack" { version = "1.35.0" constraints = "~> 1.35.0" diff --git a/compute.tf b/compute.tf index d721ae690c3ae3e2a0f037e78be31842e1263135..2d03eae2d001bfaddf153f5625095d9b8d3dc8b3 100644 --- a/compute.tf +++ b/compute.tf @@ -1,4 +1,5 @@ # data for reference image + data "openstack_images_image_v2" "base_image" { name = var.base_image_name } @@ -9,10 +10,22 @@ data "openstack_compute_flavor_v2" "m1_small" { name = "m1.small" } -# bastion node -resource "openstack_compute_instance_v2" "bastion" { - name = "bastion" +# template file cloud-init.yml + +data "template_file" "cloud_init_yml" { + template = file("${path.module}/templates/cloud-init.yml") + vars = { + sles_reg_code = var.sles_reg_code + sles_reg_email = var.sles_reg_email + sles_ses_reg = var.sles_ses_reg + } +} + +# manager node + +resource "openstack_compute_instance_v2" "mgr" { + name = "mgr" image_id = data.openstack_images_image_v2.base_image.id flavor_id = data.openstack_compute_flavor_v2.m1_small.id key_pair = var.ssh_keypair @@ -21,6 +34,8 @@ resource "openstack_compute_instance_v2" "bastion" { openstack_compute_secgroup_v2.allow_ssh.name ] + user_data = data.template_file.cloud_init_yml.rendered + block_device { # this is the image to clone from uuid = data.openstack_images_image_v2.base_image.id @@ -44,9 +59,9 @@ resource "openstack_compute_instance_v2" "bastion" { } } -resource "openstack_compute_floatingip_associate_v2" "bastion_association" { +resource "openstack_compute_floatingip_associate_v2" "mgr_association" { floating_ip = openstack_compute_floatingip_v2.floating_ip.address - instance_id = openstack_compute_instance_v2.bastion.id + instance_id = openstack_compute_instance_v2.mgr.id } # OSD nodes @@ -62,6 +77,8 @@ resource "openstack_compute_instance_v2" "osd" { "default" ] + user_data = data.template_file.cloud_init_yml.rendered + block_device { # this is the image to clone from uuid = data.openstack_images_image_v2.base_image.id @@ -102,6 +119,8 @@ resource "openstack_compute_instance_v2" "mds" { "default" ] + user_data = data.template_file.cloud_init_yml.rendered + block_device { # this is the image to clone from uuid = data.openstack_images_image_v2.base_image.id @@ -138,6 +157,8 @@ resource "openstack_compute_instance_v2" "mon" { "default" ] + user_data = data.template_file.cloud_init_yml.rendered + block_device { # this is the image to clone from uuid = data.openstack_images_image_v2.base_image.id diff --git a/networks.tf b/networks.tf index ba81251f76d2983ff2f8e8981f46bfc0e8d85706..95569582fef3c852ce2b57ec89ca87dea1354798 100644 --- a/networks.tf +++ b/networks.tf @@ -24,8 +24,9 @@ resource "openstack_networking_network_v2" "public_network" { } resource "openstack_networking_subnet_v2" "public_subnet" { - network_id = openstack_networking_network_v2.public_network.id - cidr = "10.0.0.0/24" + network_id = openstack_networking_network_v2.public_network.id + cidr = "10.0.0.0/24" + dns_nameservers = var.public_network_dns } # router diff --git a/outputs.tf b/outputs.tf index 118a6e53bfd7fb229cc7831b865248defb6d68ac..ff15da4ee4a9dea588eddc9525428c923f1b72f3 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,3 +1,3 @@ -output "bastion_ip_address" { +output "manager_ip_address" { value = openstack_compute_floatingip_v2.floating_ip.address } diff --git a/templates/cloud-init.yml b/templates/cloud-init.yml new file mode 100644 index 0000000000000000000000000000000000000000..ee4a44557b4de59d460274ce6e04e69c6d0160e9 --- /dev/null +++ b/templates/cloud-init.yml @@ -0,0 +1,5 @@ +#cloud-config + +runcmd: + - sudo SUSEConnect -r ${sles_reg_code} -e ${sles_reg_email} + - sudo SUSEConnect -p ses/7/x86_64 -r ${sles_ses_reg} diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 9ecb6c766a69ffdca063a2e92e81e751bbc24ba9..e4315622abc3605c45d0fe965c98c8159d589d0c 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -4,3 +4,6 @@ appcred_id = "application_credential_id" appcred_name = "application_credential_name" appcred_secret = "application_credential_secret" ssh_keypair = "ssh_keypair_name" +sles_reg_code = "suse registration code +sles_reg_email = "suse registration email" +sles_ses_reg = "suse storage extension registration code" diff --git a/variables.tf b/variables.tf index e0b694a6c469b00b997cef4b58606543f0234d0b..9cb38e900d09af947e81d0b6b9055a1954895a84 100644 --- a/variables.tf +++ b/variables.tf @@ -31,7 +31,7 @@ variable "ssh_keypair" { variable "base_image_name" { type = string - default = "sles-15-sp3-x86_64" + default = "sles-15-sp2-x86_64" description = "base image to use for the cluster" } @@ -40,3 +40,24 @@ variable "osd_node_count" { default = 3 description = "amount of OSD nodes to create" } + +variable "public_network_dns" { + type = list(string) + default = ["138.26.134.2"] + description = "dns to use for hosts - defaulted to one that works" +} + +variable "sles_reg_code" { + type = string + description = "Code to register instance with SUSE connect" +} + +variable "sles_reg_email" { + type = string + description = "Email to use for SUSE registration" +} + +variable "sles_ses_reg" { + type = string + description = "code to register for the storage package in SUSE" +}