This is the very first article of the Deploying infrastructure with Terraform+AWS+Packer+Ansible series, to show a basic infrastructure deployment on AWS.
In this post we’ll use terraform to create an instance on AWS, but we’ll do a little more than that.
We’ll create everything you need to get an instance running: vpc, subnet, securitygroup, keypair, internet gateway, route table….
Why ? Because that’s what you would do when creating a new application or customer environment. Breaking your different applications / customers / environments into their own VPCs is a good way to completely isolate one from the others and make them easier to manage as code, as each application can have it’s own repo with all the infrastructure need.
What is needed ?
- Git installed
- Terraform installed
- AWS IAM account with API keys (access key and secret key)
- Git clone my TAPA repo: https://github.com/andreramoni/tapa.git
Chdir to the 101-terraform+aws directory.
Edit the keypair.tf file and put your ssh pubkey instead of mine.
Take a moment and read all the files to star becoming familiar with terraform+aws.
Every first time you run terraform in a directory, you should initialize it first so it can download external components that are needed for that .tf files.
Run terraform init:
You should see something like this:
Now let’s see what these terraform files would do on AWS:
Run terraform plan:
It will show every resource it will create.
You should see this at the end:
If everything is alright, it’s time to apply it:
Run terraform apply:
You should see something like this in the end:
At this point, you can SSH into the instance using the public IP, centos user and your ssh pubkey.
That’s all by now.
To destroy everything created with this terraform, run terraform destroy:
Congratulations, you have done the very basic example usage of terraform+aws.
Stay tuned for the next examples.