Skip to content

Commit

Permalink
Run every boot
Browse files Browse the repository at this point in the history
  • Loading branch information
carlssonk committed Sep 27, 2024
1 parent 6c42c26 commit 36b4d88
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions common/services/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ data "cloudinit_config" "this" {
gzip = false
base64_encode = false

part { // This will make sure that the config runs every time instance boots
content_type = "text/cloud-config"
content = <<-EOF
#cloud-config
cloud_final_modules:
- [scripts-user, always]
EOF
}

part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/nginx_proxy.tpl", {
Expand All @@ -50,9 +59,22 @@ data "cloudinit_config" "this" {
server_name = "blackjack.carlssonk.com flagracer.carlssonk.com"
})
}
# part {
# content_type = "text/x-shellscript"
# content = templatefile("${path.module}/run_every_boot.tpl", {
# nginx_config = templatefile("${path.module}/nginx_proxy.tpl", {
# services_map = {
# "flagracer.carlssonk.com" = "flagracer.carlssonk:8080", # TODO
# "blackjack.carlssonk.com" = "blackjack.carlssonk:8080", # TODO
# }
# dns_resolver_ip = "10.0.0.2"
# server_name = "blackjack.carlssonk.com flagracer.carlssonk.com"
# })
# })
# }
}

module "ec2_instance_nginx_proxy" {
module "ec2_instance_nginx" {
count = var.reverse_proxy_type == "nginx" ? 1 : 0
name = "nginx-reverse-proxy"
source = "../../modules/ec2-instance/default"
Expand Down Expand Up @@ -89,7 +111,7 @@ module "ec2_instance_nginx_proxy" {
module "ec2_instance_nginx_eip" {
count = var.reverse_proxy_type == "nginx" ? 1 : 0
source = "../../modules/elastic-ip/default"
instance_id = module.ec2_instance_nginx_proxy[0].id
instance_id = module.ec2_instance_nginx[0].id
}

module "main_alb_access_logs_bucket" {
Expand Down
2 changes: 1 addition & 1 deletion common/services/nginx_proxy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ http {
resolver ${dns_resolver_ip};
location / {
proxy_pass $upstream;
proxy_pass http://$upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
2 changes: 1 addition & 1 deletion common/services/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
output "policy_documents" {
value = [
try(module.service_discovery_namespace[0].policy_document, null),
try(module.ec2_instance_nginx_proxy[0].policy_document, null),
try(module.ec2_instance_nginx[0].policy_document, null),
try(module.ec2_instance_nginx_eip[0].policy_document, null),
try(module.main_alb[0].policy_document, null),
try(module.main_alb_access_logs_bucket[0].policy_document, null),
Expand Down

0 comments on commit 36b4d88

Please sign in to comment.