Going over board

So, for those that don’t know. I love Terraform . And when you are building your infrastructure it’s easy to take things too far. I am not sure if I did, but sure enough, the first place I started with Terraform was not actually the IaC that will be running any code. I started with building out the GitHub repo, and AWS IAM permissions with Terraform . And no, not the AWS IAM permissions to run the code either… I defined the AWS IAM permissions for GitHub to be able to plan and build the infrastructure. If you want to know more about what I am doing with that, feel free to look at GitHub Infrastructure.

Setup

I expect this project to be large, and so I decided that I needed to have a folder structure to help organize the pieces. However, with Terraform that means I will need to use modules. It bugs me a little because I am not intending to reuse them in the project, but I needed some organization.

So I started by defining my terraform block and providers. I had to define two providers, because even though Amazon CloudFront is global, some resources like AWS WAF are required to be built in us-east-1 because the linked resource is seen as being in that region.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
  backend "s3" {
    bucket = "rayprogramming-terraform"
    key    = "video"
    region = "us-east-2"
  }
}

# Configure the AWS Provider
provider "aws" {
  region = "us-east-2"
}
provider "aws" {
  region = "us-east-1"
  alias  = "east-1"
}

I went ahead and defined my root domain/zone as a data source so that I can use it in the modules to link resources to my domain.

data "aws_route53_zone" "selected" {
  name = "rayprogramming.com"
}

Frontend

I only have the front end module for now, and I expect it to change overtime as well.

module "frontend" {
  source = "./frontend/"
  name   = "video"
  domain = data.aws_route53_zone.selected.name
  zoneid = data.aws_route53_zone.selected.zone_id
}

However, inside of that this is my file structure I am going with at this time. This structure is to help me separate concerns and organize my thoughts into code. I think at this time, I will leave this as my final bit of getting started. I have the code and it can be viewed on videoStreamer