Skip to content

Commit

Permalink
feat: Added variable to enable/disable module (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
theeternalrat authored Jun 19, 2020
1 parent 18d8b91 commit 71d0ffc
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 47 deletions.
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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

Expand Down
17 changes: 14 additions & 3 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ $ terraform apply
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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

| Name | Description |
|------|-------------|
| 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) |
Expand Down
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
module "elb" {
source = "./modules/elb"

create_elb = var.create_elb

name = var.name
name_prefix = var.name_prefix

Expand Down Expand Up @@ -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
Expand Down
39 changes: 25 additions & 14 deletions modules/elb/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# aws_elb

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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

Expand Down
2 changes: 2 additions & 0 deletions modules/elb/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
resource "aws_elb" "this" {
count = var.create_elb ? 1 : 0

name = var.name
name_prefix = var.name_prefix

Expand Down
6 changes: 6 additions & 0 deletions modules/elb/variables.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 19 additions & 4 deletions modules/elb_attachment/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# aws_elb_attachment

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## 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.

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2 changes: 1 addition & 1 deletion modules/elb_attachment/main.tf
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 6 additions & 0 deletions modules/elb_attachment/variables.tf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ variable "instances" {
type = list(string)
default = []
}

variable "create_elb" {
description = "Create the elb or not"
type = bool
default = true
}

0 comments on commit 71d0ffc

Please sign in to comment.