Skip to content

Commit

Permalink
feat(DMVP-1338): extract out frontend-app setup into own module to re…
Browse files Browse the repository at this point in the history
…-use from different projects
  • Loading branch information
aramkarapetian committed Oct 19, 2022
1 parent a604f98 commit 9be8934
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-vcs-permalinks
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
exclude: CHANGELOG.md
- id: check-yaml
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-case-conflict
- id: mixed-line-ending
args: [--fix=lf]
- id: detect-aws-credentials
args: ['--allow-missing-credentials']
- id: detect-private-key
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.62.3
hooks:
- id: terraform_fmt
- id: terraform_docs
args:
- '--args=--lockfile=false'
29 changes: 29 additions & 0 deletions cdn.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

module "cdn" {
source = "dasmeta/modules/aws//modules/cloudfront-ssl-hsts"
version = "0.36.7"

zone = [var.zone]
aliases = [var.domain]
comment = "cdn for ${var.domain}"
web_acl_id = try(module.waf[0].web_acl_arn, null)

origin = {
s3 = {
domain_name = module.s3.s3_bucket_website_endpoint
custom_origin_config = {
origin_protocol_policy = "http-only"
}
}
}

default_cache_behavior = {
target_origin_id = "s3"
use_forwarded_values = true
headers = []
}

providers = {
aws = aws.virginia
}
}
16 changes: 16 additions & 0 deletions dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module "dns" {
source = "../dns"

count = var.zone == null ? 0 : 1

zone = var.zone
create_zone = false

records = [
{
target_type = "cdn"
name = replace(var.domain, var.zone, "")
distribution_id = module.cdn.cloudfront_distribution_id
}
]
}
4 changes: 4 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
echo 'Start git pre-commit hooks and checks... ';
pre-commit run -a;
echo 'End git pre-commit hooks and checks... ';
14 changes: 14 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "s3_bucket_id" {
value = module.s3.s3_bucket_id
description = "s3 bucket name/id"
}

output "distribution_id" {
value = module.cdn.cloudfront_distribution_id
description = "cloudfront distribution id"
}

output "web_acl_id" {
value = try(module.waf[0].web_acl_id, null)
description = "waf arm/id"
}
21 changes: 21 additions & 0 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module "s3" {
source = "dasmeta/modules/aws//modules/s3"
version = "0.36.7"

name = var.domain
acl = "private"
create_index_html = true
ignore_public_acls = false
restrict_public_buckets = false
block_public_acls = false
block_public_policy = false

versioning = {
enabled = false
}
website = {
index_document = "index.html"
error_document = "index.html"
}
create_iam_user = false
}
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

variable "domain" {
type = string
description = "domain full name"
}

variable "zone" {
type = string
default = null
description = "R53 zone name"
}

variable "waf" {
type = any
default = null
description = "waf configs"
}

9 changes: 9 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = "> 0.15.0"

required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
23 changes: 23 additions & 0 deletions waf.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module "waf" {
source = "dasmeta/modules/aws//modules/waf"
version = "0.33.4"

count = try(var.waf.enabled, false) ? 1 : 0

name = try(var.waf.name, "${replace(var.domain, "/[\\W|_|\\s]+/", "-")}-firewall")

scope = try(var.waf.scope, "CLOUDFRONT")
visibility_config = try(var.waf.visibility_config, { cloudwatch_metrics_enabled = false, sampled_requests_enabled = true })
rules = try(var.waf.rules, [])
create_alb_association = try(var.waf.create_alb_association, false)
alb_arn_list = try(var.waf.alb_arn_list, [])
allow_default_action = try(var.waf.allow_default_action, true)
whitelist_ips = try(var.waf.whitelist_ips, [])
enable_whitelist = try(var.waf.enable_whitelist, true)

providers = {
// TODO: for cloudfront distribution the waf gets created in virginia, but for alb the specific region should be used,
// needs to decide how to accomplish this
aws = aws.virginia
}
}

0 comments on commit 9be8934

Please sign in to comment.