Provisioning MVM Instances with Terraform

The latest release (v0.9.10) of the Morpheus Terraform provider now supports the ability to provision MVM instances. This enables instances to be quickly spun up and torn down using infrastructure as code (IaC). This is particularly useful when evaluating the features of MVM.

The following example provisions an MVM instance using the built-in Morpheus Ubuntu 22.04 virtual image.

data "morpheus_group" "morpheus_lab" {
  name = "platform engineering"
}

data "morpheus_cloud" "morpheus_cloud" {
  name = "MVM Cloud"
}

data "morpheus_instance_type" "ubuntu" {
  name = "Ubuntu"
}

data "morpheus_instance_layout" "ubuntu" {
  name    = "Single KVM VM"
  version = "22.04"
}

data "morpheus_network" "mvm_network" {
  name = "Compute"
}

data "morpheus_plan" "mvm" {
  name           = "2 CPU, 16GB Memory"
  provision_type = "KVM"
}

resource "morpheus_mvm_instance" "mvm_example" {
  name               = "mvmubuntu"
  description        = "MVM Terraform instance example"
  cloud_id           = data.morpheus_cloud.morpheus_cloud.id
  group_id           = data.morpheus_group.morpheus_lab.id
  instance_type_id   = data.morpheus_instance_type.ubuntu.id
  instance_layout_id = data.morpheus_instance_layout.ubuntu.id
  plan_id            = data.morpheus_plan.mvm.id
  environment        = "dev"
  resource_pool_name = "mvmcluster01"
  labels             = ["demo", "terraform"]
  create_user        = true

  network_interface {
    network_id = data.morpheus_network.mvm_network.id
    network_interface_type_id = 5
  }

  storage_volume {
    root         = true
    size         = 40
    name         = "root"
    storage_type = 1
    datastore_id = 49
  }

  storage_volume {
    root         = false
    size         = 15
    name         = "data"
    storage_type = 1
    datastore_id = 49
  }

  lifecycle {
    ignore_changes = [ evar ]
  }

  tags = {
    name = "ubuntutf"
  }

}

output "mvm_instance_ip_address" {
  value = morpheus_mvm_instance.mvm_example.primary_ip_address
}

Additional configuration options can be found in the Morpheus Terraform provider documentation for the mvm_instance resource - Terraform Registry

3 Likes

Awesome thanks for sharing @mreed once I have my MVM cluster setup I certainly will be testing the new mvm instance type within the Morpheus Terraform provider :slight_smile: