Skip to content

Commit 9be8934

Browse files
feat(DMVP-1338): extract out frontend-app setup into own module to re-use from different projects
1 parent a604f98 commit 9be8934

File tree

9 files changed

+161
-0
lines changed

9 files changed

+161
-0
lines changed

.pre-commit-config.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.2.0
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-merge-conflict
7+
- id: check-vcs-permalinks
8+
- id: end-of-file-fixer
9+
- id: trailing-whitespace
10+
args: [--markdown-linebreak-ext=md]
11+
exclude: CHANGELOG.md
12+
- id: check-yaml
13+
- id: check-merge-conflict
14+
- id: check-executables-have-shebangs
15+
- id: check-case-conflict
16+
- id: mixed-line-ending
17+
args: [--fix=lf]
18+
- id: detect-aws-credentials
19+
args: ['--allow-missing-credentials']
20+
- id: detect-private-key
21+
- repo: https://github.com/antonbabenko/pre-commit-terraform
22+
rev: v1.62.3
23+
hooks:
24+
- id: terraform_fmt
25+
- id: terraform_docs
26+
args:
27+
- '--args=--lockfile=false'

cdn.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
module "cdn" {
3+
source = "dasmeta/modules/aws//modules/cloudfront-ssl-hsts"
4+
version = "0.36.7"
5+
6+
zone = [var.zone]
7+
aliases = [var.domain]
8+
comment = "cdn for ${var.domain}"
9+
web_acl_id = try(module.waf[0].web_acl_arn, null)
10+
11+
origin = {
12+
s3 = {
13+
domain_name = module.s3.s3_bucket_website_endpoint
14+
custom_origin_config = {
15+
origin_protocol_policy = "http-only"
16+
}
17+
}
18+
}
19+
20+
default_cache_behavior = {
21+
target_origin_id = "s3"
22+
use_forwarded_values = true
23+
headers = []
24+
}
25+
26+
providers = {
27+
aws = aws.virginia
28+
}
29+
}

dns.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module "dns" {
2+
source = "../dns"
3+
4+
count = var.zone == null ? 0 : 1
5+
6+
zone = var.zone
7+
create_zone = false
8+
9+
records = [
10+
{
11+
target_type = "cdn"
12+
name = replace(var.domain, var.zone, "")
13+
distribution_id = module.cdn.cloudfront_distribution_id
14+
}
15+
]
16+
}

githooks/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
echo 'Start git pre-commit hooks and checks... ';
3+
pre-commit run -a;
4+
echo 'End git pre-commit hooks and checks... ';

outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "s3_bucket_id" {
2+
value = module.s3.s3_bucket_id
3+
description = "s3 bucket name/id"
4+
}
5+
6+
output "distribution_id" {
7+
value = module.cdn.cloudfront_distribution_id
8+
description = "cloudfront distribution id"
9+
}
10+
11+
output "web_acl_id" {
12+
value = try(module.waf[0].web_acl_id, null)
13+
description = "waf arm/id"
14+
}

s3.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module "s3" {
2+
source = "dasmeta/modules/aws//modules/s3"
3+
version = "0.36.7"
4+
5+
name = var.domain
6+
acl = "private"
7+
create_index_html = true
8+
ignore_public_acls = false
9+
restrict_public_buckets = false
10+
block_public_acls = false
11+
block_public_policy = false
12+
13+
versioning = {
14+
enabled = false
15+
}
16+
website = {
17+
index_document = "index.html"
18+
error_document = "index.html"
19+
}
20+
create_iam_user = false
21+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
variable "domain" {
3+
type = string
4+
description = "domain full name"
5+
}
6+
7+
variable "zone" {
8+
type = string
9+
default = null
10+
description = "R53 zone name"
11+
}
12+
13+
variable "waf" {
14+
type = any
15+
default = null
16+
description = "waf configs"
17+
}
18+

versions.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = "> 0.15.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
}
8+
}
9+
}

waf.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module "waf" {
2+
source = "dasmeta/modules/aws//modules/waf"
3+
version = "0.33.4"
4+
5+
count = try(var.waf.enabled, false) ? 1 : 0
6+
7+
name = try(var.waf.name, "${replace(var.domain, "/[\\W|_|\\s]+/", "-")}-firewall")
8+
9+
scope = try(var.waf.scope, "CLOUDFRONT")
10+
visibility_config = try(var.waf.visibility_config, { cloudwatch_metrics_enabled = false, sampled_requests_enabled = true })
11+
rules = try(var.waf.rules, [])
12+
create_alb_association = try(var.waf.create_alb_association, false)
13+
alb_arn_list = try(var.waf.alb_arn_list, [])
14+
allow_default_action = try(var.waf.allow_default_action, true)
15+
whitelist_ips = try(var.waf.whitelist_ips, [])
16+
enable_whitelist = try(var.waf.enable_whitelist, true)
17+
18+
providers = {
19+
// TODO: for cloudfront distribution the waf gets created in virginia, but for alb the specific region should be used,
20+
// needs to decide how to accomplish this
21+
aws = aws.virginia
22+
}
23+
}

0 commit comments

Comments
 (0)