Skip to content

Commit

Permalink
Switch to more generic names for infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
sparshadotel committed Aug 27, 2019
1 parent 42df427 commit 472c520
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 53 deletions.
2 changes: 1 addition & 1 deletion infrastructure/config.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"client_workspace": "my-client-workspace",
"client_name": "my-client-workspace",
"aws_region": "some-region",
"aws_access_key": "SomeThingLikeThis",
"aws_secret_key": "VerySecretKeyWhichIamN0tGonnaWrite",
Expand Down
7 changes: 4 additions & 3 deletions infrastructure/shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type s3WebsiteVariables struct {
CLIENT_WORKSPACE string `json:"client_workspace"`
CLIENT_NAME string `json:"client_name"`
AWS_REGION string `json:"aws_region"`
AWS_ACCESS_KEY string `json:"aws_access_key"`
AWS_SECRET_KEY string `json:"aws_secret_key"`
Expand All @@ -38,6 +38,7 @@ func generateTemplateFile(templateLocation string, s3Args s3WebsiteVariables, te
if err != nil {
panic(err)
}

}

func initTerraform(workspaceDir string) {
Expand Down Expand Up @@ -112,8 +113,8 @@ func main() {
if err != nil {
panic(err)
}
workspaceDir := filepath.Join("/tmp", s3Args.CLIENT_WORKSPACE)
generateTemplateFile("templates/providers/aws/s3-website/terraform.tpl", s3Args, workspaceDir)
workspaceDir := filepath.Join("/tmp", s3Args.CLIENT_NAME)
generateTemplateFile("templates/providers/aws/frontend-architecture/terraform.tpl", s3Args, workspaceDir)
initTerraform(workspaceDir)
planTerraform(workspaceDir)
applyTerraform(workspaceDir)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Backend Initialization
terraform {
backend "remote" {
organization = "lftechnology"
token = "{{ info.TERRAFORM_TOKEN }}"
workspaces {
name = "{{ info.CLIENT_NAME }}"
}
}
}

// Provider Initialization
provider "aws" {
region = "{{ info.AWS_REGION }}"
access_key = "{{ info.AWS_ACCESS_KEY }}"
secret_key = "{{ info.AWS_SECRET_KEY }}"
}

//Bucket Initialization
resource "aws_s3_bucket" "bucket" {
bucket = "{{ info.AWS_S3_BUCKET_NAME }}"
acl = "public-read"
force_destroy = "true"
website {
index_document = "index.html"
error_document = "index.html"
}

policy = <<POLICY
{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"AddPerm",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::{{ info.AWS_S3_BUCKET_NAME }}/*"]
}
]
}
POLICY
}

resource "aws_cloudfront_distribution" "www_distribution" {
// origin is where CloudFront gets its content from.
origin {
custom_origin_config {
// These are all the defaults.
http_port = "80"
https_port = "443"
origin_protocol_policy = "http-only"
origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
}
// Here we're using our S3 bucket's URL!
domain_name = aws_s3_bucket.bucket.website_endpoint
// This can be any name to identify this origin.
origin_id = "{{ info.AWS_S3_BUCKET_NAME }}"
}
enabled = true
default_root_object = "index.html"
// All values are defaults from the AWS console.
default_cache_behavior {
viewer_protocol_policy = "redirect-to-https"
compress = true
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = ["GET", "HEAD"]
// This needs to match the `origin_id` above.
target_origin_id = "{{ info.AWS_S3_BUCKET_NAME }}"
min_ttl = 0
default_ttl = 86400
max_ttl = 31536000
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
}
wait_for_deployment = false
tags = {
Name = "{{ info.AWS_S3_BUCKET_NAME }}"
Project = "{{ info.CLIENT_NAME }}"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
}
// 404 Handling
custom_error_response {
error_code = 404
response_code = 200
response_page_path = "/"
}
}

// Outputs

output "bucket_name" {
value = aws_s3_bucket.bucket.bucket
}

output "frontend_web_url" {
value = aws_cloudfront_distribution.www_distribution.domain_name
}
49 changes: 0 additions & 49 deletions infrastructure/templates/providers/aws/s3-website/terraform.tpl

This file was deleted.

0 comments on commit 472c520

Please sign in to comment.