Deploying AWS Resources Using Terraform (Ubuntu Linux Edition)

Deploying AWS Resources Using Terraform (Ubuntu Linux Edition)

Hey guys... I'd like to show you how to deploy resources on the Amazon Web Services platform using terraform. If you'd like to see how, then please keep reading...

Kindly note that you would require an AWS account for this tutorial. So, if you haven't opened an account yet, please do so. You would also need to download a good VMware workstation, and Ubuntu image file in order to run your virtual machine, as I would be using the Ubuntu VM for this tutorial. After downloading a VMware of your choosing, open the application and click on create a new virtual machine.

UB 1.PNG

Follow the prompt until the machine is downloaded and powered on (on the VMware).

UB 2.PNG

UB 3.PNG

UB 4.PNG

UB 5.PNG

UB 6.PNG

Upon successfully installing the VM, you should see this:

UB 7.PNG

Login to the computer, as you would your traditional machine after powering up

UB 8.PNG

Open the terminal. For this, you can either press Ctrl+Alt+T or search for the terminal in applications.

Once your terminal is open, take control by typing in the sudo su command, this makes you a super user and gives you absolute permission on the system (an alternative to this is typing "sudo" in front of every command, before execution). You would be prompted for your password, which you should type in. Do not worry if your password does not display as you type, I am told it is a security feature in Linux systems, to minimize password leakage.

Next, type in the following command: wget releases.hashicorp.com/terraform/1.1.3/terr.. This should download terraform onto your system.

LN 1.PNG

Now type apt-get install zip -y this is so that terraform which has already been downloaded can be installed.

LN 2.PNG

Now, you'll unzip terraform, using the following command: unzip terraform.zip*

The next command is mv terraform /usr/local/bin This is done in order to move terraform from the downloads directory into the usr/bin directory so that terraform can be easily accessed.

Next, create directory with mkdir /terraform and change it using cd /terraform

LN 3.PNG

Then install the text editor using the command apt install vim

LN 4.PNG

Using the vim config.tf command, open the text editor, and press i to edit or insert text.

Copy the following text inside:

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.27" } }

required_version = ">= 0.14.9" }

provider "aws" { profile = "default" region = "us-west-2" }

resource "aws_instance" "app_server" { ami = "ami-830c94e3" instance_type = "t2.micro"

tags = { Name = "ExampleAppServerInstance" } }

and use esc shift:wq enter to save and close the file. (Please indent it as it is in the photo below) LN 12.PNG

Next install aws using snap install aws-cli --classic and configure it using the aws configure command. If done, you should see this:

LN 9.PNG

To configure AWS, you need to go to your actual AWS account, click on your name/profile and on the drop down, click security credentials. There, you'll download your access keys and secret keys. Be sure to keep the secret key safe, otherwise, once you lose it, it's lost forever and you would need to download fresh keys. The system will ask you for the access and secret keys, as well as your default region name and default output format (for default format, type in JSON) so please take note of those.

You can now initialize using the terraform init command

LN 8.PNG

Followed by terraform plan

LN 10.PNG

Finally, apply using the terraform apply command

LN 11.PNG

Voila! Following these steps, you have successfully deployed resources on aws using terraform. You may now proceed to the portal to check out your deployed resources.