Skip to content

Commit 9dd5cd0

Browse files
authored
Merge pull request #42 from hazelops/core-443
Proxy pick up nginx config
2 parents f668c7a + d4a7d4b commit 9dd5cd0

File tree

14 files changed

+64
-114
lines changed

14 files changed

+64
-114
lines changed

ecs-modules/ecs-task/locals.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ locals {
121121
"Resource" = "*"
122122
},
123123
{
124-
"Effect" : "Allow",
125-
"Action" : [
124+
"Effect" = "Allow",
125+
"Action" = [
126126
"firehose:PutRecordBatch"
127127
],
128-
"Resource" : [
128+
"Resource" = [
129129
"*"
130130
]
131131
},
@@ -148,6 +148,13 @@ locals {
148148
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_secret_path}/*",
149149
"arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter${local.ssm_global_secret_path}/*"
150150
]
151+
},
152+
{
153+
"Action" = [
154+
"kms:Decrypt"
155+
],
156+
"Effect" = "Allow",
157+
"Resource" = "*"
151158
}
152159
])
153160
}

examples/web-nginx-proxy/data.tf

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/web-nginx-proxy/main.tf

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,48 @@
1+
# Versions
2+
terraform {
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}
10+
11+
# Data
12+
data "aws_route53_zone" "root" {
13+
name = "${var.root_domain_name}."
14+
private_zone = false
15+
}
16+
17+
# Main
118
module "vpc" {
219
source = "registry.terraform.io/terraform-aws-modules/vpc/aws"
320
version = "~> 3.0"
421

522
name = "${var.env}-vpc"
6-
cidr = "10.30.0.0/16"
23+
cidr = "10.0.0.0/16"
724

825
azs = [
9-
"${var.aws_region}a"
26+
"${var.aws_region}a",
27+
"${var.aws_region}b"
1028
]
1129
public_subnets = [
12-
"10.30.10.0/23"
30+
"10.0.10.0/23",
31+
"10.0.12.0/23"
1332
]
1433

1534
private_subnets = [
16-
"10.30.20.0/23"
35+
"10.0.20.0/23"
1736
]
1837

38+
enable_nat_gateway = true
39+
single_nat_gateway = true
1940
manage_default_network_acl = true
2041
default_network_acl_name = "${var.env}-${var.namespace}"
2142
}
2243
resource "aws_security_group" "default_permissive" {
2344
name = "${var.env}-default-permissive"
2445
vpc_id = module.vpc.vpc_id
25-
description = "Managed by Terraform"
2646

2747
ingress {
2848
protocol = -1
@@ -42,20 +62,12 @@ resource "aws_security_group" "default_permissive" {
4262
]
4363
}
4464

45-
tags = {
46-
Terraform = "true"
47-
Env = var.env
48-
Name = "${var.env}-default-permissive"
49-
}
5065
}
5166

5267
resource "aws_route53_record" "env_ns_record" {
5368
zone_id = data.aws_route53_zone.root.id
5469
name = "${var.env}.${var.root_domain_name}"
5570
type = "NS"
56-
// ttl = "172800"
57-
58-
// Fast TTL for dev
5971
ttl = "60"
6072
records = aws_route53_zone.env_domain.name_servers
6173
}
@@ -64,62 +76,48 @@ resource "aws_route53_zone" "env_domain" {
6476
name = "${var.env}.${var.root_domain_name}"
6577
}
6678

67-
6879
module "ecs" {
6980
source = "registry.terraform.io/terraform-aws-modules/ecs/aws"
7081
version = "~> 4.0"
7182
cluster_name = "${var.env}-${var.namespace}"
7283
}
7384

74-
module "web_complete" {
85+
module "web_proxy" {
7586
source = "../.."
7687

77-
name = "app"
78-
app_type = "web"
79-
env = var.env
80-
namespace = var.namespace
81-
ecs_cluster_name = local.ecs_cluster_name
82-
83-
# Proxy enabling
84-
web_proxy_enabled = true
88+
name = "app"
89+
app_type = "web"
90+
env = var.env
91+
namespace = var.namespace
92+
93+
# Nginx Proxy enabling
94+
web_proxy_enabled = true
95+
# We mount a shared volume to /etc/nginx dir in our container. In order to the web proxy to work - your app must copy(create) Nginx config template to /etc/nginx/templates/default.conf.template. See proxied-prj/entrypoint.sh.
8596

86-
# Image should have some customization, see Dockerfile example at ./simple-prj
8797
# Containers
88-
docker_registry = local.docker_registry
89-
image_id = local.image_id
90-
docker_image_tag = local.docker_image_tag
91-
iam_instance_profile = local.iam_instance_profile
92-
key_name = local.key_name
98+
ecs_cluster_name = module.ecs.cluster_name
99+
docker_registry = var.docker_registry
100+
docker_image_tag = var.docker_image_tag
93101

94102
# Load Balancer
95103
public = true
104+
https_enabled = false
96105
alb_health_check_path = "/"
97-
alb_security_groups = local.alb_security_groups
106+
alb_security_groups = [aws_security_group.default_permissive.id]
98107
tls_cert_arn = local.tls_cert_arn
99108

100-
# EFS settings
101-
efs_enabled = false
102-
efs_mount_point = "/mnt/efs"
103-
efs_root_directory = "/"
104-
105109
# Network
106-
vpc_id = local.vpc_id
107-
public_subnets = local.public_subnets
108-
private_subnets = local.private_subnets
109-
security_groups = local.security_groups
110-
root_domain_name = var.root_domain_name
111-
zone_id = local.zone_id
112-
route53_health_check_enabled = false
113-
domain_names = [
114-
"app.${var.root_domain_name}"
115-
]
110+
vpc_id = module.vpc.vpc_id
111+
public_subnets = module.vpc.public_subnets
112+
private_subnets = module.vpc.private_subnets
113+
security_groups = [aws_security_group.default_permissive.id]
114+
root_domain_name = var.root_domain_name
115+
zone_id = aws_route53_zone.env_domain.id
116116

117117
# Environment variables
118118
app_secrets = [
119119
]
120120
environment = {
121-
ENV = var.env
122-
APP_NAME = "App"
123121
}
124122
}
125123

examples/web-nginx-proxy/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ output "private_subnet_cidrs" {
77
}
88

99
output "cloudwatch_log_group" {
10-
value = module.web_complete.cloudwatch_log_group
10+
value = module.web_proxy.cloudwatch_log_group
1111
}
1212

1313
output "ecs_cluster_name" {

examples/web-nginx-proxy/simple-prj/Dockerfile renamed to examples/web-nginx-proxy/proxied-prj/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ RUN set -ex && \
1919
ln -s /usr/bin/python3 /usr/bin/python
2020

2121
# Copy files and pipenv
22-
COPY ${PROJECT_PATH}/public/index.html ./public/index.html
22+
COPY ${PROJECT_PATH}/public/style.css ./public/style.css
2323
COPY ${PROJECT_PATH}/app.py ./
2424
COPY ${PROJECT_PATH}/Pipfile* ./
2525
COPY ${PROJECT_PATH}/nginx.conf.template ./
26-
COPY ${PROJECT_PATH}/docker-entrypoint.sh /
26+
COPY ${PROJECT_PATH}/entrypoint.sh /
2727

2828

2929
RUN python3 -m pip install pipenv
3030

3131
RUN pipenv install --deploy --system
3232

33-
ENTRYPOINT ["/docker-entrypoint.sh"]
33+
ENTRYPOINT ["/entrypoint.sh"]
3434

3535
EXPOSE 3000

examples/web-nginx-proxy/simple-prj/nginx.conf.template renamed to examples/web-nginx-proxy/proxied-prj/nginx.conf.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
client_max_body_size 20M;
22

33
upstream app {
4-
# Puma socket, as defined previously
4+
# Application server socket, as defined previously
55
server ${APP_HOST} fail_timeout=10;
66
}
77

@@ -16,7 +16,7 @@ server {
1616
add_header Cache-Control public;
1717
}
1818

19-
try_files $uri/index.html $uri @app;
19+
try_files $uri @app;
2020

2121
location @app {
2222
proxy_pass http://app;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: powderblue;
3+
}

examples/web-nginx-proxy/simple-prj/public/index.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/web-nginx-proxy/variables.tf

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
locals {
2-
env = var.env
3-
namespace = var.namespace
4-
5-
public_subnets = module.vpc.public_subnets
6-
private_subnets = module.vpc.private_subnets
7-
vpc_id = module.vpc.vpc_id
8-
security_groups = [aws_security_group.default_permissive.id]
9-
alb_security_groups = [aws_security_group.default_permissive.id]
10-
root_domain_name = var.root_domain_name
11-
zone_id = aws_route53_zone.env_domain.id
12-
13-
image_id = data.aws_ami.amazon_linux_ecs_generic.id
14-
docker_registry = var.docker_registry
15-
docker_image_tag = var.docker_image_tag
16-
17-
ecs_cluster_name = module.ecs.cluster_name
18-
tls_cert_arn = length(module.env_acm.acm_certificate_arn) > 0 ? module.env_acm.acm_certificate_arn : null
19-
}
20-
211
variable "env" {}
222
variable "namespace" {}
233
variable "aws_profile" {}
244
variable "aws_region" {}
25-
variable "ssh_public_key" {}
265
variable "docker_registry" {}
276
variable "docker_image_tag" {}
287
variable "root_domain_name" {}

examples/web-nginx-proxy/versions.tf

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)