Using ChatGPT to assist multi-cloud scenarios

I have generated Terraform codes for the same Ubuntu VM with OpenAI’s Chat GPT-4 and compared the VM prices per region in a fancy table. HCL code results are quite accurate, however, I would not trust price comparison due to outdated information. You can get adjustable results in minutes saving lots of human research time.

ChatGPT use cases to support working with multi-cloud environments

In this article, I tried only scenarios #2 (generate Terraform codes) and #7 (price comparison) from the list below:

I remember I got an interview question some time ago – the answer is obviously no

The response from GPT-4 is very nice and gives you an idea of how a software architect should structure the folders in case of multi-cloud deployments:

Cross-platform orchestration: generate Terraform code for multi-cloud deployments

My goal was the simplest possible, let’s have a simple Ubuntu VM in Clouds.

We got this code for AzureRM, “Standard_D2_v4” # 2 vCPU, 8 GB RAM is pretty nice and source_image_reference is quite accurate.

provider "azurerm" {
  features {}
}
resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West US 2"
}
resource "azurerm_virtual_network" "example" {
  name                = "example-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
}
resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}
resource "azurerm_linux_virtual_machine" "example" {
  name                            = "example-vm"
  resource_group_name             = azurerm_resource_group.example.name
  location                        = azurerm_resource_group.example.location
  size                            = "Standard_D2_v4" # 2 vCPU, 8 GB RAM
  admin_username                  = "ubuntu"
  network_interface_ids           = [azurerm_network_interface.example.id]
  disable_password_authentication = true
  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }
  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "18.04-LTS"
    version   = "latest"
  }
  admin_ssh_key {
    username   = "ubuntu"
    public_key = file("~/.ssh/id_rsa.pub")
  }
}

GCP’s main.tf is equally good. We got the same image as Azure. “ubuntu-os-cloud/ubuntu-1804-lts”

I think “n1-standard-2” # 2 vCPU, 7.5 GB RAM is a good attempt, we do not need a GCP custom VM type to meet the 8GB RAM requirement precisely.

provider "google" {
  project = "<YOUR_PROJECT_ID>"
  region  = "us-central1"
  zone    = "us-central1-a"
}
resource "google_compute_instance" "example" {
  name         = "example-vm"
  machine_type = "n1-standard-2" # 2 vCPU, 7.5 GB RAM
  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-1804-lts"
    }
  }
  network_interface {
    network = "default"
    access_config {
      // Ephemeral IP
    }
  }
  service_account {
    scopes = ["userinfo-email", "compute-ro", "storage-ro"]
  }
}

The AWS code (first attempt) is surprisingly short compared to public HCL examples.

aws_instance | Resources | hashicorp/aws | Terraform Registry

I missed the example of using AMI lookup and network and credit specifications, but still, not bad. “t2.large” # 2 vCPU, 8 GB is what I asked for.

provider "aws" {
  region = "us-west-2"
}
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0" # Ubuntu 18.04 LTS - us-west-2
  instance_type = "t2.large" # 2 vCPU, 8 GB

Let’s ask for a correction adding what I missed

provider "aws" {
  region = "us-west-2"
}
data "aws_vpc" "default" {
  default = true
}
data "aws_subnet" "default" {
  availability_zone = "us-west-2a"
  default_for_az    = true
}
data "aws_security_group" "default" {
  name = "default"
  vpc_id = data.aws_vpc.default.id
}
data "aws_ami" "ubuntu" {
  most_recent = true
  owners      = ["099720109477"] # Canonical
  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
  }
  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }
}
resource "aws_instance" "example" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t2.large" # 2 vCPU, 8 GB RAM
  key_name          = "your_key_pair_name"
  vpc_security_group_ids = [data.aws_security_group.default.id]
  subnet_id         = data.aws_subnet.default.id
  tags = {
    Name = "example-vm"
  }
}

Wohoo, I have the AMI lookup now and this is using the same as other clouds.

“ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*”

Regarding Oracle Cloud, we got nothing because the provider is officially called Oracle Cloud Infrastructure. Fair enough.

This is what ChatGCP generated

provider "oci" {
  tenancy_ocid     = "<TENANCY_OCID>"
  user_ocid        = "<USER_OCID>"
  fingerprint      = "<FINGERPRINT>"
  private_key_path = "<PRIVATE_KEY_PATH>"
  region           = "us-ashburn-1"
}
data "oci_identity_availability_domains" "ads" {
  compartment_id = "<COMPARTMENT_OCID>"
}
resource "oci_core_virtual_network" "example" {
  cidr_block     = "10.0.0.0/16"
  compartment_id = "<COMPARTMENT_OCID>"
  display_name   = "example-vcn"
  dns_label      = "examplevcn"
}
resource "oci_core_subnet" "example" {
  availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
  cidr_block          = "10.0.1.0/24"
  compartment_id      = "<COMPARTMENT_OCID>"
  display_name        = "example-subnet"
  dns_label           = "examplesubnet"
  security_list_ids    = [oci_core_security_list.example.id]
  vcn_id              = oci_core_virtual_network.example.id
}
resource "oci_core_security_list" "example" {
  compartment_id = "<COMPARTMENT_OCID>"
  display_name   = "example-security-list"
  vcn_id         = oci_core_virtual_network.example.id
  ingress_security_rules {
    protocol = "6" # TCP
    source   = "0.0.0.0/0"
    tcp_options {
      min = 22
      max = 22
    }
  }
}
data "oci_core_images" "ubuntu" {
  compartment_id = "<COMPARTMENT_OCID>"
  operating_system = "Ubuntu"
  operating_system_version = "18.04"
  shape = "VM.Standard2.2" # 2 vCPU, 15 GB RAM
  sort_by = "TIMECREATED"
  sort_order = "DESC"
}
resource "oci_core_instance" "example" {
  availability_domain = data.oci_identity_availability_domains.ads.availability_domains[0].name
  compartment_id      = "<COMPARTMENT_OCID>"
  display_name        = "example-vm"
  shape               = "VM.Standard2.2" # 2 vCPU, 15 GB RAM
  agent_config {
    is_monitoring_disabled = false
  }
  create_vnic_details {
    subnet_id        = oci_core_subnet.example.id
    display_name     = "example-vnic"
    assign_public_ip = true
  }
  source_details {
    source_type = "image"
    source_id   = data.oci_core_images.ubuntu.images[0].id
  }
  metadata = {
    ssh_authorized_keys = "<YOUR_PUBLIC_SSH_KEY>"
  }
}

Haha, there is the exact match for sure. OCI presales people keep talking about funky VM configurations using Flexible Shapes: a flexible shape is a shape that lets you customize the number of OCPUs and the amount of memory when launching or resizing your VM. The image is good and has the same OS version.

Price comparison in a fancy table

Asking for price comparison from AI can result in quite outdated pricing information, however, it’s quite fun to see how small the difference is in EUR for the same VM (probably this is similar today).

Obviously, you are not using the public cloud for VM hosting only, so this example is disconnected from real-world pricing exercises.

And it is amazing to see easy to ask for additional things

As a conclusion, I am impressed with GPT-4 capabilities to support working in a multi-cloud environment. I used to work on a DevOps project recently and I have written the HCL code by myself following the design patterns our agile team agreed on, however, I can imagine that lots of cloud software engineers (developers) will use AI to support their work (save time).

Related posts

Comparison of VMware relocation options in public cloud

I keep researching this topic from several perspectives: regional availability, provided architecture, most popular use cases, VMware software versions, provided hardware configuration, and finally the price of a 3-node vSphere cluster in the Cloud.

AWS MiGratioN, GCP Migrate4Cloud, and Azure Migrate pros and cons

It’s been more than 5 years since I am testing and comparing 1st party migration tools. I have seen these tools getting better over the years, with major improvements by acquisitions, end-of-life products, continuous changes, and improvements not just the tools but the methodology around, well-architected, CaF, the concept of the landing zone, 5Rs become 7Rs. In this article, I am sharing my experiences with the most commonly used cloud migration tools.

Oracle Database service for Azure – connecting Azure VM and Power App

I have connected a Database Admin Azure VM running Oracle’s SQL Developer (Windows version) and a Microsoft Power Platform application displaying Oracle’s HR demo schema (via on-premises data gateway on Azure VM connecting with Power Platform’s Oracle Premium Connector) to the same Oracle Database hosted on OCI.

Oracle Database service for Azure – linking subscriptions

As part of my multi-cloud research, I wanted to test Oracle Database Service for Azure. In this article, you will see how to sign up for the new service and how to link Oracle and Azure accounts. I used Frankfurt datacenters, Azure MSDN, and OCI paid account (Free Tier does not work) using my private Azure Active Directory.

Why multi-cloud is the way to go? VMware and Oracle perspective.

While cloud migration is still a popular topic during customer discussions, I have noticed that more and more customers are considering an exit plan from one cloud (vendor lock-in) to another cloud meaning there is an increase in multi-cloud migration demand. VMware, Oracle, and SAP are the major workloads in on-premises data centers today. Based on my research both VMware and Oracle are very vocal about the importance of having a multi-cloud strategy.

AWS Site-to-Site VPN using MikroTik RouterOS

There are two ways of approaching this challenge. (#1) running MikroTik virtual appliance (CHR) in AWS (#2) using Virtual Private Gateway, a “cloud-native” networking solution provided by AWS. Each solution has its own benefits.