Piers Karsenbarg

Setting Up Terraform

Posted at — Apr 25, 2019

So let’s start with Terraform. This post is going to be pretty short as I just set up some variables and the provider as AWS. I’m sure there are better ways of doing that, but this works for me.


variable "root_domain_name" {
  default = "piers.dev"

variable "access_key" {}
variable "secret_key" {}


provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region = "us-east-1"

Couple of notes about this. I’m using us-east-1 because that’s the region that Cloudfront looks at for certificates and since the site will be behind Cloudfront (which is global) and stored in S3 (which is global) then it doesn’t really matter does it?

The access_key and secret_key variables are stored in a separate secret.tvars file that looks like this:


access_key = "yourawsaccesskey"
secret_key = "yourawssecretkey"

Obviously I’m not going to paste my actual ones here.

First of all you should run the following to initialise Terraform:

terraform init

This downloads the provider necessary for Terraform to run the code. Then you can run the following:

terraform apply -var-file=secret.tfvars

Which uses the variable tvars file and applies the access key and secret key.