Terraform
A tool that enables infrastructure as code to set up servers in AWS EC2.
Cloud Dev environments
To set up a developer's development environment in AWS, run this terraform project. The scripts will allow the joining of an existing VPC, the creation of a public subnet and a variable number of EC2 instances that the user will have SSH access to. Alarms have been created in the scripts which will auto-shutdown the instances after a configurable period, based on CPU metrics. A Lambda scheduled event can also be configured which can run at a regular interval to shut down any instances that may still be running.
Pre-requisites
Creating a VPC
This should only be done once per AWS account as there is a limit of 5 per region. Please check if this has already been run and use the existing VPC_ID and SUBNET_ID for the following section if it does and skips to the next section.
Navigate to the infrastructure/terraform/vpc directory
Initialize Terraform project:
terraform initExecute the following:
terraform applyCopy the output for the next step, e.g for ICAP this has already been run and this is the result:
Apply complete! Resources: 5 added, 0 changed, 0 destroyed.
Outputs:
SUBNET_ID = "subnet-0004b0dacb5862d59"
VPC_ID = "vpc-067ab69f374ac9f47"Creating EC2 instances
Navigate to the infrastructure/terraform directory
Initialize Terraform project:
The following properties have to be set:
The configuration can be done using an terraform variable file. Create a file called my.tfvars. Below is an example that illustrates the structure of the environment variables file. This example is of a configuration that you can use for the ICAP CDR. Please replace {user} with your own user.
The AWS account to be used is defined in the ~/.aws/credentials file. If you don't have file this make sure you have configured the AWS CLI.
The sample file above has access to 3 accounts and the options for <account_name> could be "default", "jembi-sandbox", "jembi-icap"
Optionally, add ACCOUNT = "<account_name>" to my.tfvars if you want to use something other than default.
The flag for specifying an environment variables file is -var-file, create the AWS stack by running:
Once the script has run successfully, the ip addresses and domains for the servers will be displayed:
SSH access should be now available - use the default 'ubuntu' user - ssh ubuntu@<ip_address>
Destroying the AWS stack - run:
Last updated
Was this helpful?