Skip to content

Provision an instance Always Free on Oracle OCI with Terraform.

Notifications You must be signed in to change notification settings

ciro-mota/Terraform-OCI

Repository files navigation

Terraform-OCI

License Oracle Terraform Ansible Red Hat Ubuntu Shell Script Last Commit

Provision an instance on Oracle OCI with Always Free features and standard machine type. You will be able to choose between Ubuntu 20.04 or 22.04 or Oracle Linux images.

📋 Requirements:

📌 Before executing:

  1. It is necessary to get some credentials to fill in the some variables values for Terraform execution. These values are taken directly from the OCI Cloud Console:
  • tenancy_ocid:

Login into your OCI Cloud Console account and then go to this address. In OCID click on Copy or Show, copy and paste into a notepad.

  • user_ocid:

Main Menu » Identity & Security » Users » oracleidentitycloudservice/<<your-email>>. In OCID click on Copy or Show, copy and paste into a notepad.

  • Run the commands below to generate a key pair required for authentication:
mkdir ~/.oci
openssl genrsa -out ~/.oci/oci_api_key.pem 2048
chmod go-rwx ~/.oci/oci_api_key.pem
openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem
  • fingerprint:

Capture the public_key generated in the previous step (cat ~/.oci/oci_api_key_public.pem) » access Main Menu » Identity & Security » Users » oracleidentitycloudservice/<<your-email>> » API Keys » Add API Key » Paste Public Key and paste the public key content.

This will generate your fingerprint, copy and paste it into a notepad.

  • SSH:

A key pair may be required for SSH access to the instance. If not, generate a new pair with the command ssh-keygen -b 2048 -t rsa.

  • Remote State

You might want to store your states remotely in an OCI bucket. For this Main Menu » Storage » Object Storage & Archive Storage » create a uniquely named Bucket » Create Pre-Authenticated Request » Permit object reads and writes, and copy the given URL.

In the main.tf file, uncomment lines 9 to 12 and insert the given URL in the address field. This is a purely optional step.

  1. Add some variables to your .bashrc or .zshrc file by filling them in with the values obtained earlier:
export TF_VAR_tenancy_ocid=<your credencials>
export TF_VAR_user_ocid=<your credencials>
export TF_VAR_fingerprint=<your credencials>
export TF_VAR_private_key_path=~/.oci/oci_api_key.pem
export TF_VAR_public_key_path=$(cat /home/your-username/.ssh/id_rsa.pub)

💻 Usage

  1. Clone this repo.
  2. By default an instance with Ubuntu 22.04 with AMD hardware will be provisioned, if you want another OS modify the variables.tf file and instance.tf file on lines 24 to 26, if you wish.
  3. If you want to use ARM instances, use the instance-arm.tf file instead of the instance.tf file.
  4. Run terraform init, terraform plan -out= name-of-the-plan and terraform apply. At the end, terraform destroy for deletion of what was created in the OCI.

🔧 Post Install Scripts

You can also apply post-installation scripts to your instance through. This project counts as example scripts for nginx provisioning provided by Ansible Galaxy.

To work with these settings, uncomment line 31 in the instance.tf file.

🎁 Sponsoring

If you like this work, give me it a star on GitHub, and consider supporting it buying me a coffee:

PayPal

About

Provision an instance Always Free on Oracle OCI with Terraform.

Topics

Resources

Stars

Watchers

Forks