diff --git a/README.yaml b/README.yaml index 784812d..44fa851 100644 --- a/README.yaml +++ b/README.yaml @@ -44,15 +44,16 @@ usage : |- module "alb" { source = "clouddrove/alb/aws" version = "1.4.0" - name = "alb" + name = local.name enable = true internal = true load_balancer_type = "application" instance_count = module.ec2.instance_count - security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids] subnets = module.public_subnets.public_subnet_id target_id = module.ec2.instance_id vpc_id = module.vpc.vpc_id + allowed_ip = [module.vpc.vpc_cidr_block] + allowed_ports = [3306] listener_certificate_arn = module.acm.arn enable_deletion_protection = false with_target_group = true @@ -61,6 +62,34 @@ usage : |- https_port = 443 listener_type = "forward" target_group_port = 80 + + http_tcp_listeners = [ + { + port = 80 + protocol = "TCP" + target_group_index = 0 + }, + { + port = 81 + protocol = "TCP" + target_group_index = 0 + }, + ] + https_listeners = [ + { + port = 443 + protocol = "TLS" + target_group_index = 0 + certificate_arn = module.acm.arn + }, + { + port = 84 + protocol = "TLS" + target_group_index = 0 + certificate_arn = module.acm.arn + }, + ] + target_groups = [ { backend_protocol = "HTTP" @@ -80,7 +109,14 @@ usage : |- } } ] - } + + extra_ssl_certs = [ + { + https_listener_index = 0 + certificate_arn = module.acm.arn + } + ] + } ``` ### NLB Example @@ -88,9 +124,9 @@ usage : |- module "nlb" { source = "clouddrove/alb/aws" version = "1.4.0" - name = "nlb" + name = local.name enable = true - internal = true + internal = false load_balancer_type = "network" instance_count = module.ec2.instance_count subnets = module.public_subnets.public_subnet_id @@ -104,6 +140,11 @@ usage : |- protocol = "TCP" target_group_index = 0 }, + { + port = 81 + protocol = "TCP" + target_group_index = 0 + }, ] target_groups = [ { @@ -112,11 +153,26 @@ usage : |- target_type = "instance" }, { - backend_protocol = "TLS" - backend_port = 443 + backend_protocol = "TCP" + backend_port = 81 target_type = "instance" }, ] + + https_listeners = [ + { + port = 443 + protocol = "TLS" + target_group_index = 0 + certificate_arn = module.acm.arn + }, + { + port = 84 + protocol = "TLS" + target_group_index = 0 + certificate_arn = module.acm.arn + }, + ] } ``` @@ -125,28 +181,29 @@ usage : |- module "clb" { source = "clouddrove/alb/aws" version = "1.4.0" - name = "clb" - load_balancer_type = "classic" - clb_enable = true - internal = true - target_id = module.ec2.instance_id - security_groups = [module.ssh.security_group_ids, module.http_https.security_group_ids] - subnets = module.public_subnets.public_subnet_id - with_target_group = true + + name = local.name + load_balancer_type = "classic" + clb_enable = true + internal = true + vpc_id = module.vpc.vpc_id + target_id = module.ec2.instance_id + subnets = module.public_subnets.public_subnet_id + with_target_group = true listeners = [ { - lb_port = 22000 - lb_protocol = "TCP" - instance_port = 22000 - instance_protocol = "TCP" - ssl_certificate_id = null + lb_port = 22000 + lb_protocol = "TCP" + instance_port = 22000 + instance_protocol = "TCP" + ssl_certificate_id = null }, { - lb_port = 4444 - lb_protocol = "TCP" - instance_port = 4444 - instance_protocol = "TCP" - ssl_certificate_id = null + lb_port = 4444 + lb_protocol = "TCP" + instance_port = 4444 + instance_protocol = "TCP" + ssl_certificate_id = null } ] health_check_target = "TCP:4444" @@ -154,5 +211,5 @@ usage : |- health_check_interval = 30 health_check_unhealthy_threshold = 5 health_check_healthy_threshold = 5 - } + } ``` diff --git a/_example/alb/example.tf b/_example/alb/example.tf index 7c7ec0c..0a52e5c 100644 --- a/_example/alb/example.tf +++ b/_example/alb/example.tf @@ -84,7 +84,7 @@ module "ec2" { vpc_id = module.vpc.vpc_id ssh_allowed_ip = ["0.0.0.0/0"] ssh_allowed_ports = [22] - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z5bv7japQ5LZY1fFOK47S5KVo20y12XwkBcHeL5Bc8MuKt552JSRH7KKxvr2KD9QN5lCc0sOnQnlOK0INGHeIY4WnUSBvlVd4aOAJa4xE2PP0/kbDMAZfO6ET5OIlZF+X7n5VCYyxNJLWbx4opFIcpWgINz4m/GkArB4p4KeF+pc84rX5GkM4fn5SsMMpJTZmhhJYA2YW/E= mamraj@mamraj" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z" instance_count = 2 ami = "ami-08d658f84a6d84a80" instance_type = "t2.nano" diff --git a/_example/clb/example.tf b/_example/clb/example.tf index 034e29a..b9a61c2 100644 --- a/_example/clb/example.tf +++ b/_example/clb/example.tf @@ -88,7 +88,7 @@ module "ec2" { instance_type = "t2.nano" monitoring = false tenancy = "default" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z5bv7japQ5LZY1fFOK47S5KVo20y12XwkBcHeL5Bc8MuKt552JSRH7KKxvr2KD9QN5lCc0sOnQnlOK0INGHeIY4WnUSBvlVd4aOAJa4xE2PP0/kbDMAZfO6ET5OIlZF+X7n5VCYyxNJLWbx4opFIcpWgINz4m/GkArB4p4KeF+pc84rX5GkM4fn5SsMMpJTZmhhJYA2YW/E= mamraj@mamraj" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z5bv7japQ5LZY1fFOK47S5K" subnet_ids = tolist(module.public_subnets.public_subnet_id) iam_instance_profile = module.iam-role.name assign_eip_address = true diff --git a/_example/nlb/exampe.tf b/_example/nlb/exampe.tf index 2e97de4..78117c7 100644 --- a/_example/nlb/exampe.tf +++ b/_example/nlb/exampe.tf @@ -88,7 +88,7 @@ module "ec2" { ssh_allowed_ip = ["0.0.0.0/0"] ssh_allowed_ports = [22] tenancy = "default" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z5bv7japQ5LZY1fFOK47S5KVo20y12XwkBcHeL5Bc8MuKt552JSRH7KKxvr2KD9QN5lCc0sOnQnlOK0INGHeIY4WnUSBvlVd4aOAJa4xE2PP0/kbDMAZfO6ET5OIlZF+X7n5VCYyxNJLWbx4opFIcpWgINz4m/GkArB4p4KeF+pc84rX5GkM4fn5SsMMpJTZmhhJYA2YW/E= mamraj@mamraj" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCmPuPTJ58AMvweGBuAqKX+tkb0ylYq5k6gPQnl6+ivQ8i/jsUJ+juI7q/7vSoTpd0k9Gv7DkjGWg1527I+LJeropVSaRqwDcrnuM1IfUCu0QdRoU8e0sW7kQGnwObJhnRcxiGPa1inwnneq9zdXK8BGgV2E4POKdwbEBlmjZmW8j4JMnCsLvZ4hxBjZB/3fnvHhn7UCqd2C6FhOz9k+aK2kxXHxdDdO9BzKqtvm5dSAxHhw6nDHSU+cHupjiiY/SvmFH0QpR5Fn1kyZH7DxV4D8R9wvP9jKZe/RRTEkB2HY7FpVNz/EqO/z5bv7japQ5LZY1" subnet_ids = tolist(module.public_subnets.public_subnet_id) iam_instance_profile = module.iam-role.name assign_eip_address = true diff --git a/main.tf b/main.tf index 8e71389..f792c63 100644 --- a/main.tf +++ b/main.tf @@ -86,9 +86,9 @@ resource "aws_lb" "main" { enable_waf_fail_open = var.enable_waf_fail_open desync_mitigation_mode = var.desync_mitigation_mode xff_header_processing_mode = var.xff_header_processing_mode - ip_address_type = var.ip_address_type - tags = module.labels.tags - drop_invalid_header_fields = true + ip_address_type = var.ip_address_type + tags = module.labels.tags + drop_invalid_header_fields = true timeouts { create = var.load_balancer_create_timeout @@ -278,7 +278,7 @@ resource "aws_lb_target_group" "main" { ## For attaching resources with Elastic Load Balancer (ELB), see the aws_elb_attachment resource. ##----------------------------------------------------------------------------- resource "aws_lb_target_group_attachment" "attachment" { -# count = var.enable && var.with_target_group && var.load_balancer_type == "application" && var.target_type == "" ? var.instance_count : 0 + # count = var.enable && var.with_target_group && var.load_balancer_type == "application" && var.target_type == "" ? var.instance_count : 0 count = var.enable && var.with_target_group && var.load_balancer_type == "application" ? length(var.https_listeners) : 0 target_group_arn = element(aws_lb_target_group.main[*].arn, count.index)