From 71d0ffc8f5ec5e56fa52a8dcbfbe6773174e9c68 Mon Sep 17 00:00:00 2001 From: Ryan Atkinson Date: Fri, 19 Jun 2020 13:09:59 -0700 Subject: [PATCH] feat: Added variable to enable/disable module (#23) --- .pre-commit-config.yaml | 18 ++++++------- README.md | 41 ++++++++++++++++++----------- examples/complete/README.md | 17 +++++++++--- main.tf | 4 +++ modules/elb/README.md | 39 +++++++++++++++++---------- modules/elb/main.tf | 2 ++ modules/elb/variables.tf | 6 +++++ modules/elb_attachment/README.md | 23 +++++++++++++--- modules/elb_attachment/main.tf | 2 +- modules/elb_attachment/variables.tf | 6 +++++ variables.tf | 6 +++++ 11 files changed, 117 insertions(+), 47 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0285452..656323b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.27.0 - hooks: - - id: terraform_fmt - - id: terraform_docs - - repo: git://github.com/pre-commit/pre-commit-hooks - rev: v2.5.0 - hooks: - - id: check-merge-conflict +- repo: git://github.com/antonbabenko/pre-commit-terraform + rev: v1.31.0 + hooks: + - id: terraform_fmt + - id: terraform_docs +- repo: git://github.com/pre-commit/pre-commit-hooks + rev: v3.1.0 + hooks: + - id: check-merge-conflict diff --git a/README.md b/README.md index 30059f3..5ad3a27 100644 --- a/README.md +++ b/README.md @@ -79,25 +79,34 @@ module "elb_http" { * Valid SSL certificate has to be specified as `ssl_certificate_id` argument for secure listener. Use [terraform-aws-acm module](https://github.com/terraform-aws-modules/terraform-aws-acm) to create one. See [ELB example](https://github.com/terraform-aws-modules/terraform-aws-elb/blob/master/examples/complete/main.tf) for details. +## Requirements + +No requirements. + +## Providers + +No provider. + ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| access\_logs | An access logs block | map(string) | `{}` | no | -| connection\_draining | Boolean to enable connection draining | bool | `"false"` | no | -| connection\_draining\_timeout | The time in seconds to allow for connections to drain | number | `"300"` | no | -| cross\_zone\_load\_balancing | Enable cross-zone load balancing | bool | `"true"` | no | -| health\_check | A health check block | map(string) | n/a | yes | -| idle\_timeout | The time in seconds that the connection is allowed to be idle | number | `"60"` | no | -| instances | List of instances ID to place in the ELB pool | list(string) | `[]` | no | -| internal | If true, ELB will be an internal ELB | bool | `"false"` | no | -| listener | A list of listener blocks | list(map(string)) | n/a | yes | -| name | The name of the ELB | string | `"null"` | no | -| name\_prefix | The prefix name of the ELB | string | `"null"` | no | -| number\_of\_instances | Number of instances to attach to ELB | number | `"0"` | no | -| security\_groups | A list of security group IDs to assign to the ELB | list(string) | n/a | yes | -| subnets | A list of subnet IDs to attach to the ELB | list(string) | n/a | yes | -| tags | A mapping of tags to assign to the resource | map(string) | `{}` | no | +|------|-------------|------|---------|:--------:| +| access\_logs | An access logs block | `map(string)` | `{}` | no | +| connection\_draining | Boolean to enable connection draining | `bool` | `false` | no | +| connection\_draining\_timeout | The time in seconds to allow for connections to drain | `number` | `300` | no | +| create\_elb | Create the elb or not | `bool` | `true` | no | +| cross\_zone\_load\_balancing | Enable cross-zone load balancing | `bool` | `true` | no | +| health\_check | A health check block | `map(string)` | n/a | yes | +| idle\_timeout | The time in seconds that the connection is allowed to be idle | `number` | `60` | no | +| instances | List of instances ID to place in the ELB pool | `list(string)` | `[]` | no | +| internal | If true, ELB will be an internal ELB | `bool` | `false` | no | +| listener | A list of listener blocks | `list(map(string))` | n/a | yes | +| name | The name of the ELB | `string` | `null` | no | +| name\_prefix | The prefix name of the ELB | `string` | `null` | no | +| number\_of\_instances | Number of instances to attach to ELB | `number` | `0` | no | +| security\_groups | A list of security group IDs to assign to the ELB | `list(string)` | n/a | yes | +| subnets | A list of subnet IDs to attach to the ELB | `list(string)` | n/a | yes | +| tags | A mapping of tags to assign to the resource | `map(string)` | `{}` | no | ## Outputs diff --git a/examples/complete/README.md b/examples/complete/README.md index 676f9f6..99c65e8 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -19,11 +19,22 @@ $ terraform apply Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | +| random | n/a | + ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| number\_of\_instances | Number of instances to create and attach to ELB | string | `"1"` | no | +|------|-------------|------|---------|:--------:| +| number\_of\_instances | Number of instances to create and attach to ELB | `number` | `1` | no | ## Outputs @@ -31,7 +42,7 @@ Note that this example may create resources which cost money. Run `terraform des |------|-------------| | this\_elb\_dns\_name | The DNS name of the ELB | | this\_elb\_id | The name of the ELB | -| this\_elb\_instances | The list of instances in the ELB (if may be outdated, because instances are attached using elb_attachment resource) | +| this\_elb\_instances | The list of instances in the ELB (if may be outdated, because instances are attached using elb\_attachment resource) | | this\_elb\_name | The name of the ELB | | this\_elb\_source\_security\_group\_id | The ID of the security group that you can use as part of your inbound rules for your load balancer's back-end application instances | | this\_elb\_zone\_id | The canonical hosted zone ID of the ELB (to be used in a Route 53 Alias record) | diff --git a/main.tf b/main.tf index 78a3c6f..3c8d88f 100644 --- a/main.tf +++ b/main.tf @@ -4,6 +4,8 @@ module "elb" { source = "./modules/elb" + create_elb = var.create_elb + name = var.name name_prefix = var.name_prefix @@ -34,6 +36,8 @@ module "elb" { module "elb_attachment" { source = "./modules/elb_attachment" + create_attachment = var.create_elb + number_of_instances = var.number_of_instances elb = module.elb.this_elb_id diff --git a/modules/elb/README.md b/modules/elb/README.md index 214287e..d70a2d9 100644 --- a/modules/elb/README.md +++ b/modules/elb/README.md @@ -1,23 +1,34 @@ # aws_elb +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | + ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| access\_logs | An access logs block | map(string) | `{}` | no | -| connection\_draining | Boolean to enable connection draining | bool | `"false"` | no | -| connection\_draining\_timeout | The time in seconds to allow for connections to drain | number | `"300"` | no | -| cross\_zone\_load\_balancing | Enable cross-zone load balancing | bool | `"true"` | no | -| health\_check | A health check block | map(string) | n/a | yes | -| idle\_timeout | The time in seconds that the connection is allowed to be idle | number | `"60"` | no | -| internal | If true, ELB will be an internal ELB | bool | n/a | yes | -| listener | A list of listener blocks | list(map(string)) | n/a | yes | -| name | The name of the ELB | string | `"null"` | no | -| name\_prefix | The prefix name of the ELB | string | `"null"` | no | -| security\_groups | A list of security group IDs to assign to the ELB | list(string) | n/a | yes | -| subnets | A list of subnet IDs to attach to the ELB | list(string) | n/a | yes | -| tags | A mapping of tags to assign to the resource | map(string) | `{}` | no | +|------|-------------|------|---------|:--------:| +| access\_logs | An access logs block | `map(string)` | `{}` | no | +| connection\_draining | Boolean to enable connection draining | `bool` | `false` | no | +| connection\_draining\_timeout | The time in seconds to allow for connections to drain | `number` | `300` | no | +| create\_elb | Create the elb or not | `bool` | `true` | no | +| cross\_zone\_load\_balancing | Enable cross-zone load balancing | `bool` | `true` | no | +| health\_check | A health check block | `map(string)` | n/a | yes | +| idle\_timeout | The time in seconds that the connection is allowed to be idle | `number` | `60` | no | +| internal | If true, ELB will be an internal ELB | `bool` | n/a | yes | +| listener | A list of listener blocks | `list(map(string))` | n/a | yes | +| name | The name of the ELB | `string` | `null` | no | +| name\_prefix | The prefix name of the ELB | `string` | `null` | no | +| security\_groups | A list of security group IDs to assign to the ELB | `list(string)` | n/a | yes | +| subnets | A list of subnet IDs to attach to the ELB | `list(string)` | n/a | yes | +| tags | A mapping of tags to assign to the resource | `map(string)` | `{}` | no | ## Outputs diff --git a/modules/elb/main.tf b/modules/elb/main.tf index 344b500..e2bad80 100644 --- a/modules/elb/main.tf +++ b/modules/elb/main.tf @@ -1,4 +1,6 @@ resource "aws_elb" "this" { + count = var.create_elb ? 1 : 0 + name = var.name name_prefix = var.name_prefix diff --git a/modules/elb/variables.tf b/modules/elb/variables.tf index c80374b..a5481e6 100644 --- a/modules/elb/variables.tf +++ b/modules/elb/variables.tf @@ -1,3 +1,9 @@ +variable "create_elb" { + description = "Create the elb or not" + type = bool + default = true +} + variable "name" { description = "The name of the ELB" type = string diff --git a/modules/elb_attachment/README.md b/modules/elb_attachment/README.md index 1b1c359..36bbca4 100644 --- a/modules/elb_attachment/README.md +++ b/modules/elb_attachment/README.md @@ -1,12 +1,27 @@ # aws_elb_attachment +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| aws | n/a | + ## Inputs | Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| elb | The name of the ELB | string | n/a | yes | -| instances | List of instances ID to place in the ELB pool | list(string) | n/a | yes | -| number\_of\_instances | Number of instances ID to place in the ELB pool | number | n/a | yes | +|------|-------------|------|---------|:--------:| +| create\_attachment | Create the elb attachment or not | `bool` | `true` | no | +| elb | The name of the ELB | `string` | n/a | yes | +| instances | List of instances ID to place in the ELB pool | `list(string)` | n/a | yes | +| number\_of\_instances | Number of instances ID to place in the ELB pool | `number` | n/a | yes | + +## Outputs + +No output. diff --git a/modules/elb_attachment/main.tf b/modules/elb_attachment/main.tf index b85b588..42ab9b9 100644 --- a/modules/elb_attachment/main.tf +++ b/modules/elb_attachment/main.tf @@ -1,5 +1,5 @@ resource "aws_elb_attachment" "this" { - count = var.number_of_instances + count = var.create_attachment ? var.number_of_instances : 0 elb = var.elb instance = element(var.instances, count.index) diff --git a/modules/elb_attachment/variables.tf b/modules/elb_attachment/variables.tf index 85d1bae..5547436 100644 --- a/modules/elb_attachment/variables.tf +++ b/modules/elb_attachment/variables.tf @@ -1,3 +1,9 @@ +variable "create_attachment" { + description = "Create the elb attachment or not" + type = bool + default = true +} + variable "number_of_instances" { description = "Number of instances ID to place in the ELB pool" type = number diff --git a/variables.tf b/variables.tf index 88fadd4..5d69065 100644 --- a/variables.tf +++ b/variables.tf @@ -83,3 +83,9 @@ variable "instances" { type = list(string) default = [] } + +variable "create_elb" { + description = "Create the elb or not" + type = bool + default = true +} \ No newline at end of file