Skip to content

AmpereComputing/terraform-oci-ampere-a1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ampere Computing

terraform-oci-ampere-a1

License

Description

Terraform module to launch Ampere A1 Shapes on Oracle Cloud Infrastructure (OCI) Free-Tier

Deploy to Oracle Cloud

Requirements

What exactly is Terraform doing

The goal of this code is to supply the minimal ammount of information to quickly have working Ampere A1 instances on OCI "Always Free". To keep things simple, The root compartment will be used (compartment id and tenancy id are the same) when launching the instance.

Addtional tasks performed by this code:

  • Dynamically creating sshkeys to use when logging into the instance.
  • Dynamically getting region, availability zone and image id..
  • Creating necessary core networking configurations for the tenancy
  • Rendering metadata to pass into the Ampere A1 instance.
  • Launch 1 to 4 Ampere A1 instances 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.
Please note that Compartment OCID are the same as Tenancy OCID for Root Compartment. The following is an example of what terraform.tfvars should look like:

tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaabcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopq"
user_ocid = "ocid1.user.oc1..aaaaaaaabcdefghijklmnopqrstuvwxyz0987654321zyxwvustqrponmlkj"
fingerprint = "a1:01:b2:02:c3:03:e4:04:10:11:12:13:14:15:16:17"
private_key_path = "/home/bwayne/.oci/oracleidentitycloudservice_bwayne-08-09-14-59.pem"

Using as a Module

This can also be used as a 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 Terraform

terraform init && terraform plan && terraform apply -auto-approve
<script id="asciicast-432487" src="https://asciinema.org/a/432487.js" async data-autoplay="true" data-size="small" data-speed="2"></script>

Running OpenTofu

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

Additional Terraform resources for OCI Ampere A1

Using as a Module

This can also be used as a 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.

Example AlmaLinux 8

# Example of Ampere A1 running AlmaLinux 8 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "almalinux8"
  instance_prefix          = "ampere-a1-almalinux-8"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example AlmaLinux 9

# Example of Ampere A1 running AlmaLinux 9 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "almalinux9"
  instance_prefix          = "ampere-a1-almalinux-9"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example FreeBSD 13.1

# Example of Ampere A1 running FreeBSD 13.1 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "freebsd"
  instance_prefix          = "ampere-a1-freebsd"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example OpenMandriva

# Example of Ampere A1 running OpenMandriva on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "openmandriva"
  instance_prefix          = "ampere-a1-openmandriva"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example OracleLinux 7.9

# Example of Ampere A1 running OracleLinux 7.9 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "oraclelinux79"
  instance_prefix          = "ampere-a1-oraclelinux-79"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example OracleLinux 8

# Example of Ampere A1 running OracleLinux 8 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "oraclelinux8"
  instance_prefix          = "ampere-a1-oraclelinux-8"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example Ubuntu 18.04

# Example of Ampere A1 running Ubuntu 18.04 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "ubuntu1804"
  instance_prefix          = "ampere-a1-ubuntu-1804"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example Ubuntu 20.04

# Example of Ampere A1 running Ubuntu 20.04 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "ubuntu2004"
  instance_prefix          = "ampere-a1-ubuntu-2004"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Example Ubuntu 22.04

# Example of Ampere A1 running Ubuntu 22.04 on OCI using this module
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
locals {
  cloud_init_template_path = "${path.cwd}/cloud-init.yaml.tpl"
}
module "oci-ampere-a1" {
  source                   = "github.com/amperecomputing/terraform-oci-ampere-a1"
  tenancy_ocid             = var.tenancy_ocid
  user_ocid                = var.user_ocid
  fingerprint              = var.fingerprint
  private_key_path         = var.private_key_path
# Optional
# oci_vcn_cidr_block       = "10.2.0.0/16"
# oci_vcn_cidr_subnet      = "10.2.1.0/24"
  oci_os_image             = "ubuntu2204"
  instance_prefix          = "ampere-a1-ubuntu-2204"
  oci_vm_count             = "1"
  ampere_a1_vm_memory      = "24"
  ampere_a1_cpu_core_count = "4"
  cloud_init_template_file = local.cloud_init_template_path
}
output "oci_ampere_a1_private_ips" {
  value     = module.oci-ampere-a1.ampere_a1_private_ips
}
output "oci_ampere_a1_public_ips" {
  value     = module.oci-ampere-a1.ampere_a1_public_ips
}

Inputs

Name Description Type Default Required
ampere_a1_cpu_core_count Default core count for Ampere A1 instances in OCI Free Tier string "4" no
ampere_a1_shape n/a string "VM.Standard.A1.Flex" no
ampere_a1_vm_memory Default RAM in GB for Ampere A1 instances in OCI Free Tier string "24" no
cloud_init_template_file Optional path for a cloud-init file string null no
fingerprint OCI Fingerprint ID for Free-Tier Account any n/a yes
instance_prefix Name prefix for vm instances string "ampere-a1-" no
oci_os_image Default OS Image From the Local Vars string "oraclelinux84" no
oci_vcn_cidr_block CIDR Address range for OCI Networks string "10.2.0.0/16" no
oci_vcn_cidr_subnet CIDR Address range for OCI Networks string "10.2.1.0/24" no
oci_vm_count OCI Free Tier Ampere A1 is two instances number 1 no
private_key_path Local path to the OCI private key file any n/a yes
tenancy_ocid OCI Tenancy ID for Free-Tier Account any n/a yes
user_ocid OCI User ID for Free-Tier Account any n/a yes

Outputs

Name Description
OCI_AlmaLinux_8_OS_Image_id Output OCI AlmaLinux 8 Image ID
OCI_AlmaLinux_9_OS_Image_id Output OCI AlmaLinux 9 Image ID
OCI_Availability_Domains Output Availability Domain Results
OCI_FreeBSD_OS_Image_id Output OCI FreeBSD Image ID
OCI_OpenMandriva_Linux_Image_id Output OCI OpenMandriva Image ID
OracleLinux-7_9-aarch64-latest-name Output OCI OracleLinux 7.9 Image Name
OracleLinux-7_9-aarch64-latest_ocid Output OCI OracleLinux 7.9 Image ID
OracleLinux-8-aarch64-latest-name Output OCI AlmaLinux 8 Image Name
OracleLinux-8-aarch64-latest_ocid Output OCI AlmaLinux 8 Image ID
OracleLinux-9-aarch64-latest-name Output OCI AlmaLinux 9 Image ID
OracleLinux-9-aarch64-latest_ocid Output OCI AlmaLinux 9 Image ID
Ubuntu-18_04-aarch64-latest_name Output OCI Ubuntu 18.04 Image Name
Ubuntu-18_04-aarch64-latest_ocid Output OCI Ubuntu 18.04 Image ID
Ubuntu-20_04-aarch64-latest_name Output OCI Ubuntu 20.04 Image Name
Ubuntu-20_04-aarch64-latest_ocid Output OCI Ubuntu 20.04 Image ID
Ubuntu-22_04-aarch64-latest_name Output OCI Ubuntu 22.04 Image Name
Ubuntu-22_04-aarch64-latest_ocid Output OCI Ubuntu 22.04 Image ID
ampere_a1_boot_volume_ids Output the boot volume IDs of the instance(s)
ampere_a1_private_ips Output the private IP(s) of the instance(s)
ampere_a1_public_ips Output the public IP(s) of the instance(s)
local_oci_aarch64_image_ids Output: List of available OCI image IDs
local_oci_aarch64_image_names Output: List of available OCI image names
local_oci_aarch64_images_map Output: the local map of the available oci image names and IDs
oci_aarch64_images_map Output: map of image names and image ids
oci_home_region Output: the home region of the tenancy
oci_ssh_private_key Output: The dynamically created openssh private key
oci_ssh_public_key Output: The dynamically created openssh public key
random_uuid Output: A randomly generated uuid

References