diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 0a52135..1480640 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -16,11 +16,11 @@ jobs: with: actions_subcommand: 'fmt' - - name: 'Terraform Init' + - name: 'ALB Terraform Init' uses: clouddrove/github-actions@v2.0 with: actions_subcommand: 'init' - tf_actions_working_dir: ./_example + tf_actions_working_dir: ./_example/alb - name: Configure AWS Credentials uses: clouddrove/configure-aws-credentials@v1 @@ -29,19 +29,41 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-east-2 - - name: 'Terraform Plan' + - name: 'ALB Terraform Plan' uses: clouddrove/github-actions@v2.0 with: actions_subcommand: 'plan' - tf_actions_working_dir: ./_example + tf_actions_working_dir: ./_example/alb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: 'Terratest' + - name: 'ALB Terratest' uses: clouddrove/github-actions@v2.0 with: actions_subcommand: 'terratest' - tf_actions_working_dir: ./_test + tf_actions_working_dir: ./_test/alb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 'CLB Terraform Init' + uses: clouddrove/github-actions@v2.0 + with: + actions_subcommand: 'init' + tf_actions_working_dir: ./_example/clb + + - name: 'CLB Terraform Plan' + uses: clouddrove/github-actions@v2.0 + with: + actions_subcommand: 'plan' + tf_actions_working_dir: ./_example/clb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: 'CLB Terratest' + uses: clouddrove/github-actions@v2.0 + with: + actions_subcommand: 'terratest' + tf_actions_working_dir: ./_test/clb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index fc7f933..6d3513f 100644 --- a/README.md +++ b/README.md @@ -68,33 +68,139 @@ This module has a few dependencies: **IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-alb/releases). -### Simple Example -Here is an example of how you can use this module in your inventory structure: +Here are examples of how you can use this module in your inventory structure: +### ALB Example ```hcl - module "alb" { - source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.5" - name = "alb" - application = "clouddrove" - environment = "test" - label_order = ["environment", "name", "application"] - internal = false - load_balancer_type = "application" - instance_count = 2 - security_groups = ["sg-xxxxxxx"] - subnets = "subnet-xxxxxxx" - enable_deletion_protection = false - target_id = "i-xxxxxxxxxx" - vpc_id = "vpc-xxxxxxxxx" - target_group_protocol = "HTTP" - target_group_port = 80 - listener_certificate_arn = "arn:aws:acm:eu-west-1:xxxxxxxxxxxx:certificate/xxxxxx-xxxx-xxxxx-xxxx" - https_enabled = true - http_enabled = true - https_port = 443 - listener_type = "forward" + module "alb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + name = "alb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + internal = false + 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 + enable_deletion_protection = false + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + https_enabled = true + http_enabled = true + https_port = 443 + listener_type = "forward" + listener_certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_port = 80 + target_groups = [ + { + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" + deregistration_delay = 300 + health_check = { + enabled = true + interval = 30 + path = "/" + port = "traffic-port" + healthy_threshold = 3 + unhealthy_threshold = 3 + timeout = 10 + protocol = "HTTP" + matcher = "200-399" + } + } + ] } ``` +### NLB Example +```hcl + module "alb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + name = "nlb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + internal = false + load_balancer_type = "application" + instance_count = module.ec2.instance_count + subnets = module.public_subnets.public_subnet_id + enable_deletion_protection = false + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + http_tcp_listeners = [ + { + port = 80 + protocol = "TCP" + target_group_index = 0 + }, + ] + + https_listeners = [ + { + port = 443 + protocol = "TLS" + certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_index = 1 + }, + ] + + target_groups = [ + { + backend_protocol = "TCP" + backend_port = 80 + target_type = "instance" + }, + { + backend_protocol = "TLS" + backend_port = 443 + target_type = "instance" + }, + ] + } +``` + +### CLB Example +```hcl + module "clb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + + name = "clb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + load_balancer_type = "classic" + internal = false + 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 + + listeners = [ + { + 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 + } + ] + + health_check_target = "TCP:4444" + health_check_timeout = 10 + health_check_interval = 30 + health_check_unhealthy_threshold = 5 + health_check_healthy_threshold = 5 +} +``` + @@ -104,71 +210,78 @@ Here is an example of how you can use this module in your inventory structure: | Name | Description | Type | Default | Required | |------|-------------|:----:|:-----:|:-----:| -| access\_logs | Access logs Enable or Disable. | bool | `"false"` | no | -| alb\_environment | A mapping of tags to assign to the resource. | string | `""` | no | -| alb\_name | The name of the LB. This name must be unique within your AWS account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen. If not specified, Terraform will autogenerate a name beginning with tf-lb. | string | `""` | no | -| allocation\_id | The allocation ID of the Elastic IP address. | string | `""` | no | -| application | Application \(e.g. `cd` or `clouddrove`\). | string | `""` | no | -| attributes | Additional attributes \(e.g. `1`\). | list | `` | no | -| delimiter | Delimiter to be used between `organization`, `environment`, `name` and `attributes`. | string | `"-"` | no | -| deregistration\_delay | The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds. | number | `"300"` | no | -| enable | If true, create alb. | bool | `"true"` | no | -| enable\_cross\_zone\_load\_balancing | Indicates whether cross zone load balancing should be enabled in application load balancers. | bool | `"false"` | no | -| enable\_deletion\_protection | If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to false. | string | `""` | no | -| enable\_http2 | Indicates whether HTTP/2 is enabled in application load balancers. | bool | `"true"` | no | -| environment | Environment \(e.g. `prod`, `dev`, `staging`\). | string | `""` | no | -| health\_check\_healthy\_threshold | The number of consecutive health checks successes required before considering an unhealthy target healthy. | number | `"2"` | no | -| health\_check\_interval | The duration in seconds in between health checks. | number | `"15"` | no | -| health\_check\_matcher | The HTTP response codes to indicate a healthy check. | string | `"200-399"` | no | -| health\_check\_path | The destination for the health check request. | string | `"/"` | no | -| health\_check\_timeout | The amount of time to wait in seconds before failing a health check request. | number | `"10"` | no | -| health\_check\_unhealthy\_threshold | The number of consecutive health check failures required before considering the target unhealthy. | number | `"2"` | no | -| http\_enabled | A boolean flag to enable/disable HTTP listener. | bool | `"true"` | no | -| http\_listener\_type | The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc. | string | `"redirect"` | no | -| http\_port | The port on which the load balancer is listening. like 80 or 443. | number | `"80"` | no | -| https\_enabled | A boolean flag to enable/disable HTTPS listener. | bool | `"true"` | no | -| https\_port | The port on which the load balancer is listening. like 80 or 443. | number | n/a | yes | -| idle\_timeout | The time in seconds that the connection is allowed to be idle. | number | `"60"` | no | -| instance\_count | The count of instances. | number | `"0"` | no | -| internal | If true, the LB will be internal. | string | `""` | no | -| ip\_address\_type | The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. | string | `"ipv4"` | no | -| label\_order | Label order, e.g. `name`,`application`. | list | `` | no | -| listener\_certificate\_arn | The ARN of the SSL server certificate. Exactly one certificate is required if the protocol is HTTPS. | string | `""` | no | -| listener\_protocol | The protocol for connections from clients to the load balancer. Valid values are TCP, HTTP and HTTPS. Defaults to HTTP. | string | `"HTTPS"` | no | -| listener\_ssl\_policy | The security policy if using HTTPS externally on the load balancer. \[See\]\(https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html\). | string | `"ELBSecurityPolicy-2016-08"` | no | -| listener\_type | The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc. | string | n/a | yes | -| load\_balancer\_create\_timeout | Timeout value when creating the ALB. | string | `"10m"` | no | -| load\_balancer\_delete\_timeout | Timeout value when deleting the ALB. | string | `"10m"` | no | -| load\_balancer\_type | The type of load balancer to create. Possible values are application or network. The default value is application. | string | `""` | no | -| load\_balancer\_update\_timeout | Timeout value when updating the ALB. | string | `"10m"` | no | -| log\_bucket\_name | S3 bucket \(externally created\) for storing load balancer access logs. Required if logging\_enabled is true. | string | `""` | no | -| managedby | ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'. | string | `"anmol@clouddrove.com"` | no | -| name | Name \(e.g. `app` or `cluster`\). | string | `""` | no | -| security\_groups | A list of security group IDs to assign to the LB. Only valid for Load Balancers of type application. | list | `` | no | -| status\_code | The HTTP redirect code. The redirect is either permanent \(HTTP\_301\) or temporary \(HTTP\_302\). | string | `"HTTP_301"` | no | -| subnet\_id | The id of the subnet of which to attach to the load balancer. You can specify only one subnet per Availability Zone. | string | `""` | no | +| access_logs | Access logs Enable or Disable. | bool | `false` | no | +| allocation_id | The allocation ID of the Elastic IP address. | string | `` | no | +| application | Application (e.g. `cd` or `clouddrove`). | string | `` | no | +| attributes | Additional attributes (e.g. `1`). | list | `` | no | +| availability_zones | The AZ's to serve traffic in. | list(map(string)) | `` | no | +| connection_draining | TBoolean to enable connection draining. Default: false. | bool | `false` | no | +| connection_draining_timeout | The time after which connection draining is aborted in seconds. | number | `300` | no | +| delimiter | Delimiter to be used between `organization`, `environment`, `name` and `attributes`. | string | `-` | no | +| drop_invalid_header_fields | Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). The default is false. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. Only valid for Load Balancers of type application. | bool | `false` | no | +| enable | If true, create alb. | bool | `true` | no | +| enable_connection_draining | Whether or not to enable connection draining ("true" or "false"). | bool | `false` | no | +| enable_cross_zone_load_balancing | Indicates whether cross zone load balancing should be enabled in application load balancers. | bool | `false` | no | +| enable_deletion_protection | If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to false. | string | `` | no | +| enable_http2 | Indicates whether HTTP/2 is enabled in application load balancers. | bool | `true` | no | +| environment | Environment (e.g. `prod`, `dev`, `staging`). | string | `` | no | +| health_check_healthy_threshold | The number of successful health checks before an instance is put into service. | number | `10` | no | +| health_check_interval | The time between health check attempts in seconds. | number | `30` | no | +| health_check_target | The target to use for health checks. | string | `TCP:80` | no | +| health_check_timeout | The time after which a health check is considered failed in seconds. | number | `5` | no | +| health_check_unhealthy_threshold | The number of failed health checks before an instance is taken out of service. | number | `2` | no | +| http_enabled | A boolean flag to enable/disable HTTP listener. | bool | `true` | no | +| http_listener_type | The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc. | string | `redirect` | no | +| http_port | The port on which the load balancer is listening. like 80 or 443. | number | `80` | no | +| http_tcp_listeners | A list of maps describing the HTTP listeners for this ALB. Required key/values: port, protocol. Optional key/values: target_group_index (defaults to 0) | list(map(string)) | `` | no | +| https_enabled | A boolean flag to enable/disable HTTPS listener. | bool | `true` | no | +| https_listeners | A list of maps describing the HTTPS listeners for this ALB. Required key/values: port, certificate_arn. Optional key/values: ssl_policy (defaults to ELBSecurityPolicy-2016-08), target_group_index (defaults to 0) | list(map(string)) | `` | no | +| https_port | The port on which the load balancer is listening. like 80 or 443. | number | `443` | no | +| idle_timeout | The time in seconds that the connection is allowed to be idle. | number | `60` | no | +| instance_count | The count of instances. | number | `0` | no | +| internal | If true, the LB will be internal. | string | `` | no | +| ip_address_type | The type of IP addresses used by the subnets for your load balancer. The possible values are ipv4 and dualstack. | string | `ipv4` | no | +| label_order | Label order, e.g. `name`,`application`. | list | `` | no | +| listener_certificate_arn | The ARN of the SSL server certificate. Exactly one certificate is required if the protocol is HTTPS. | string | `` | no | +| listener_protocol | The protocol for connections from clients to the load balancer. Valid values are TCP, HTTP and HTTPS. Defaults to HTTP. | string | `HTTPS` | no | +| listener_ssl_policy | The security policy if using HTTPS externally on the load balancer. [See](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html). | string | `ELBSecurityPolicy-2016-08` | no | +| listener_type | The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc. | string | `forward` | no | +| listeners | A list of listener configurations for the ELB. | object | - | yes | +| load_balancer_create_timeout | Timeout value when creating the ALB. | string | `10m` | no | +| load_balancer_delete_timeout | Timeout value when deleting the ALB. | string | `10m` | no | +| load_balancer_type | The type of load balancer to create. Possible values are application or network. The default value is application. | string | `` | no | +| load_balancer_update_timeout | Timeout value when updating the ALB. | string | `10m` | no | +| log_bucket_name | S3 bucket (externally created) for storing load balancer access logs. Required if logging_enabled is true. | string | `` | no | +| managedby | ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'. | string | `anmol@clouddrove.com` | no | +| name | Name (e.g. `app` or `cluster`). | string | `` | no | +| security_groups | A list of security group IDs to assign to the LB. Only valid for Load Balancers of type application. | list | `` | no | +| status_code | The HTTP redirect code. The redirect is either permanent (HTTP_301) or temporary (HTTP_302). | string | `HTTP_301` | no | +| subnet_id | The id of the subnet of which to attach to the load balancer. You can specify only one subnet per Availability Zone. | string | `` | no | +| subnet_mapping | A list of subnet mapping blocks describing subnets to attach to network load balancer | list(map(string)) | `` | no | | subnets | A list of subnet IDs to attach to the LB. Subnets cannot be updated for Load Balancers of type network. Changing this value will for load balancers of type network will force a recreation of the resource. | list | `` | no | -| tags | Additional tags \(e.g. map\(`BusinessUnit`,`XYZ`\). | map | `` | no | -| target\_group\_port | The port on which targets receive traffic, unless overridden when registering a specific target. | string | `""` | no | -| target\_group\_protocol | The protocol to use for routing traffic to the targets. | string | `""` | no | -| target\_id | The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. | list | n/a | yes | -| target\_type | The type of target that you must specify when registering targets with this target group. The possible values are instance \(targets are specified by instance ID\) or ip \(targets are specified by IP address\) or lambda \(targets are specified by lambda arn\). The default is instance. | string | `"instance"` | no | -| vpc\_id | The identifier of the VPC in which to create the target group. | string | `""` | no | +| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | map | `` | no | +| target_group_port | The port on which targets receive traffic, unless overridden when registering a specific target. | string | `80` | no | +| target_groups | A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port. Optional key/values are in the target_groups_defaults variable. | any | `` | no | +| target_id | The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is ip, specify an IP address. | list | - | yes | +| vpc_id | The identifier of the VPC in which to create the target group. | string | `` | no | ## Outputs | Name | Description | |------|-------------| | arn | The ARN of the ALB. | -| arn\_suffix | The ARN suffix of the ALB. | -| dns\_name | DNS name of ALB. | -| http\_listener\_arn | The ARN of the HTTP listener. | -| https\_listener\_arn | The ARN of the HTTPS listener. | -| listener\_arns | A list of all the listener ARNs. | -| main\_target\_group\_arn | The main target group ARN. | +| arn_suffix | The ARN suffix of the ALB. | +| clb_arn | The ARN of the CLB. | +| clb_name | DNS name of CLB. | +| clb_zone_id | The ID of the zone which ALB is provisioned. | +| dns_name | DNS name of ALB. | +| http_listener_arn | The ARN of the HTTP listener. | +| https_listener_arn | The ARN of the HTTPS listener. | +| listener_arns | A list of all the listener ARNs. | +| main_target_group_arn | The main target group ARN. | | name | The ARN suffix of the ALB. | | tags | A mapping of tags to assign to the resource. | -| zone\_id | The ID of the zone which ALB is provisioned. | +| zone_id | The ID of the zone which ALB is provisioned. | diff --git a/README.yaml b/README.yaml index 0d7ce75..496f999 100644 --- a/README.yaml +++ b/README.yaml @@ -32,29 +32,135 @@ include: # How to use this project usage : |- - ### Simple Example - Here is an example of how you can use this module in your inventory structure: + Here are examples of how you can use this module in your inventory structure: + ### ALB Example ```hcl - module "alb" { - source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.5" - name = "alb" - application = "clouddrove" - environment = "test" - label_order = ["environment", "name", "application"] - internal = false - load_balancer_type = "application" - instance_count = 2 - security_groups = ["sg-xxxxxxx"] - subnets = "subnet-xxxxxxx" - enable_deletion_protection = false - target_id = "i-xxxxxxxxxx" - vpc_id = "vpc-xxxxxxxxx" - target_group_protocol = "HTTP" - target_group_port = 80 - listener_certificate_arn = "arn:aws:acm:eu-west-1:xxxxxxxxxxxx:certificate/xxxxxx-xxxx-xxxxx-xxxx" - https_enabled = true - http_enabled = true - https_port = 443 - listener_type = "forward" + module "alb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + name = "alb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + internal = false + 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 + enable_deletion_protection = false + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + https_enabled = true + http_enabled = true + https_port = 443 + listener_type = "forward" + listener_certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_port = 80 + target_groups = [ + { + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" + deregistration_delay = 300 + health_check = { + enabled = true + interval = 30 + path = "/" + port = "traffic-port" + healthy_threshold = 3 + unhealthy_threshold = 3 + timeout = 10 + protocol = "HTTP" + matcher = "200-399" + } + } + ] } - ``` \ No newline at end of file + ``` + + ### NLB Example + ```hcl + module "alb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + name = "nlb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + internal = false + load_balancer_type = "application" + instance_count = module.ec2.instance_count + subnets = module.public_subnets.public_subnet_id + enable_deletion_protection = false + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + http_tcp_listeners = [ + { + port = 80 + protocol = "TCP" + target_group_index = 0 + }, + ] + + https_listeners = [ + { + port = 443 + protocol = "TLS" + certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_index = 1 + }, + ] + + target_groups = [ + { + backend_protocol = "TCP" + backend_port = 80 + target_type = "instance" + }, + { + backend_protocol = "TLS" + backend_port = 443 + target_type = "instance" + }, + ] + } + ``` + + ### CLB Example + ```hcl + module "clb" { + source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.6" + + name = "clb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + load_balancer_type = "classic" + internal = false + 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 + + listeners = [ + { + 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 + } + ] + + health_check_target = "TCP:4444" + health_check_timeout = 10 + 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 new file mode 100644 index 0000000..8c8976b --- /dev/null +++ b/_example/alb/example.tf @@ -0,0 +1,170 @@ +provider "aws" { + region = "eu-west-1" +} + +module "vpc" { + source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.12.5" + + name = "vpc" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + cidr_block = "172.16.0.0/16" +} + +module "public_subnets" { + source = "git::https://github.com/clouddrove/terraform-aws-subnet.git?ref=tags/0.12.6" + + name = "public-subnet" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + availability_zones = ["eu-west-1b", "eu-west-1c"] + vpc_id = module.vpc.vpc_id + cidr_block = module.vpc.vpc_cidr_block + type = "public" + igw_id = module.vpc.igw_id +} + +module "http_https" { + source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.4" + + name = "http-https" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + vpc_id = module.vpc.vpc_id + allowed_ip = ["0.0.0.0/0"] + allowed_ports = [80, 443] +} + +module "ssh" { + source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.4" + + name = "ssh" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + vpc_id = module.vpc.vpc_id + allowed_ip = [module.vpc.vpc_cidr_block] + allowed_ports = [22] +} + +module "iam-role" { + source = "git::https://github.com/clouddrove/terraform-aws-iam-role.git?ref=tags/0.12.3" + + name = "iam-role" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + assume_role_policy = data.aws_iam_policy_document.default.json + + policy_enabled = true + policy = data.aws_iam_policy_document.iam-policy.json +} + +data "aws_iam_policy_document" "default" { + statement { + effect = "Allow" + actions = ["sts:AssumeRole"] + principals { + type = "Service" + identifiers = ["ec2.amazonaws.com"] + } + } +} + +data "aws_iam_policy_document" "iam-policy" { + statement { + actions = [ + "ssm:UpdateInstanceInformation", + "ssmmessages:CreateControlChannel", + "ssmmessages:CreateDataChannel", + "ssmmessages:OpenControlChannel", + "ssmmessages:OpenDataChannel"] + effect = "Allow" + resources = ["*"] + } +} + +module "ec2" { + source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.4" + + name = "ec2-instance" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + instance_count = 2 + ami = "ami-08d658f84a6d84a80" + instance_type = "t2.nano" + monitoring = false + tenancy = "default" + + vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http_https.security_group_ids] + subnet_ids = tolist(module.public_subnets.public_subnet_id) + + assign_eip_address = true + associate_public_ip_address = true + + instance_profile_enabled = true + iam_instance_profile = module.iam-role.name + + disk_size = 8 + ebs_optimized = false + ebs_volume_enabled = true + ebs_volume_type = "gp2" + ebs_volume_size = 30 +} + + +module "alb" { + source = "./../../" + + name = "alb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + enable = true + internal = false + 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 + enable_deletion_protection = false + + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + + https_enabled = true + http_enabled = true + https_port = 443 + listener_type = "forward" + listener_certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_port = 80 + + target_groups = [ + { + backend_protocol = "HTTP" + backend_port = 80 + target_type = "instance" + deregistration_delay = 300 + health_check = { + enabled = true + interval = 30 + path = "/" + port = "traffic-port" + healthy_threshold = 3 + unhealthy_threshold = 3 + timeout = 10 + protocol = "HTTP" + matcher = "200-399" + } + } + ] +} diff --git a/_example/outputs.tf b/_example/alb/outputs.tf similarity index 100% rename from _example/outputs.tf rename to _example/alb/outputs.tf diff --git a/_example/clb/example.tf b/_example/clb/example.tf new file mode 100644 index 0000000..68c95ff --- /dev/null +++ b/_example/clb/example.tf @@ -0,0 +1,161 @@ +provider "aws" { + region = "eu-west-1" +} + +module "vpc" { + source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.12.5" + + name = "vpc" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + cidr_block = "172.16.0.0/16" +} + +module "public_subnets" { + source = "git::https://github.com/clouddrove/terraform-aws-subnet.git?ref=tags/0.12.6" + + name = "public-subnet" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + availability_zones = ["eu-west-1b", "eu-west-1c"] + vpc_id = module.vpc.vpc_id + cidr_block = module.vpc.vpc_cidr_block + type = "public" + igw_id = module.vpc.igw_id +} + +module "http_https" { + source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.4" + + name = "http-https" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + vpc_id = module.vpc.vpc_id + allowed_ip = ["0.0.0.0/0"] + allowed_ports = [80, 443] +} + +module "ssh" { + source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.12.4" + + name = "ssh" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + vpc_id = module.vpc.vpc_id + allowed_ip = [module.vpc.vpc_cidr_block] + allowed_ports = [22] +} + +module "iam-role" { + source = "git::https://github.com/clouddrove/terraform-aws-iam-role.git?ref=tags/0.12.3" + + name = "iam-role" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + assume_role_policy = data.aws_iam_policy_document.default.json + + policy_enabled = true + policy = data.aws_iam_policy_document.iam-policy.json +} + +data "aws_iam_policy_document" "default" { + statement { + effect = "Allow" + actions = ["sts:AssumeRole"] + principals { + type = "Service" + identifiers = ["ec2.amazonaws.com"] + } + } +} + +data "aws_iam_policy_document" "iam-policy" { + statement { + actions = [ + "ssm:UpdateInstanceInformation", + "ssmmessages:CreateControlChannel", + "ssmmessages:CreateDataChannel", + "ssmmessages:OpenControlChannel", + "ssmmessages:OpenDataChannel"] + effect = "Allow" + resources = ["*"] + } +} + +module "ec2" { + source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.4" + + name = "ec2-instance" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + instance_count = 2 + ami = "ami-08d658f84a6d84a80" + instance_type = "t2.nano" + monitoring = false + tenancy = "default" + + vpc_security_group_ids_list = [module.ssh.security_group_ids, module.http_https.security_group_ids] + subnet_ids = tolist(module.public_subnets.public_subnet_id) + + assign_eip_address = true + associate_public_ip_address = true + + instance_profile_enabled = true + iam_instance_profile = module.iam-role.name + + disk_size = 8 + ebs_optimized = false + ebs_volume_enabled = true + ebs_volume_type = "gp2" + ebs_volume_size = 30 +} + +module "clb" { + source = "./../../" + + name = "clb" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + + load_balancer_type = "classic" + clb_enable = true + internal = false + 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 + + listeners = [ + { + 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 + } + ] + + health_check_target = "TCP:4444" + health_check_timeout = 10 + health_check_interval = 30 + health_check_unhealthy_threshold = 5 + health_check_healthy_threshold = 5 +} \ No newline at end of file diff --git a/_example/clb/outputs.tf b/_example/clb/outputs.tf new file mode 100644 index 0000000..728f04c --- /dev/null +++ b/_example/clb/outputs.tf @@ -0,0 +1,9 @@ +output "arn" { + value = module.clb.*.clb_arn + description = "The ARN suffix of the ALB" +} + +output "tags" { + value = module.clb.tags + description = "A mapping of tags to assign to the alb." +} \ No newline at end of file diff --git a/_example/example.tf b/_example/nlb/example.tf similarity index 77% rename from _example/example.tf rename to _example/nlb/example.tf index 933b0dc..51c13a5 100644 --- a/_example/example.tf +++ b/_example/nlb/example.tf @@ -2,7 +2,6 @@ provider "aws" { region = "eu-west-1" } - module "vpc" { source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.12.4" @@ -95,12 +94,11 @@ data "aws_iam_policy_document" "iam-policy" { module "ec2" { source = "git::https://github.com/clouddrove/terraform-aws-ec2.git?ref=tags/0.12.4" - name = "ec2-instance" - application = "clouddrove" - environment = "test" - label_order = ["environment", "application", "name"] - - instance_count = 2 + name = "ec2-instance" + application = "clouddrove" + environment = "test" + label_order = ["environment", "application", "name"] + instance_count = 1 ami = "ami-08d658f84a6d84a80" instance_type = "t2.nano" monitoring = false @@ -123,29 +121,52 @@ module "ec2" { } -module "alb" { - source = "./../" +module "nlb" { + source = "./../../" - name = "alb" + name = "nlb" application = "clouddrove" environment = "test" label_order = ["environment", "application", "name"] + enable = true internal = false - load_balancer_type = "application" + load_balancer_type = "network" 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 enable_deletion_protection = false - target_id = module.ec2.instance_id - vpc_id = module.vpc.vpc_id - target_group_protocol = "HTTP" - target_group_port = 80 - - https_enabled = false - http_enabled = true - https_port = 443 - listener_type = "forward" - + target_id = module.ec2.instance_id + vpc_id = module.vpc.vpc_id + + http_tcp_listeners = [ + { + port = 80 + protocol = "TCP" + target_group_index = 0 + }, + ] + + // TLS + https_listeners = [ + { + port = 443 + protocol = "TLS" + certificate_arn = "arn:aws:acm:eu-west-1:924144197303:certificate/0418d2ba-91f7-4196-991b-28b5c60cd4cf" + target_group_index = 1 + }, + ] + + target_groups = [ + { + backend_protocol = "TCP" + backend_port = 80 + target_type = "instance" + }, + { + backend_protocol = "TLS" + backend_port = 443 + target_type = "instance" + }, + ] } \ No newline at end of file diff --git a/_example/nlb/outputs.tf b/_example/nlb/outputs.tf new file mode 100644 index 0000000..989c39b --- /dev/null +++ b/_example/nlb/outputs.tf @@ -0,0 +1,9 @@ +output "arn" { + value = module.nlb.*.arn + description = "The ARN suffix of the ALB" +} + +output "tags" { + value = module.nlb.tags + description = "A mapping of tags to assign to the alb." +} \ No newline at end of file diff --git a/_test/alb_test.go b/_test/alb/alb_test.go similarity index 96% rename from _test/alb_test.go rename to _test/alb/alb_test.go index bd39b75..7e1b5a9 100644 --- a/_test/alb_test.go +++ b/_test/alb/alb_test.go @@ -15,7 +15,7 @@ func Test(t *testing.T) { terraformOptions := &terraform.Options{ // Source path of Terraform directory. - TerraformDir: "../_example", + TerraformDir: "../../_example/alb", } // This will run 'terraform init' and 'terraform application' and will fail the test if any errors occur diff --git a/_test/clb/clb_test.go b/_test/clb/clb_test.go new file mode 100644 index 0000000..5351f0a --- /dev/null +++ b/_test/clb/clb_test.go @@ -0,0 +1,34 @@ +// Managed By : CloudDrove +// Description : This Terratest is used to test the Terraform VPC module. +// Copyright @ CloudDrove. All Right Reserved. +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func Test(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + // Source path of Terraform directory. + TerraformDir: "../../_example/clb", + } + + // This will run 'terraform init' and 'terraform application' and will fail the test if any errors occur + terraform.InitAndApply(t, terraformOptions) + + // To clean up any resources that have been created, run 'terraform destroy' towards the end of the test + defer terraform.Destroy(t, terraformOptions) + + // To get the value of an output variable, run 'terraform output' + Arn := terraform.Output(t, terraformOptions, "arn") + Tags := terraform.OutputMap(t, terraformOptions, "tags") + + // Check that we get back the outputs that we expect + assert.Equal(t, "test-clouddrove-clb", Tags["Name"]) + assert.Contains(t, Arn, "arn:aws:elasticloadbalancing") +} \ No newline at end of file diff --git a/_test/nlb/alb_test.go b/_test/nlb/alb_test.go new file mode 100644 index 0000000..1cd833b --- /dev/null +++ b/_test/nlb/alb_test.go @@ -0,0 +1,34 @@ +// Managed By : CloudDrove +// Description : This Terratest is used to test the Terraform VPC module. +// Copyright @ CloudDrove. All Right Reserved. +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +func Test(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + // Source path of Terraform directory. + TerraformDir: "../../_example/nlb", + } + + // This will run 'terraform init' and 'terraform application' and will fail the test if any errors occur + terraform.InitAndApply(t, terraformOptions) + + // To clean up any resources that have been created, run 'terraform destroy' towards the end of the test + defer terraform.Destroy(t, terraformOptions) + + // To get the value of an output variable, run 'terraform output' + Arn := terraform.Output(t, terraformOptions, "arn") + Tags := terraform.OutputMap(t, terraformOptions, "tags") + + // Check that we get back the outputs that we expect + assert.Equal(t, "test-clouddrove-nlb", Tags["Name"]) + assert.Contains(t, Arn, "arn:aws:elasticloadbalancing") +} \ No newline at end of file diff --git a/main.tf b/main.tf index 47650ca..c27039c 100644 --- a/main.tf +++ b/main.tf @@ -24,6 +24,7 @@ resource "aws_lb" "main" { internal = var.internal load_balancer_type = var.load_balancer_type security_groups = var.security_groups + drop_invalid_header_fields = var.drop_invalid_header_fields subnets = var.subnets enable_deletion_protection = var.enable_deletion_protection idle_timeout = var.idle_timeout @@ -42,12 +43,20 @@ resource "aws_lb" "main" { bucket = var.log_bucket_name prefix = module.labels.id } + dynamic "subnet_mapping" { + for_each = var.subnet_mapping + + content { + subnet_id = subnet_mapping.value.subnet_id + allocation_id = lookup(subnet_mapping.value, "allocation_id", null) + } + } } # Module : LOAD BALANCER LISTENER HTTPS # Description : Provides a Load Balancer Listener resource. resource "aws_lb_listener" "https" { - count = var.enable == true && var.https_enabled == true ? 1 : 0 + count = var.enable == true && var.https_enabled == true && var.load_balancer_type == "application" ? 1 : 0 load_balancer_arn = element(aws_lb.main.*.arn, count.index) port = var.https_port @@ -63,7 +72,7 @@ resource "aws_lb_listener" "https" { # Module : LOAD BALANCER LISTENER HTTP # Description : Provides a Load Balancer Listener resource. resource "aws_lb_listener" "http" { - count = var.enable == true && var.http_enabled == true ? 1 : 0 + count = var.enable == true && var.http_enabled == true && var.load_balancer_type == "application" ? 1 : 0 load_balancer_arn = element(aws_lb.main.*.arn, count.index) port = var.http_port @@ -79,23 +88,73 @@ resource "aws_lb_listener" "http" { } } +# Module : LOAD BALANCER LISTENER HTTPS +# Description : Provides a Load Balancer Listener resource. +resource "aws_lb_listener" "nhttps" { + count = var.enable == true && var.https_enabled == true && var.load_balancer_type == "network" ? length(var.https_listeners) : 0 + + load_balancer_arn = element(aws_lb.main.*.arn, count.index) + port = var.https_listeners[count.index]["port"] + protocol = lookup(var.https_listeners[count.index], "protocol", "HTTPS") + certificate_arn = var.https_listeners[count.index]["certificate_arn"] + ssl_policy = lookup(var.https_listeners[count.index], "ssl_policy", var.listener_ssl_policy) + default_action { + target_group_arn = aws_lb_target_group.main[lookup(var.https_listeners[count.index], "target_group_index", count.index)].id + type = "forward" + } +} + +# Module : LOAD BALANCER LISTENER HTTP +# Description : Provides a Load Balancer Listener resource. +resource "aws_lb_listener" "nhttp" { + count = var.enable == true && var.load_balancer_type == "network" ? length(var.http_tcp_listeners) : 0 + + load_balancer_arn = element(aws_lb.main.*.arn, 0) + port = var.http_tcp_listeners[count.index]["port"] + protocol = var.http_tcp_listeners[count.index]["protocol"] + default_action { + target_group_arn = aws_lb_target_group.main[lookup(var.http_tcp_listeners[count.index], "target_group_index", count.index)].id + type = "forward" + } +} + # Module : LOAD BALANCER TARGET GROUP # Description : Provides a Target Group resource for use with Load Balancer resources. resource "aws_lb_target_group" "main" { - count = var.enable ? 1 : 0 - name = module.labels.id - port = var.target_group_port - protocol = var.target_group_protocol - vpc_id = var.vpc_id - target_type = var.target_type - deregistration_delay = var.deregistration_delay - health_check { - path = var.health_check_path - timeout = var.health_check_timeout - healthy_threshold = var.health_check_healthy_threshold - unhealthy_threshold = var.health_check_unhealthy_threshold - interval = var.health_check_interval - matcher = var.health_check_matcher + count = var.enable ? length(var.target_groups) : 0 + name = format("%s-%s", module.labels.id, count.index) + port = lookup(var.target_groups[count.index], "backend_port", null) + protocol = lookup(var.target_groups[count.index], "backend_protocol", null) != null ? upper(lookup(var.target_groups[count.index], "backend_protocol")) : null + vpc_id = var.vpc_id + target_type = lookup(var.target_groups[count.index], "target_type", null) + deregistration_delay = lookup(var.target_groups[count.index], "deregistration_delay", null) + slow_start = lookup(var.target_groups[count.index], "slow_start", null) + proxy_protocol_v2 = lookup(var.target_groups[count.index], "proxy_protocol_v2", null) + lambda_multi_value_headers_enabled = lookup(var.target_groups[count.index], "lambda_multi_value_headers_enabled", null) + dynamic "health_check" { + for_each = length(keys(lookup(var.target_groups[count.index], "health_check", {}))) == 0 ? [] : [lookup(var.target_groups[count.index], "health_check", {})] + + content { + enabled = lookup(health_check.value, "enabled", null) + interval = lookup(health_check.value, "interval", null) + path = lookup(health_check.value, "path", null) + port = lookup(health_check.value, "port", null) + healthy_threshold = lookup(health_check.value, "healthy_threshold", null) + unhealthy_threshold = lookup(health_check.value, "unhealthy_threshold", null) + timeout = lookup(health_check.value, "timeout", null) + protocol = lookup(health_check.value, "protocol", null) + matcher = lookup(health_check.value, "matcher", null) + } + } + + dynamic "stickiness" { + for_each = length(keys(lookup(var.target_groups[count.index], "stickiness", {}))) == 0 ? [] : [lookup(var.target_groups[count.index], "stickiness", {})] + + content { + enabled = lookup(stickiness.value, "enabled", null) + cookie_duration = lookup(stickiness.value, "cookie_duration", null) + type = lookup(stickiness.value, "type", null) + } } } @@ -103,10 +162,55 @@ resource "aws_lb_target_group" "main" { # Description : Provides the ability to register instances and containers with an # Application Load Balancer (ALB) or Network Load Balancer (NLB) target group. resource "aws_lb_target_group_attachment" "attachment" { - count = var.enable ? var.instance_count : 0 + count = var.enable && var.load_balancer_type == "application" ? var.instance_count : 0 target_group_arn = element(aws_lb_target_group.main.*.arn, count.index) target_id = element(var.target_id, count.index) port = var.target_group_port } +resource "aws_lb_target_group_attachment" "nattachment" { + count = var.enable && var.load_balancer_type == "network" ? length(var.https_listeners) : 0 + + target_group_arn = element(aws_lb_target_group.main.*.arn, count.index) + target_id = element(var.target_id, 0) + port = lookup(var.target_groups[count.index], "backend_port", null) +} + + +# Module : Classic LOAD BALANCER +# Description : This terraform module is used to create classic Load Balancer on AWS. +resource "aws_elb" "main" { + count = var.clb_enable && var.load_balancer_type == "classic" == true ? 1 : 0 + + name = module.labels.id + instances = var.target_id + internal = var.internal + cross_zone_load_balancing = var.enable_cross_zone_load_balancing + idle_timeout = var.idle_timeout + connection_draining = var.connection_draining + connection_draining_timeout = var.connection_draining_timeout + security_groups = var.security_groups + subnets = var.subnets + + dynamic "listener" { + for_each = var.listeners + content { + instance_port = listener.value.instance_port + instance_protocol = listener.value.instance_protocol + lb_port = listener.value.lb_port + lb_protocol = listener.value.lb_protocol + ssl_certificate_id = listener.value.ssl_certificate_id + } + } + + health_check { + target = var.health_check_target + timeout = var.health_check_timeout + interval = var.health_check_interval + unhealthy_threshold = var.health_check_unhealthy_threshold + healthy_threshold = var.health_check_healthy_threshold + } + + tags = module.labels.tags +} diff --git a/outputs.tf b/outputs.tf index cafefbf..90f6d4d 100644 --- a/outputs.tf +++ b/outputs.tf @@ -10,6 +10,10 @@ output "arn" { description = "The ARN of the ALB." } +output "clb_arn" { + value = join("", concat(aws_elb.main.*.arn)) + description = "The ARN of the CLB." +} output "arn_suffix" { value = join("", aws_lb.main.*.arn_suffix) description = "The ARN suffix of the ALB." @@ -20,11 +24,19 @@ output "dns_name" { description = "DNS name of ALB." } +output "clb_name" { + value = join("", aws_elb.main.*.dns_name) + description = "DNS name of CLB." +} output "zone_id" { value = join("", aws_lb.main.*.zone_id) description = "The ID of the zone which ALB is provisioned." } +output "clb_zone_id" { + value = join("", aws_elb.main.*.zone_id) + description = "The ID of the zone which ALB is provisioned." +} output "main_target_group_arn" { value = join("", aws_lb_target_group.main.*.arn) description = "The main target group ARN." diff --git a/variables.tf b/variables.tf index d052fcc..9a7d4ae 100644 --- a/variables.tf +++ b/variables.tf @@ -50,11 +50,6 @@ variable "managedby" { # Module : ALB # Description : Terraform ALB module variables. -variable "alb_name" { - type = string - default = "" - description = "The name of the LB. This name must be unique within your AWS account, can have a maximum of 32 characters, must contain only alphanumeric characters or hyphens, and must not begin or end with a hyphen. If not specified, Terraform will autogenerate a name beginning with tf-lb." -} variable "instance_count" { type = number @@ -74,6 +69,36 @@ variable "load_balancer_type" { description = "The type of load balancer to create. Possible values are application or network. The default value is application." } +variable "drop_invalid_header_fields" { + type = bool + default = false + description = "Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (true) or routed to targets (false). The default is false. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. Only valid for Load Balancers of type application." +} + +variable "subnet_mapping" { + default = [] + type = list(map(string)) + description = "A list of subnet mapping blocks describing subnets to attach to network load balancer" +} + +variable "https_listeners" { + description = "A list of maps describing the HTTPS listeners for this ALB. Required key/values: port, certificate_arn. Optional key/values: ssl_policy (defaults to ELBSecurityPolicy-2016-08), target_group_index (defaults to 0)" + type = list(map(string)) + default = [] +} + +variable "http_tcp_listeners" { + description = "A list of maps describing the HTTP listeners for this ALB. Required key/values: port, protocol. Optional key/values: target_group_index (defaults to 0)" + type = list(map(string)) + default = [] +} + +variable "target_groups" { + description = "A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port. Optional key/values are in the target_groups_defaults variable." + type = any + default = [] +} + variable "security_groups" { type = list default = [] @@ -87,8 +112,8 @@ variable "subnets" { } variable "enable_deletion_protection" { - type = string - default = "" + type = bool + default = false description = "If true, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to false." } @@ -104,14 +129,9 @@ variable "allocation_id" { description = "The allocation ID of the Elastic IP address." } -variable "alb_environment" { - type = string - default = "" - description = "A mapping of tags to assign to the resource." -} - variable "https_port" { type = number + default = 443 description = "The port on which the load balancer is listening. like 80 or 443." } @@ -141,6 +161,7 @@ variable "http_enabled" { variable "listener_type" { type = string + default = "forward" description = "The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc." } @@ -158,16 +179,10 @@ variable "listener_certificate_arn" { variable "target_group_port" { type = string - default = "" + default = 80 description = "The port on which targets receive traffic, unless overridden when registering a specific target." } -variable "target_group_protocol" { - type = string - default = "" - description = "The protocol to use for routing traffic to the targets." -} - variable "vpc_id" { type = string default = "" @@ -233,68 +248,92 @@ variable "access_logs" { description = "Access logs Enable or Disable." } -variable "target_type" { +variable "http_listener_type" { type = string - default = "instance" - description = "The type of target that you must specify when registering targets with this target group. The possible values are instance (targets are specified by instance ID) or ip (targets are specified by IP address) or lambda (targets are specified by lambda arn). The default is instance." + default = "redirect" + description = "The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc." } -variable "deregistration_delay" { - type = number - default = 300 - description = "The amount time for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused. The range is 0-3600 seconds. The default value is 300 seconds." +variable "status_code" { + type = string + default = "HTTP_301" + description = " The HTTP redirect code. The redirect is either permanent (HTTP_301) or temporary (HTTP_302)." } -variable "health_check_path" { - type = string - default = "/" - description = "The destination for the health check request." +variable "enable" { + type = bool + default = false + description = "If true, create alb." } -variable "health_check_timeout" { - type = number - default = 10 - description = "The amount of time to wait in seconds before failing a health check request." +variable "clb_enable" { + type = bool + default = false + description = "If true, create clb." } -variable "health_check_healthy_threshold" { - type = number - default = 2 - description = "The number of consecutive health checks successes required before considering an unhealthy target healthy." +variable "listeners" { + default = [] + type = list(object({ + lb_port : number + lb_protocol : string + instance_port : number + instance_protocol : string + ssl_certificate_id : string + })) + description = "A list of listener configurations for the ELB." } -variable "health_check_unhealthy_threshold" { - type = number - default = 2 - description = "The number of consecutive health check failures required before considering the target unhealthy." +variable "enable_connection_draining" { + type = bool + default = false + description = "Whether or not to enable connection draining (\"true\" or \"false\")." } -variable "health_check_interval" { +variable "connection_draining_timeout" { type = number - default = 15 - description = "The duration in seconds in between health checks." + default = 300 + description = "The time after which connection draining is aborted in seconds." } -variable "health_check_matcher" { - type = string - default = "200-399" - description = "The HTTP response codes to indicate a healthy check." +variable "connection_draining" { + type = bool + default = false + description = "TBoolean to enable connection draining. Default: false." } -variable "http_listener_type" { - type = string - default = "redirect" - description = "The type of routing action. Valid values are forward, redirect, fixed-response, authenticate-cognito and authenticate-oidc." +variable "availability_zones" { + default = [] + type = list(map(string)) + description = "The AZ's to serve traffic in." } -variable "status_code" { +variable "health_check_target" { + description = "The target to use for health checks." type = string - default = "HTTP_301" - description = " The HTTP redirect code. The redirect is either permanent (HTTP_301) or temporary (HTTP_302)." + default = "TCP:80" } -variable "enable" { - type = bool - default = true - description = "If true, create alb." +variable "health_check_timeout" { + type = number + default = 5 + description = "The time after which a health check is considered failed in seconds." +} + +variable "health_check_interval" { + description = "The time between health check attempts in seconds." + type = number + default = 30 +} + +variable "health_check_unhealthy_threshold" { + type = number + default = 2 + description = "The number of failed health checks before an instance is taken out of service." +} + +variable "health_check_healthy_threshold" { + type = number + default = 10 + description = "The number of successful health checks before an instance is put into service." } \ No newline at end of file