diff --git a/compute/main.tf b/compute/main.tf index b8e71b9..12a7d03 100644 --- a/compute/main.tf +++ b/compute/main.tf @@ -1,6 +1,8 @@ module "ec2" { source = "../modules/ec2" + domain_name = var.domain_name + record_name = var.record_name instance_type = var.instance_type instance_id = var.instance_id my_ip_address = var.my_ip_address diff --git a/compute/variables.tf b/compute/variables.tf index d258182..d757df6 100644 --- a/compute/variables.tf +++ b/compute/variables.tf @@ -5,3 +5,15 @@ variable "instance_type" {} variable "instance_id" {} variable "vpc_id" {} + +variable "domain_name" { + default = "staiwo.com" + description = "domain name" + type = string +} + +variable "record_name" { + default = "www" + description = "sub domain name" + type = string +} diff --git a/modules/ec2/elb.tf b/modules/ec2/elb.tf index 6677815..9222e48 100644 --- a/modules/ec2/elb.tf +++ b/modules/ec2/elb.tf @@ -74,6 +74,25 @@ resource "aws_lb_listener" "custom-elb" { load_balancer_arn = aws_lb.custom-elb.arn port = "80" protocol = "HTTP" + + default_action { + type = "redirect" + + redirect { + port = "443" + protocol = "HTTPS" + status_code = "HTTP_301" + } + } +} + +resource "aws_lb_listener" "https" { + load_balancer_arn = aws_lb.custom-elb.arn + port = "443" + protocol = "HTTPS" + ssl_policy = "ELBSecurityPolicy-2016-08" + certificate_arn = aws_acm_certificate.acm_certificate.arn + default_action { type = "forward" target_group_arn = aws_lb_target_group.elb-tg.arn diff --git a/modules/ec2/variables.tf b/modules/ec2/variables.tf index d258182..529ade4 100644 --- a/modules/ec2/variables.tf +++ b/modules/ec2/variables.tf @@ -5,3 +5,13 @@ variable "instance_type" {} variable "instance_id" {} variable "vpc_id" {} + +variable "domain_name" { + description = "domain name" + type = string +} + +variable "record_name" { + description = "sub domain name" + type = string +}