This is my solution for the auxis test provided at the technical interview.
For our Terraform instance to connect to the AWS instances, we will need to generate a key pair:
$ ssh-keygen -t rsa -f auxis_keypair
...
$ ls auxis_keypair*
auxis_keypair auxis_keypair.pub
auxis_keypair is our PEM file and the other is the public key that we will be using for our connection thru the SSH Agent. Then you need to import this using the AWS console in order to be used:
- Go to Services and under Compute click on EC2. The EC2 Dashboard will welcome you with information about your current instances, security groups, key pairs, etc.
- Under Resources you will see the Key Pairs link.
- Click on Import Key Pair and then upload the public key file previously created.
- Set the name as auxis_keypair and click on Import.
You'll need to set up the ssh_agent:
$ eval `ssh-agent`
Note: The keys should be in the root directory of the repo, one directory before the Terraform and Chef code (../terraform/
)
Cookbooks are already included in the commit. You can test the specs:
$ cd chef-repo/cookbooks/tomcat/
$ chef exec rspec
And foodcritic:
$ cd chef-repo/
$ foodcritic -B cookbooks/
After installing Terraform (in my case I used pacman: sudo pacman -S -q community/terraform
) we change the working directory to terraform/ and init it:
$ cd terraform/ && terraform init
Tip: you can check the plan via terraform plan
or reverse the plan with terraform destroy -force
.
If everything is OK then you have to export the AWS Access Key and Secret Access Key in order to run the terraform plan:
$ export AWS_ACCESS_KEY_ID="..."
$ export AWS_SECRET_ACCESS_KEY="..."
$ terraform apply -auto-approve
And it will start deploying the environment.
Note: Due to DNS catching or replication, check the load balancers' DNS name from other clients.