Skip to main content

Compute instances

In today's post, we are going to talk about compute instances in OCI.

First of all, what is a compute instance? A compute instance is the OCI resource that you must deploy to provision and manage compute hosts.

So, If you have the requirement to create a Virtual Machine (VM) or an infrastructure to host your application then you must use Compute Instance service.

OCI offers 2 flavours:

  • Bare Metal: Physical server without any virtualisation. Direct access to the hardware. The user has to manage the virtualisation layer, as well as the rest of the layers: OS, App Container, code... It is  a Single-Tenant Model, i.e. dedicated to only one client. It does not share hardware with other clients.
  • Virtual Machine: It is basically a Bare metal with a virtualisation layer (which is taken care of by the Cloud Provider). Therefore, it has a hypervisor where it can run VMs smaller than the BM. It is based on a Multi-Tenant model.

OCI also offers different shapes depending on the requirements of the application:

  • Standard: Designed for general purposes and applicable for a multitude of use cases. It defines a series of cores, memorys and nwtwork "T-shirts". You cannot reshape any of these resources independently, but must increase/decrease all of them together.
  • Flexible: Let you customize the number of OCPUs and the amount of memory allocated to an instance. The network bandwidth scale according the number of OCPUs.
  • DenseIO: Designed for large databases, big data workloads, and applications that require high-performance.
  • GPU: Recommended for hardware-accelerated workloads.
In the following I will show you how to create a compute instance in 2 different ways:

  • Manually from OCI Console
To access to the compute instance view in OCI, just navigate to Compute / Instance




After selecting the compartment in which you want to deploy the instance, select "Create Instance" button, and fill the required information.

Depending on the region in which you are deploying, you can select between 1 of the 3 available ADs, or you can only use the one available in that region.


Select also the image (OS. It can be different distribution of UNIX or Windows) and shape:

You will also need to choose the network segment on which the instance will reside. We will talk more in depth about networking in future posts:


And finally, you must indicate (or generate in OCI) the keys to access to the compute instance:


  • With Terraform code
Use the power of Infrastructure as Code to deploy it:

resource "oci_core_instance" "test_instance" {
    #Required
    availability_domain = var.instance_availability_domain
    compartment_id = var.compartment_id
    shape = var.instance_shape

    #Optional
    agent_config {

        #Optional
        are_all_plugins_disabled = var.instance_agent_config_are_all_plugins_disabled
        is_management_disabled = var.instance_agent_config_is_management_disabled
        is_monitoring_disabled = var.instance_agent_config_is_monitoring_disabled
        plugins_config {
            #Required
            desired_state = var.instance_agent_config_plugins_config_desired_state
            name = var.instance_agent_config_plugins_config_name
        }
    }
    availability_config {

        #Optional
        is_live_migration_preferred = var.instance_availability_config_is_live_migration_preferred
        recovery_action = var.instance_availability_config_recovery_action
    }
    compute_cluster_id = oci_core_compute_cluster.test_compute_cluster.id
    create_vnic_details {

        #Optional
        assign_ipv6ip = var.instance_create_vnic_details_assign_ipv6ip
        assign_private_dns_record = var.instance_create_vnic_details_assign_private_dns_record
        assign_public_ip = var.instance_create_vnic_details_assign_public_ip
        defined_tags = {"Operations.CostCenter"= "42"}
        display_name = var.instance_create_vnic_details_display_name
        freeform_tags = {"Department"= "Finance"}
        hostname_label = var.instance_create_vnic_details_hostname_label
        ipv6address_ipv6subnet_cidr_pair_details = var.instance_create_vnic_details_ipv6address_ipv6subnet_cidr_pair_details
        nsg_ids = var.instance_create_vnic_details_nsg_ids
        private_ip = var.instance_create_vnic_details_private_ip
        skip_source_dest_check = var.instance_create_vnic_details_skip_source_dest_check
        subnet_id = oci_core_subnet.test_subnet.id
        vlan_id = oci_core_vlan.test_vlan.id
    }
    dedicated_vm_host_id = oci_core_dedicated_vm_host.test_dedicated_vm_host.id
    defined_tags = {"Operations.CostCenter"= "42"}
    display_name = var.instance_display_name
    extended_metadata = {
        some_string = "stringA"
        nested_object = "{\"some_string\": \"stringB\", \"object\": {\"some_string\": \"stringC\"}}"
    }
    fault_domain = var.instance_fault_domain
    freeform_tags = {"Department"= "Finance"}
    hostname_label = var.instance_hostname_label
    instance_configuration_id = oci_core_instance_configuration.test_instance_configuration.id
    instance_options {

        #Optional
        are_legacy_imds_endpoints_disabled = var.instance_instance_options_are_legacy_imds_endpoints_disabled
    }
    ipxe_script = var.instance_ipxe_script
    is_pv_encryption_in_transit_enabled = var.instance_is_pv_encryption_in_transit_enabled
    launch_options {

        #Optional
        boot_volume_type = var.instance_launch_options_boot_volume_type
        firmware = var.instance_launch_options_firmware
        is_consistent_volume_naming_enabled = var.instance_launch_options_is_consistent_volume_naming_enabled
        is_pv_encryption_in_transit_enabled = var.instance_launch_options_is_pv_encryption_in_transit_enabled
        network_type = var.instance_launch_options_network_type
        remote_data_volume_type = var.instance_launch_options_remote_data_volume_type
    }
    metadata = var.instance_metadata
    platform_config {
        #Required
        type = var.instance_platform_config_type

        #Optional
        are_virtual_instructions_enabled = var.instance_platform_config_are_virtual_instructions_enabled
        config_map = var.instance_platform_config_config_map
        is_access_control_service_enabled = var.instance_platform_config_is_access_control_service_enabled
        is_input_output_memory_management_unit_enabled = var.instance_platform_config_is_input_output_memory_management_unit_enabled
        is_measured_boot_enabled = var.instance_platform_config_is_measured_boot_enabled
        is_memory_encryption_enabled = var.instance_platform_config_is_memory_encryption_enabled
        is_secure_boot_enabled = var.instance_platform_config_is_secure_boot_enabled
        is_symmetric_multi_threading_enabled = var.instance_platform_config_is_symmetric_multi_threading_enabled
        is_trusted_platform_module_enabled = var.instance_platform_config_is_trusted_platform_module_enabled
        numa_nodes_per_socket = var.instance_platform_config_numa_nodes_per_socket
        percentage_of_cores_enabled = var.instance_platform_config_percentage_of_cores_enabled
    }
    preemptible_instance_config {
        #Required
        preemption_action {
            #Required
            type = var.instance_preemptible_instance_config_preemption_action_type

            #Optional
            preserve_boot_volume = var.instance_preemptible_instance_config_preemption_action_preserve_boot_volume
        }
    }
    shape = var.instance_shape
    shape_config {

        #Optional
        baseline_ocpu_utilization = var.instance_shape_config_baseline_ocpu_utilization
        memory_in_gbs = var.instance_shape_config_memory_in_gbs
        nvmes = var.instance_shape_config_nvmes
        ocpus = var.instance_shape_config_ocpus
        vcpus = var.instance_shape_config_vcpus
    }
    source_details {
        #Required
        source_id = oci_core_image.test_image.id
        source_type = "image"

        #Optional
        boot_volume_size_in_gbs = var.instance_source_details_boot_volume_size_in_gbs
        boot_volume_vpus_per_gb = var.instance_source_details_boot_volume_vpus_per_gb
        instance_source_image_filter_details {
            #Required
            compartment_id = var.compartment_id

            #Optional
            defined_tags_filter = var.instance_source_details_instance_source_image_filter_details_defined_tags_filter
            operating_system = var.instance_source_details_instance_source_image_filter_details_operating_system
            operating_system_version = var.instance_source_details_instance_source_image_filter_details_operating_system_version
        }
        kms_key_id = oci_kms_key.test_key.id
    }
    preserve_boot_volume = false
}

Popular posts from this blog

Object Storage

  Object Storage in Oracle Cloud Infrastructure (OCI) is a cloud-based service that lets you store and access any kind of digital file—like photos, videos, documents, or backups—easily and securely. Instead of using folders like on your computer, it organizes everything in containers called “buckets,” where each file is an “object.” It’s designed to handle large amounts of data, so you don’t have to worry about running out of space, and your files are safely stored and always available when you need them. In OCI Object Storage, there are different storage tiers depending on how often you need to access your files: The Standard tier is for data you use regularly—it's fast and always ready.  The Archive tier is for files you don’t need very often, like old backups or logs; it’s much cheaper, but it takes a few hours to access the data when you need it.  You can move files between these tiers to save money using something called lifecycle policies —these are simple rules...

Purge Logging Analytics logs

 Is your tenant generating unexpected costs for Logging Analytics? Here is a possible solution. In the metrics you can see that as time progresses the storage used by Logging Analytics only increases. The explanation is that you are only generating logs, without deleting the old ones. Here is how you can create a Logging Analytics log purging policy: Navigate to Logging Analytics / Administration / Storage Here you can create a policy like this, which will purge the logs with more than 1 month old (for example): Also you can delete manually the Logging Analytics logs clicking the following button:

Infrastructure as Code

In some of the previous posts we have seen how to deploy some resources with Terraform. Terraform is an Infrastructure-as-Code (IaC) tool that allows to manage, version and maintain your infrastructure programmatically in OCI. But... What is Infrastructure as Code?   So, let's start with the concept of Infrastructure as Code (IaC). Infrastructure as Code, abbreviated as IaC, allows us to manage and provision infrastructure through code, rather than manual processes . This approach offers numerous advantages:   The first advantage is deployment automation . You won't need to manually prepare or manage operating systems, servers, storage, or any other components. Everything becomes automated.   Another benefit is the speed of implementation and deployment due to this automation.   It also reduces the risk of errors by utilizing templates for deployments and eliminating manual processes.   Lastly, using IaC ensures consistent environment crea...