Skip to content

Commit

Permalink
ET-5331 Adapting modules and deleting redundant (#169)
Browse files Browse the repository at this point in the history
* Adapting modules and deleting redundant

* Adding optional domain

* Making public domain dynamic

* Adding health settings

* adapting

* Modifying variables

* Adding docker nginx

* Adding timeout
  • Loading branch information
jorge-cr-13 authored Jan 15, 2024
1 parent aa7cc8d commit aa2d99f
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 234 deletions.
9 changes: 9 additions & 0 deletions docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM nginx:latest

# Custom nginx conf
COPY default.conf /tmp/default_temp.conf

# Copy the entrypoint script to the container
COPY entrypoint.sh /docker-entrypoint.d/

RUN chmod +x /docker-entrypoint.d/entrypoint.sh
15 changes: 15 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
server_name ${SERVER_NAME};

location / {
access_log off;
proxy_pass http://${BACKEND_IP};
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# Set timeout values
proxy_read_timeout 600s;
}
}
3 changes: 3 additions & 0 deletions docker/nginx/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
envsubst '${SERVER_NAME} ${BACKEND_IP}' < /tmp/default_temp.conf > /etc/nginx/conf.d/default.conf
exec "$@"
29 changes: 18 additions & 11 deletions generic/lightsail/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,45 @@ resource "aws_lightsail_container_service" "this" {
}
}

public_domain_names {
certificate {
certificate_name = var.certificate_name
domain_names = [
var.subdomain_name,
"www.${var.subdomain_name}"
]
dynamic "public_domain_names" {
for_each = var.domain_name != "" ? [1] : []
content {
certificate {
certificate_name = var.certificate_name
domain_names = [
var.subdomain_name,
"www.${var.subdomain_name}"
]
}
}
}
}

# Domain settings
data "aws_route53_zone" "this" {
name = var.domain_name
count = var.domain_name != "" ? 1 : 0
name = var.domain_name
}

locals {
url_no_protocol = replace(replace(aws_lightsail_container_service.this.url, "https://", ""), "//$/", "")
url_no_protocol = replace(replace(aws_lightsail_container_service.this.url, "https://", ""), "//$/", "")
custom_domain_zone_id = var.domain_name != "" ? data.aws_route53_zone.this[0].id : ""
}

resource "aws_route53_record" "custom_domain" {
count = var.domain_name != "" ? 1 : 0
name = var.subdomain_name
type = "CNAME"
records = [local.url_no_protocol]
ttl = 300
zone_id = data.aws_route53_zone.this.id
zone_id = local.custom_domain_zone_id
}

resource "aws_route53_record" "www_custom_domain" {
count = var.domain_name != "" ? 1 : 0
name = "www.${var.subdomain_name}"
type = "CNAME"
records = [local.url_no_protocol]
ttl = 300
zone_id = data.aws_route53_zone.this.id
zone_id = local.custom_domain_zone_id
}
12 changes: 11 additions & 1 deletion generic/lightsail/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "lightsail_service_name" {
description = "Role created for lightsail use"
description = "Service name for the containers"
value = var.service_name
}

Expand All @@ -12,3 +12,13 @@ output "private_registry_access" {
description = "Describes a request to configure an Amazon Lightsail container service to access private container image repositories"
value = var.private_registry_access
}

output "service_public_url" {
description = "The url to access the service"
value = aws_lightsail_container_service.this.url
}

output "service_private_domain" {
description = "The private domain name of the container service"
value = aws_lightsail_container_service.this.private_domain_name
}
3 changes: 3 additions & 0 deletions generic/lightsail/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ variable "private_registry_access" {
variable "certificate_name" {
description = "Name of the validated certificate for SSL"
type = string
default = ""
}

variable "domain_name" {
description = "The name of the DNS region."
type = string
default = ""
}

variable "subdomain_name" {
description = "The domain name for the app."
type = string
default = ""
}
85 changes: 0 additions & 85 deletions generic/lightsail_container/main.tf

This file was deleted.

9 changes: 0 additions & 9 deletions generic/lightsail_container/outputs.tf

This file was deleted.

10 changes: 0 additions & 10 deletions generic/lightsail_container/terraform.tf

This file was deleted.

76 changes: 0 additions & 76 deletions generic/lightsail_container/variables.tf

This file was deleted.

34 changes: 17 additions & 17 deletions generic/lightsail_deployment/main.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
resource "aws_lightsail_container_service_deployment_version" "this" {
container {
container_name = var.service_name
image = var.container_image

command = var.container_command

environment = var.environmental_variables

ports = var.ports
dynamic "container" {
for_each = var.containers
content {
container_name = container.value.name
image = container.value.image
command = container.value.command
environment = container.value.envs
ports = container.value.port
}
}

public_endpoint {
container_name = var.service_name
container_port = keys(var.ports)[0]
container_name = var.public_container
container_port = var.public_port

health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout_seconds = 2
interval_seconds = 5
path = var.health_check_path
success_codes = var.health_success_codes
healthy_threshold = var.health_check.healthy_threshold
unhealthy_threshold = var.health_check.unhealthy_threshold
timeout_seconds = var.health_check.timeout_sec
interval_seconds = var.health_check.interval_sec
path = var.health_check.path
success_codes = var.health_check.success_code
}
}

Expand Down
Loading

0 comments on commit aa2d99f

Please sign in to comment.