Skip to content

Commit

Permalink
Merge pull request #2 from clouddrove/TF-6
Browse files Browse the repository at this point in the history
Tf 6
  • Loading branch information
anmolnagpal committed Jan 25, 2020
2 parents 5e82e79 + 7215644 commit fb6b409
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 97 deletions.
166 changes: 83 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Terraform AWS ALB
</h1>

<p align="center" style="font-size: 1.2rem;">
<p align="center" style="font-size: 1.2rem;">
This terraform module is used to create ALB on AWS.
</p>

Expand Down Expand Up @@ -38,7 +38,7 @@
<hr>


We eat, drink, sleep and most importantly love **DevOps**. We are working towards stratergies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.
We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy <b>Bigger problems are always solved by breaking them into smaller manageable problems</b>. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller <b>connected yet manageable pieces</b> within the infrastructure.

This module is basically combination of [Terraform open source](https://www.terraform.io/) and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself.

Expand All @@ -49,7 +49,7 @@ We have [*fifty plus terraform modules*][terraform_modules]. A few of them are c

## Prerequisites

This module has a few dependencies:
This module has a few dependencies:

- [Terraform 0.12](https://learn.hashicorp.com/terraform/getting-started/install.html)
- [Go](https://golang.org/doc/install)
Expand All @@ -71,29 +71,28 @@ This module has a few dependencies:
### Simple Example
Here is an example of how you can use this module in your inventory structure:
```hcl
module "alb" {
source = "git::https://github.com/clouddrove/terraform-aws-alb.git?ref=tags/0.12.3"
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.3"
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"
}
```


Expand All @@ -105,75 +104,76 @@ 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 | `<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_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 | - | 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 | `<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 | - | 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 |
| 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 | `<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 |
| 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 | `<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 | `<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 |
| 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 | `<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 |
| 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 | `<list>` | no |
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`). | map | `<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 | - | 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 | `<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 |

## 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. |
| 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. |




## Testing
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.
In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system.

You need to run the following command in the testing folder:
```hcl
Expand All @@ -182,7 +182,7 @@ You need to run the following command in the testing folder:



## Feedback
## Feedback
If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-alb/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com).

If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-alb)!
Expand All @@ -200,4 +200,4 @@ At [CloudDrove][website], we offer expert guidance, implementation support and s
[linkedin]: https://cpco.io/linkedin
[twitter]: https://twitter.com/clouddrove/
[email]: https://clouddrove.com/contact-us.html
[terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language=
[terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language=
Loading

0 comments on commit fb6b409

Please sign in to comment.