Skip to content

AmpereComputing/terraform-azure-ampere-vm

Repository files navigation

Ampere Computing

terraform-azure-ampere-vm

Source Code documentation workflow pages-build-deployment Latest version GitHub issues Github stars Github last-commit GitHub forks Github forks GitHub License License GitHub deployments Website

Description

OpenTofu/Terraform code to launch a Ampere virtual machines on Microsoft Azure.

Requirements

What exactly is OpenTofu/Terraform doing

The goal of this code is to supply the minimal ammount of information to quickly have working Ampere virtual machines on "Azure". Virtual machines are configured with a simple cloud-config using the Azure metadata provider APIs.

Addtional tasks performed by this code:

  • Dynamically creating sshkeys to use when logging into the instance.
  • Creating necessary core networking configurations for the tenancy
  • Rendering metadata to pass into the Ampere virtual machine
  • Launch Ampere virtual machine with metadata and ssh keys.
  • Output IP information to connect to the instance.

To get started clone this repository from GitHub locally.

Configuration with terraform.tfvars

The easiest way to configure is to use a terraform.tfvars in the project directory.
The following is an example of what terraform.tfvars should look like:

subscription_id = "12345678-abcd-1234-abcd-1234567890ab"
tenant_id = "87654321-dcba-4321-dcba-ba0987654321"

Using as a Module

This can also be used as a OpenTofu or Terraform module. The examples directory contains example code for module usage showing different operating systems booting with a custom cloud-init templates. Doing a clone of this repository and changing directory to one of the examples, placing a terraform.tfvars into that directory, and running a typical terrafornm workflow will produce a working virtual machine in the os that was specified in the main.tf that is located within the chosen example directory.

Running using OpenTofu

tofu init && tofu plan && tofu apply -auto-approve

Running using Terraform

terraform init && terraform plan && terraform apply -auto-approve

Examples

AlmaLinux 8

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "almalinux8"
        instance_prefix          = "azure-ampere-vm-almalinux8"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

Debian 11

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "debian11"
        instance_prefix          = "azure-ampere-vm-debian-11"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

CBL Mariner

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "mariner"
        instance_prefix          = "azure-ampere-vm-mariner"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

OpenSuse

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "opensuse"
        instance_prefix          = "azure-ampere-vm-opensuse-15"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

Example Ubuntu 18.04

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "ubuntu1804"
        instance_prefix          = "azure-ampere-vm-ubuntu-1804"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

Example Ubuntu 20.04

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "ubuntu2004"
        instance_prefix          = "azure-ampere-vm-ubuntu-2004"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

Example Ubuntu 22.04

variable "subscription_id" {}
variable "tenant_id" {}

locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}

module "azure-ampere-vm" {
        source                   = "github.com/amperecomputing/terraform-azure-ampere-vm"  
        subscription_id          = var.subscription_id
        tenant_id                = var.tenant_id
     #  Optional
     #  resource_group           = var.resource_group
     #  rg_prefix                = var.rg_prefix
     #  virtual_network_name     = var.virtual_network_name
     #  address_space            = var.address_space
     #  subnet_prefix            = var.subnet_prefix
     #  vm_size                  = var.vm_size
        location                 = "westus2"
        azure_vm_count           = 1
        azure_os_image           = "ubuntu2204"
        instance_prefix          = "azure-ampere-vm-ubuntu-2204"
        cloud_init_template_file = local.cloud_init_template_path
}

output "azure_ampere_vm_private_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_private_ipaddresses
}
output "azure_ampere_vm_public_ips" {
  value     = module.azure-ampere-vm.azure_ampere_vm_public_ipaddresses
}

Inputs

Name Description Type Default Required
address_space The address space that is used by the virtual network. You can supply more than one address space. Changing this forces a new resource to be created. string "10.2.0.0/16" no
azure_os_image Default OS Image From the Local Vars string "ubuntu2004" no
azure_vm_count Azure Ampere Virtual machine Config number 1 no
cloud_init_template_file Optional path for a cloud-init file string null no
instance_prefix Name prefix for vm instances string "azure-ampere-vm" no
location The location/region where the virtual network is created. Changing this forces a new resource to be created. string "westus2" no
resource_group The name of the resource group in which to create the virtual network. string "Terraform-Ampere-on-Azure" no
rg_prefix The shortened abbreviation to represent your resource group that will go on the front of some resources. string "rg" no
subnet_prefix The address prefix to use for the subnet. string "10.2.1.0/24" no
subscription_id Azure Credentials string "Azure Subscription ID" no
tags n/a map
{
"environment": "Public Cloud"
}
no
tenant_id n/a string "Azure Tenant ID" no
virtual_network_name The name for the virtual network. string "vnet" no
vm_size Specifies the size of the Azure Ampere virtual machine. string "Standard_D16ps_v5" no

Modules

No modules.

Outputs

Name Description
azure_ampere_vm_private_ipaddresses Output the Azure VM(s)) private/internal ip address
azure_ampere_vm_public_ipaddresses Output the Azure VM(s)) public/external ip address
azure_ampere_vm_ssh_private_key Output the Azure SSH private key
azure_ampere_vm_ssh_public_key Output the Azure SSH public key
azure_current_subscription_display_name Output the Display Name for the current Azure Subscription
azure_ssh_private_key output the Azure SSH private key
azure_ssh_pubic_key output the Azure SSH public key
random_uuid Output: A randomly generated uuid

Providers

Name Version
azurerm n/a
local n/a
random n/a
tls n/a

Resources

Name Type
azurerm_network_interface.nic resource
azurerm_network_security_group.nsg resource
azurerm_public_ip.pip resource
azurerm_resource_group.rg resource
azurerm_subnet.subnet resource
azurerm_virtual_machine.vm resource
azurerm_virtual_network.vnet resource
local_file.azure-ssh-privkey resource
local_file.azure-ssh-pubkey resource
random_uuid.random_id resource
tls_private_key.azure resource
azurerm_public_ip.pip data source
azurerm_subscription.current data source

Requirements

No requirements.

References

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •