frennky / terraform-oci-free

Terraform configuration that creates the Always Free instance on Oracle Cloud Infrastructure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform-OCI-Free

This is a Terraform configuration that creates the Always Free instance on Oracle Cloud Infrastructure. By default, instance will have 4 Arm-based Ampere A1 cores, 24 GB of memory and 200 GB volume size.

In order to use Oracle Cloud Free Tier, you'll need to register free tier account. Once you have that set up, you can proceed with configuring auth.

Configure auth

Generate API key pair that will be used by provider.

mkdir ~/.oci
openssl genrsa -out ~/.oci/oci.pem 4096
openssl rsa -pubout -in ~/.oci/oci.pem -out ~/.oci/oci_public.pem

Go to Profile >> My profile >> API keys and Add API key. Paste public key and copy configuration preview file. Save configuration file as terraform.tfvars in repository root.

Optionally

Generate RSA key pair that will be used to SSH into instance.

For more details, check docs.

ssh-keygen -t rsa -b 4096 -C oci -f ~/.ssh/oci_free

Configure backend

Create bucket named tfstate and get namespace. Save home region and endpoint details in backend.conf file.

region   = "<home region>"
endpoint = "https://<namespace>.compat.objectstorage.<home region>.oraclecloud.com"

For more details, check docs.

Go to Profile >> My profile >> Customer secret keys and Generate secret key. Create Customer Secret key and save access key and secret key in credentials file.

[default]
aws_access_key_id=...
aws_secret_access_key=...

Create instance

terraform init -backend-config=backend.conf
terraform plan -var-file=terraform.tfvars
terraform apply -var-file=terraform.tfvars

Connect to instance

ssh -i ~/.ssh/oci ubuntu@public_ip

Requirements

Name Version
terraform >= 1.3.7
oci >= 4.104.0
tls 4.0.4

Providers

Name Version
local 2.3.0
oci 4.104.2
tls 4.0.4

Modules

No modules.

Resources

Name Type
local_file.instance_ssh_private_key resource
local_file.instance_ssh_public_key resource
oci_core_instance.free_instance resource
oci_core_internet_gateway.free_internet_gateway resource
oci_core_route_table.free_route_table resource
oci_core_security_list.free_security_list resource
oci_core_subnet.free_subnet resource
oci_core_vcn.free_vcn resource
oci_identity_compartment.free_compartment resource
tls_private_key.instance_ssh_private_key resource
oci_core_images.instance_images data source
oci_identity_availability_domains.ads data source

Inputs

Name Description Type Default Required
fingerprint The fingerprint for the user's RSA key. This can be found in user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. string n/a yes
image_operating_system The image's operating system. string "Canonical Ubuntu" no
image_operating_system_version The image's operating system version. string "22.04" no
instance_boot_volume_size The size of the boot volume in GBs. Minimum value is 50 GB and maximum value is 32,768 GB (32 TB). number 200 no
instance_hostname A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information. string "free" no
instance_memory The total amount of memory available to the instance, in gigabytes. number 24 no
instance_ocpus The total number of OCPUs available to the instance. number 4 no
instance_public_key_path Public SSH key to be included in the ~/.ssh/authorized_keys file for the default user on the instance. string "" no
instance_shape The shape of an instance. The shape determines the number of CPUs, amount of memory, and other resources allocated to the instance. string "VM.Standard.A1.Flex" no
private_key_path The path to the user's PEM formatted private key. A private_key or a private_key_path must be provided if auth is set to 'ApiKey', ignored otherwise. string n/a yes
region The region for API connections (e.g. us-ashburn-1). string n/a yes
tenancy_ocid The tenancy OCID for a user. The tenancy OCID can be found at the bottom of user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. string n/a yes
user_ocid The user OCID. This can be found in user settings in the Oracle Cloud Infrastructure console. Required if auth is set to 'ApiKey', ignored otherwise. string n/a yes

Outputs

Name Description
compartment-id The OCID of the compartment.
compartment-name The name you assign to the compartment during creation. The name must be unique across all compartments in the parent.
instance-name A user-friendly name. Does not have to be unique, and it's changeable.
instance-public-ip The public IP address of instance VNIC (if enabled).
instance-region The region that contains the availability domain the instance is running in.
instance-shape The shape of the instance. The shape determines the number of CPUs and the amount of memory allocated to the instance.
instance-state The current state of the instance.

About

Terraform configuration that creates the Always Free instance on Oracle Cloud Infrastructure

License:MIT License


Languages

Language:HCL 100.0%