Skip to content

Commit

Permalink
feat(lightsail): adding ancv resume
Browse files Browse the repository at this point in the history
  • Loading branch information
kiraum committed Oct 23, 2024
1 parent 150e833 commit 19ff913
Show file tree
Hide file tree
Showing 7 changed files with 1,160 additions and 19 deletions.
45 changes: 43 additions & 2 deletions environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,22 @@ module "route53" {
type = "CNAME"
ttl = 300
records = ["protonmail3.domainkey.dempd74kuxcjabpnbahdxnyoscyzm34xj6e5of6vyqwjrw64bwqoq.domains.proton.ch."]
},
# lightsail
{
name = "ansiv"
type = "CNAME"
ttl = 300
records = [module.lightsail_ansiv.container_url]
},
# lightsail cert
{
name = module.lightsail_ansiv.domain_validation_records["ansiv.kiraum.it"].name
type = module.lightsail_ansiv.domain_validation_records["ansiv.kiraum.it"].type
ttl = 300
records = [module.lightsail_ansiv.domain_validation_records["ansiv.kiraum.it"].value]
}

]
},
"xpto_it" = {
Expand Down Expand Up @@ -271,7 +286,22 @@ module "route53" {
type = "CNAME"
ttl = 300
records = ["protonmail3.domainkey.d5cgr4quagzmaa5rqmmtnppt6lo46zuzu2zjylpuruv5luk4vmkuq.domains.proton.ch."]
},
# lightsail
{
name = "ansiv"
type = "CNAME"
ttl = 300
records = [module.lightsail_ansiv.container_url]
},
# lightsail cert
{
name = module.lightsail_ansiv.domain_validation_records["ansiv.xpto.it"].name
type = module.lightsail_ansiv.domain_validation_records["ansiv.xpto.it"].type
ttl = 300
records = [module.lightsail_ansiv.domain_validation_records["ansiv.xpto.it"].value]
}

]
}
}
Expand All @@ -287,8 +317,7 @@ module "route53" {
module "static_website" {
source = "../../modules/static_website"

bucket_name = "xpto-static-website-bucket"
# domain_names = ["kiraum.it"]
bucket_name = "xpto-static-website-bucket"
domain_names = ["xpto.it", "kiraum.it"]
cloudfront_price_class = "PriceClass_100"

Expand All @@ -303,3 +332,15 @@ module "static_website" {
aws.us_east_1 = aws.us_east_1
}
}


# Lightsail module
module "lightsail_ansiv" {
source = "../../modules/lightsail_ansiv"

container_name = "ansiv"
container_image = ":ansiv.resume.6"
availability_zone = "${var.aws_region}a"
bundle_id = "nano"
custom_domain_name = ["ansiv.xpto.it", "ansiv.kiraum.it"]
}
60 changes: 60 additions & 0 deletions modules/lightsail_ansiv/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
resource "aws_lightsail_container_service" "ansiv" {
name = var.container_name
power = var.bundle_id
scale = 1
is_disabled = false

private_registry_access {
ecr_image_puller_role {
is_active = true
}
}

public_domain_names {
certificate {
certificate_name = aws_lightsail_certificate.ansiv.name
domain_names = sort(var.custom_domain_name)
}
}

tags = {
Name = var.container_name
}
}

resource "aws_lightsail_container_service_deployment_version" "ansiv" {
service_name = aws_lightsail_container_service.ansiv.name

container {
container_name = var.container_name
image = var.container_image

command = ["serve", "file", "/app/resume.json", "--port", "8080"]

ports = {
8080 = "HTTP"
}
}

public_endpoint {
container_name = var.container_name
container_port = 8080



health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout_seconds = 10
interval_seconds = 300
path = "/"
success_codes = "200-499"
}
}
}

resource "aws_lightsail_certificate" "ansiv" {
name = "${var.container_name}-cert"
domain_name = var.custom_domain_name[0]
subject_alternative_names = slice(var.custom_domain_name, 1, length(var.custom_domain_name))
}
14 changes: 14 additions & 0 deletions modules/lightsail_ansiv/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "container_url" {
value = trimprefix(trimsuffix(aws_lightsail_container_service.ansiv.url, "/"), "https://")
description = "The clean domain name of the Lightsail container service"
}

output "domain_validation_records" {
value = {
for dvo in aws_lightsail_certificate.ansiv.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
value = dvo.resource_record_value
type = dvo.resource_record_type
}
}
}
Loading

0 comments on commit 19ff913

Please sign in to comment.