In this article we will see how to create custom image in oracle cloud using packer..
1. Fetch all required parameters from oci
region code:
availability_domain :
tenancy_ocid :
user_ocid :
base_image_ocid :
compartment_ocid :
shape :
subnet_ocid :
fingerprint :
key_file :
a. region code:
Give the region code from where you wanted to create the custom image
Here I want to create custom image in the phoenix region , so my region code is us-phoenix-1
b. availability_domain : AD nothing but a DataCenter.
while creating the instance u will get the ad name : EAbO:PHX-AD-1
c. Get the tenancy & user ocid :
you need to create public and private key for instance:
open your linux terminal or gitbash in windows then enter these commands:
$ openssl genrsa -out key.pem 2048
$ openssl rsa -in key.pem -outform PEM -pubout -out public.pem
d. copy that fingetprint
e. Get the Base image ocid Click Here to get the Image OCID List
Here I would like to create oracle linux 7 so I need to click on Oracle Linux 7 then click on ReadMore.. There you will get the image code for specific region, copy that image ocid
f. create vcn in that region and also create subnet , copy that subnet ocid
open the required ports
g. key_file is the location of the private key file path
Install the packer : Click Here
Then add the path into environment path
create a file oci_image.json and copy the below text , replace with your ocids
{"builders": [{"type": "oracle-oci","region": "us-phoenix-1","availability_domain": "EAbO:PHX-AD-1","tenancy_ocid" : "ocid1.tenancy.oc1..aaaaaaayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy","base_image_ocid": "ocid1.image.oc1.phx.aaaaaaaaiqmtu5jaqezxl6jz6ozopb4l3vfl7dt3hmf4o6yseuvw3rzeabxa","compartment_ocid": "ocid1.compartment.oc1..aazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz","image_name": "MyOCILinux-PackerPractice","shape": "VM.Standard2.1","ssh_username": "opc","subnet_ocid": "ocid1.subnet.oc1.phx.aaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","user_ocid" : "ocid1.user.oc1..aaacccccccccccccccccccccccccccccccccccccccccccccccc","fingerprint": "90:c2:89:8a:56:a2:54:12:58:d4:e3:a2:e4","key_file" : "C:\\Users\\urname\\Documents\\Practice\\packer\\oracle-cloud\\key.pem"}],"provisioners": [{"type": "shell","inline": ["sudo su","sudo yum update -y","sudo yum install docker -y","sudo yum install git -y","sudo yum install httpd -y"]}]}
packer build oci_image.json
Check your oci console
Thats it, You have successfully created Custom Image Using Packer in Oracle Cloud..
Thanks for reading,
Tharun.K
For more tech tutorials/videos subscribe to my youtube channel click here to subscribe
0 Comments