Deploying an Ubuntu VM on OCI

Thought you could provision VMs manually using the OCI’s UI, I prefer using Terraform to manage it because you can manage infrastructure as code and provisioning and destroying are easily repeatable.

Here is Terraform code I used to provision my Ubuntu VM.

resource oci_core_instance ashburn-blog {
    compartment_id      = var.tenancy_ocid
    display_name        = "blog-host"
    availability_domain = "Gumm:US-ASHBURN-AD-1"
    shape               = "VM.Standard.E3.Flex"

    shape_config {
        memory_in_gbs = 2
        ocpus = 2
    }
    
    source_details {
        source_type = "image"
        source_id   = var.config["image_ocid"]
        boot_volume_size_in_gbs = 80
    }
    create_vnic_details {
        assign_public_ip = "true"
        hostname_label   = "blog-host"
        subnet_id        = var.config["public_subnet_ocid"]
    }
    metadata = {
        ssh_authorized_keys = file(var.public_ssh_key)
    }
}

Some values are defined in variables.tf file as variables as you can imagine. You may have to get the correct OCID for var.config[‘image_ocid’] by executing OCI CLI command. I have blogged how to list available images before, please refer to this blog post to list images and their OCID.

Once that’s ready, all you have to do is to run terraform apply to provision the VM as the way you want. (I didn’t realize I had 2 CPUs in the VM though I said I had 1 CPU for this blog. htop shows I have 2 CPUs.)

Author: admin

A software engineer in greater Seattle area

Leave a Reply

Your email address will not be published. Required fields are marked *