I haven’t written a blog in a while, and I have made a couple of mistakes lately that could have easily been avoided if I had done my tasks as IaC (Infrastructure as Code). So I will start a series of IaC and Terraform. I know many blogs about this, but I hope you find this helpful.
I will start with an Oracle Linux 8 VM that I created in OCI to work with. I won’t go into how I set that up, but I am using the always-free version.
[root@oracle-rene-cloud-ace ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.9 (Ootpa)
I installed the following in the VM
[root@oracle-rene-cloud-ace ~]# yum update
Last metadata expiration check: 0:05:35 ago on Tue 13 Feb 2024 01:55:37 PM GMT.
...
[root@oracle-rene-cloud-ace ~]# yum install yum-utils -y
Last metadata expiration check: 2:51:59 ago on Tue 13 Feb 2024 02:01:55 PM GMT.
...
[root@oracle-rene-cloud-ace ~]# yum install terraform -y
Last metadata expiration check: 1:08:28 ago on Tue 13 Feb 2024 03:55:37 PM GMT.
...
[root@oracle-rene-cloud-ace ~]# dnf install -y oracle-database-preinstall-19c
Last metadata expiration check: 0:11:39 ago on Tue 13 Feb 2024 05:51:03 PM GMT
...
[root@oracle-rene-cloud-ace ~]$ dnf install -y python36-oci-cli
Last metadata expiration check: 2:48:55 ago on Tue 13 Feb 2024 06:51:03 PM GMT.
...
Once I did this, I set up OCI CLI and my config file as per this blog post. After I configured everything, I tested my environment was working and queried the region and availability domain, as I needed that information for my terraform variables.
[opc@oracle-rene-cloud-ace ~]$ oci setup repair-file-permissions --file /home/opc/.oci/config
[opc@oracle-rene-cloud-ace ~]$ oci iam region list --output table
+-----+-------------------+
| key | name |
+-----+-------------------+
| AMS | eu-amsterdam-1 |
| ARN | eu-stockholm-1 |
| AUH | me-abudhabi-1 |
| BOG | sa-bogota-1 |
| BOM | ap-mumbai-1 |
...
| YYZ | ca-toronto-1 |
| ZRH | eu-zurich-1 |
+-----+-------------------+
[opc@oracle-rene-cloud-ace ~]$ oci iam availability-domain list --query "data[*].{Name:\"name\"}" --output table
+------------------------+
| Name |
+------------------------+
| LVfX:CA-TORONTO-1-AD-1 |
+------------------------+
What it is
How does it work?
Resources
Working with variables
Basic CLI Usage
tfstate
We went over the basics of Terraform and how to initialize our environment so that we can start to work with Terraform and OCI. In the next blog posts, I will go into how to do basic IaC for an IAM Policy and a compartment, and we will grow it from there.