Added example and KB to create a free ampere instance in Oracle Cloud

This commit is contained in:
Michele Cereda
2023-01-08 19:14:35 +01:00
parent ad3ceedd17
commit 5e6de46733
10 changed files with 264 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
# Oracle free tier Ampere VM
Simple example to create an Ampere VM instance in Oracle Cloud's free tier.
1. [Requirements](#requirements)
2. [Further readings](#further-readings)
3. [Sources](#sources)
## Requirements
1. VCN
1. Public Subnet
For a Subnet to be considered Public, it needs to have associated a Route Table with a default route pointing to an Internet Gateway.
The default route table created using Terraform does not contain this route, nor it is possible to create the single route in it at the time of writing.<br />
A solution to this is to create a new Route Table **with** the default route above and attach it to the Subnet. See the code for details.
![requirements]
## Further readings
## Sources
- [Ridiculously powerful free server in the cloud]
- [Always free resources] in Oracle Cloud
- [Oracle Cloud Infrastructure Provider documentation]
- [oracle-terraform-modules/terraform-oci-compute-instance]
<!-- internal references -->
[requirements]: design/requirements.png
<!-- external references -->
[always free resources]: https://docs.oracle.com/en-us/iaas/Content/FreeTier/freetier_topic-Always_Free_Resources.htm
[oracle cloud infrastructure provider documentation]: https://registry.terraform.io/providers/oracle/oci/latest/docs
[ridiculously powerful free server in the cloud]: https://medium.com/codex/ridiculously-powerful-free-server-in-the-cloud-dd4da8524a9c
[oracle-terraform-modules/terraform-oci-compute-instance]: https://github.com/oracle-terraform-modules/terraform-oci-compute-instance

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python3
from diagrams import Cluster, Diagram
from diagrams.oci.compute import VM
from diagrams.oci.network import InternetGateway, RouteTable, Vcn
with Diagram("Requirements", show=False):
vcn = Vcn("VCN")
vm = VM("Ampere instance")
with Cluster("Public Subnet"):
ig = InternetGateway("Internet Gateway")
rt = RouteTable("Route Table")
vcn >> ig >> rt
rt >> vm

View File

@@ -0,0 +1,14 @@
availability_domain = "FIXME" # get it with `oci iam availability-domain list`
compartment_id = "FIXME" # get it with `oci iam compartment list`
memory_in_gbs = 24
ocpus = 4
# get it with `oci compute image list -c 'tenancy_id'`
# or check https://docs.oracle.com/en-us/iaas/images/
source_id = "ocid1.image.oc1.eu-amsterdam-1.aaaaaaaavmra3s4va4fqd4vlcrqc5v5jyqov5vdla3x3b6gzc64n6dkpuqua"
ssh_authorized_keys = <<EOT
ssh-ed25519 key-1 comment
ssh-ed25519 key-n comment
EOT

View File

@@ -0,0 +1,61 @@
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_vcn
resource "oci_core_vcn" "this" {
compartment_id = var.compartment_id
cidr_blocks = ["10.0.0.0/16"]
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_subnet
resource "oci_core_subnet" "this" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
cidr_block = "10.0.0.0/24"
}
# Needed to be able to connect to the instance from the Internet.
# Need to create a route table with the default route 0.0.0.0/0 pointing to the
# internet gateway, and associate the subnet to it.
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_internet_gateway
resource "oci_core_internet_gateway" "this" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
}
resource "oci_core_route_table" "this" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.this.id
route_rules {
destination = "0.0.0.0/0"
destination_type = "CIDR_BLOCK"
network_entity_id = oci_core_internet_gateway.this.id
}
}
resource "oci_core_route_table_attachment" "this" {
subnet_id = oci_core_subnet.this.id
route_table_id = oci_core_route_table.this.id
}
# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_instance
resource "oci_core_instance" "this" {
compartment_id = var.compartment_id
availability_domain = var.availability_domain
shape = var.shape
create_vnic_details {
subnet_id = oci_core_subnet.this.id
}
metadata = {
ssh_authorized_keys = var.ssh_authorized_keys
}
shape_config {
memory_in_gbs = var.memory_in_gbs
ocpus = var.ocpus
}
source_details {
boot_volume_size_in_gbs = var.boot_volume_size_in_gbs
source_id = var.source_id
source_type = var.source_type
}
}

View File

@@ -0,0 +1,3 @@
output "instance" {
value = oci_core_instance.this
}

View File

@@ -0,0 +1,35 @@
variable "availability_domain" {
type = string
}
variable "compartment_id" {
type = string
}
variable "shape" {
type = string
default = "VM.Standard.A1.Flex"
}
variable "memory_in_gbs" {
type = number
default = 24
}
variable "ocpus" {
type = number
default = 4
}
variable "boot_volume_size_in_gbs" {
type = number
default = 50
}
variable "source_id" {
type = string
}
variable "source_type" {
type = string
default = "image"
}
variable "ssh_authorized_keys" {
type = string
}