Welcome to the part 3 of VPC and Terraform with AWS. In this post, we will use our previously written code to provision infrastructure using terraform

Let’s start to build our infrastructure. In order to use AWS provider, we must force on terraform to download necessary plugins. Type below command to do this

$ terraform init

You should get the message, that Terraform has been successfully initialized!. Let’s run another command to check what terraform is going to configure in our infrastructure:

$ terraform plan

You should get a message that terraform is going to add 17 items with the full description of each. Let’s run the final command to provision the infrastructure:

$ terraform apply

Terraform will prompt you for the confirmation. Type “yes” to continue. Now go to AWS Console and check if new resources have been successfully created. Below are some of the examples

access config

access config

access config

access config

As you can see, our code is working! We have successfully created our infrastructure using Terraform! WOW!!! :)

Let’s do some cleanup before AWS will start to charge us for the resource we used to demonstrate this use case. You can run the following command to destroy all infrastructure which was provisioned by terraform

$ terraform destroy

Confirm by yes and terraform will delete all resources created earlier.

As you remember, at the beginning of this topic we initialized the GIT repository. Now it’s a time to upload it to our GIT repository. First, make sure you created an appropriate remote repository and configured access to it. See my previous post how to create CodeCommit repository Terraform.

It’s a good practice to do not upload variable values, terraform remote state files as well as any dependencies. Let’s remove all of these kinds of files from being uploaded.

cd ~\devops-aws\
cat << EOF > .gitignore
*/terraform.tfvars
*/terraform.tfstate
*/terraform.tfstate.backup
*/.terraform
EOF

Next configure a remote repository and upload our changes, here is some example.

cd ~\devops-aws\
git remote add origin https://url-to-your-git/user/repo.git
git remote -v
git add .
git commit -m "my commit message"
git push origin master

Now our code is stored in remote GIT repository. The original code used for this tutorial can be found at my GitHub https://github.com/mycloudfun/devops-aws.

Feel free to test this code.

I hope you’ve enjoyed the reading! Any feedback is very welcome.

Cheers!