Skip to content

Commit

Permalink
added(iac): added terraform directory for creating web app infrastruc…
Browse files Browse the repository at this point in the history
…ture (#15)
  • Loading branch information
SSouik authored Apr 16, 2022
1 parent 6d372ec commit 3cd3df3
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 1 deletion.
43 changes: 43 additions & 0 deletions .github/workflows/pull-request.terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Pull Request Terraform Checks

on:
pull_request:
branches:
- 'main'
paths:
- 'terraform/**'

jobs:
validate:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
steps:
- name: Checkout the source code
uses: actions/checkout@v2
- name: Setup terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.8
- name: Initialize Terraform modules
run: terraform init
- name: Validate Terraform
run: terraform validate

format:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
steps:
- name: Checkout the source code
uses: actions/checkout@v2
- name: Setup terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.8
- name: Initialize Terraform modules
run: terraform init
- name: Check the Terraform format
run: terraform fmt -recursive -check
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ yarn-error.log*

# vercel
.vercel

# local .terraform directories and files
.terraform/
.terraform.*

# .tfstate files
*.tfstate
*.tfstate.*

# .tfvars files
*.tfvars
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "personal-website-template",
"version": "1.1.0",
"version": "2.0.0",
"private": false,
"license": "MIT",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions terraform/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
# backend "s3" {
# bucket = "" # Replace with the name of the S3 bucket to place remote state
# key = "" # Name of the .tfstate file in the S3 bucket
# region = "us-east-1"
# }

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
}
64 changes: 64 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
locals {
region = "us-east-1"
env = "test"
app_name = "mywebsite-app"
domain_name = "www.mywebsite.com"
acm_domain = "*.mywebsite.com" # replace with the domain name attached to your ACM certificate
hosted_zone_id = "ABC123" # Replace with Hosted ZOne ID of your domain name

# Custom error responses for AWS CloudFront
responses = [
{
error_code = 404,
response_code = 404,
response_page_path = "/404"
},
{
error_code = 403,
response_code = 404,
response_page_path = "/404"
}
]

s3_apps = {
"mywebsite-app" = {
domain_name = "www.mywebsite.bucket"
s3_config = {
error_document = "index.html"
index_document = "index.html"
force_destroy = true
acl = "private"
}
app_config = null
origin_path = ""
cache_behavior = {
path_pattern = "*"
allowed_methods = ["GET", "HEAD"]
cached_methods = ["GET", "HEAD"]
forwarded_values = {
query_string = false
cookies = "none"
}
lambdas = []
default_ttl = 3600
min_ttl = 0
max_ttl = 86400
viewer_protocol_policy = "redirect-to-https"
}
}
}
}

module "aws_cloudfront_app" {
source = "git::https://github.com/SSouik/aws-cloudfront-app.git?ref=v2.1.0"
region = local.region
env = local.env
app_name = local.app_name
domain_name = local.domain_name
cloudfront_responses = local.responses
use_acm_certificate = true
route53_zone_id = local.hosted_zone_id
acm_certificate_domain = local.acm_domain
default_app_name = "mywebsite-app" # Must match the name of your S3 App
s3_app_configs = local.s3_apps
}
3 changes: 3 additions & 0 deletions terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "us-east-1" # replace with your region
}
1 change: 1 addition & 0 deletions terraform/terraform.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.8

0 comments on commit 3cd3df3

Please sign in to comment.