SpaceRocketIaC uses Cloud9 IDE, Terraform, and Ansible for Infrastructure as Code (IaC). This makes it easy to set up and maintain AWS infrastructure. Our goal is to make the code ready to be integrated into your CI/CD pipeline.
The easiest way to get started using IaC with AWS services is by using AWS's Cloud9 IDE.
This tutorial assumes familiarity with Terraform, Packer, Ansible and AWS.
Getting Started with Cloud9 IDE
Cloud9 is a browser-based code editor that is hosted on an EC2 instance. AWS Cloud9 can serve as a 'bastion host' by providing a fortified gateway to AWS services. It provides a fortified gateway to AWS services through the use of AWS best practices such as credential rotation and session keys, as well as the ability to limit access by IP addresses. AWS Cloud9 also simplifies IaC management by providing pre-authentication to AWS services, which allows for easy modification and deployment using tools like Terraform, Packer, and Ansible.
In this tutorial, we will be setting up Cloud9 IDE, associating an Elastic IP address, and installing Terraform, Packer, and Ansible. This tutorial assumes you are already logged into the AWS console with a non-root user with administrative access. If not, follow these instructions: Getting set up with IAM.
Without further ado, let's get started!
Search for Cloud9 in the AWS search bar, then create a new environment by clicking the "Create environment" button.
Give your environment a name and select the environment type.
Select the desired instance type (for demonstration purposes,
t2.micro
should be sufficient. If you need more resources, choose a larger instance type), Ubuntu Server 18.04 LTS as your platform, and lastly, choose how long you want your Cloud9 IDE to be active. This is useful because you will not be charged for the time when the Cloud9 IDE is not in use.Select Secure Shell (SSH) for the connection method for your environment. You can leave the VPC and Subnet as their default values.
Lastly, click the "Create" button to create the environment.
Once the environment is ready, click Open in the Cloud9 IDE column. You will then be taken to the Cloud9 IDE web-based code editor.
From the terminal, you can run commands and interact with the environment just as you would on a local terminal.
Now that we have created the Cloud9 instance and environment, we are ready to create an Elastic IP and associate it with the Cloud9 instance. After that, we will install Terraform, Packer, and Ansible.
Set Cloud9 Elastic IP
We need to add an Elastic IP to the Cloud9 instance to maintain consistent access, even after restarts and the IP address of the EC2 instance changes. Let's do that by creating an Elastic IP and associating it with the Cloud9 instance.
Go to the EC2 service in the search bar and navigate to Elastic IPs via the left navigation menu.
Click "Allocate Elastic IP address". On the next screen stick with Amazon's default pool of IPv4 addresses, give it a Name tag of Cloud9 EIP, and then click "Allocate".
On the next screen, select the Cloud9 EIP address and click the "Actions" drop-down button. Click "Associate Elastic IP" (or click the button that says "Associate this Elastic IP address" in the big green banner).
Select Instance as the resource type and the MyCloud9IDE
instance from the drop-down selector, then click "Associate".
Now we have a static IP address that won't change after the Cloud9 instance shuts down from inactivity and restarts later with a different IP address; it will use the Elastic IP address instead.
Getting your Elastic IP
To obtain your Elastic IP, navigate to the EC2 service in the AWS console. In the left sidebar, go to Network & Security > Elastic IPs. Select your Cloud9 EIP and under the 'Summary' tab, copy the "Allocated IPv4 address". When using it in CIDR notation, it will be in the format <IP.AD.DR.ESS>/32
.
Install Terraform, Packer, and Ansible
Before you can use the Terraform and Packer tools on your Cloud9 IDE, we need to install them on the system.
How to install Terraform on Ubuntu
You can find the official Terraform install steps at https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli .
How to install Packer on Ubuntu
Since we already have Hashicorp's Linux repository on our system, run the following command to install Packer:
sudo apt-get update && sudo apt-get install packer
How to install Ansible on Ubuntu
To install Ansible, follow the steps found here: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html.
You may need to update 'pip' to the latest version:
sudo -H pip3 install --upgrade pip
Once you have completed installing Terraform and Ansible, confirm they are installed:
terraform --version
packer --version
ansible --version
Congratulations! Your Cloud9 IDE is now set up and ready for use
That is it! In this tutorial, we set up a Cloud9 IDE that acts as a bastion for our AWS services and IaC tools. We installed Terraform, Packer, and Ansible, and verified their versions. We also set up an Elastic IP, so that it can be used in the future for tools such as Ansible to SSH into EC2 instances created by Terraform. We are now ready to start "Building Infrastructure with Terraform and Ansible."
Launch Your Project
Get your project off the ground
with Space-Rocket!
Fill out the form below to get started.