Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load balancer module #2

Merged
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ terraform 1.5.7
terraform-docs 0.17.0
tflint 0.50.3
pre-commit 3.6.2
python 3.12.1
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,46 @@ module "module_name" {

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.1 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5.7 |
| <a name="requirement_digitalocean"></a> [digitalocean](#requirement\_digitalocean) | >= 2.34.1 |

## Providers

No providers.
| Name | Version |
|------|---------|
| <a name="provider_digitalocean"></a> [digitalocean](#provider\_digitalocean) | >= 2.34.1 |

## Modules

No modules.

## Resources

No resources.
| Name | Type |
|------|------|
| [digitalocean_loadbalancer.main](https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/resources/loadbalancer) | resource |

## Inputs

No inputs.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_droplet_ids"></a> [droplet\_ids](#input\_droplet\_ids) | A list of the IDs of each droplet to be attached to the Load Balancer. | `list(string)` | `[]` | no |
| <a name="input_droplet_tag"></a> [droplet\_tag](#input\_droplet\_tag) | The name of a Droplet tag corresponding to Droplets to be assigned to the Load Balancer. | `string` | `null` | no |
| <a name="input_firewall"></a> [firewall](#input\_firewall) | List of objects that represent the configuration of each healthcheck. | `list(any)` | `[]` | no |
| <a name="input_forwarding_rule"></a> [forwarding\_rule](#input\_forwarding\_rule) | List of objects for forwarding\_rule. | `list(any)` | `[]` | no |
| <a name="input_name"></a> [name](#input\_name) | The Load Balancer name | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | The region to start in | `string` | n/a | yes |
| <a name="input_size"></a> [size](#input\_size) | The size of the Load Balancer. It must be either lb-small, lb-medium, or lb-large. Defaults to lb-small. Only one of size or size\_unit may be provided. | `string` | `"lb-small"` | no |
| <a name="input_size_unit"></a> [size\_unit](#input\_size\_unit) | The size of the Load Balancer. It must be in the range (1, 100). Defaults to 1. Only one of size or size\_unit may be provided. | `number` | `1` | no |
| <a name="input_vpc_uuid"></a> [vpc\_uuid](#input\_vpc\_uuid) | The ID of the VPC where the load balancer will be located. | `string` | `""` | no |

## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_id"></a> [id](#output\_id) | The ID of the Load Balancer. |
| <a name="output_ip"></a> [ip](#output\_ip) | The ip of the Load Balancer. |
| <a name="output_urn"></a> [urn](#output\_urn) | The urn for the Load Balancer. |
<!-- END_TF_DOCS -->

## Examples of usage
Expand Down
38 changes: 36 additions & 2 deletions examples/example_of_use/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
module "module_name" {
source = "../../"
provider "digitalocean" {
token = var.do_token
}

module "terraform_module_digitalocean_vpc" {
source = "github.com/opsd-io/terraform-module-digitalocean-vpc"
vpc_name = "your-vpc"
region = "nyc1"
description = "VPC added by terraform module"
}


module "digitalocean_droplet" {
source = "github.com/opsd-io/terraform-module-digitalocean-droplet?ref=MB_droplet_creation"
image = "ubuntu-20-04-x64"
name = "web-1"
region = "nyc1"
size = "s-1vcpu-1gb"
vpc_uuid = [module.terraform_module_digitalocean_vpc.id]
}

module "digitalocean_loadbalancer" {
source = "github.com/opsd-io/terraform-module-digitalocean-load-balancer?ref=load_balancer_module"
name = "loadbalancer-1"
region = "nyc1"
droplet_ids = [module.digitalocean_droplet.id]
vpc_uuid = [module.digitalocean_vpc.id]

forwarding_rule = [
{
entry_port = 80
entry_protocol = "http"

target_port = 80
target_protocol = "http"
}
]
}
10 changes: 10 additions & 0 deletions examples/example_of_use/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "do_token" {
description = "Token to digitalOcean API"
type = string
}

variable "droplet_ids" {
description = "A list of the IDs of each droplet to be attached to the Load Balancer."
type = list(string)
default = []
}
14 changes: 5 additions & 9 deletions examples/example_of_use/versions.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
terraform {
required_version = ">= 1.3.1"
required_version = ">= 1.5.7"
required_providers {
# github = {
# source = "integrations/github"
# version = ">= 5.3.0"
# }
# azurerm = {
# source = "hashicorp/azurerm"
# version = ">= 3.22.0"
# }
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.34.1"
}
}
}
28 changes: 27 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# Terraform code goes here
resource "digitalocean_loadbalancer" "main" {
name = var.name
region = var.region
size = var.size
size_unit = var.size_unit
vpc_uuid = var.vpc_uuid
droplet_ids = var.droplet_ids
droplet_tag = var.droplet_tag

dynamic "forwarding_rule" {
for_each = var.forwarding_rule
content {
entry_port = forwarding_rule.value.entry_port
entry_protocol = forwarding_rule.value.entry_protocol
target_port = forwarding_rule.value.target_port
target_protocol = forwarding_rule.value.target_protocol
}
}

dynamic "firewall" {
for_each = var.firewall
content {
deny = lookup(firewall.value, "deny", null)
allow = lookup(firewall.value, "allow", null)
}
}
}
18 changes: 14 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# output "variable" {
# description = "output variable description"
# value = variable.main.name
# }
output "id" {
description = "The ID of the Load Balancer."
value = digitalocean_loadbalancer.main.id
}

output "ip" {
description = "The ip of the Load Balancer."
value = digitalocean_loadbalancer.main.ip
}

output "urn" {
description = "The urn for the Load Balancer."
value = digitalocean_loadbalancer.main.urn
}
63 changes: 51 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
# variable "variable_name" {
# description = "variable description"
# type = number
# default = 1
# }

# variable "variable_password" {
# description = "variable description"
# type = string
# sensitive = true
# default = "abc"
# }
variable "name" {
description = "The Load Balancer name"
type = string
}

variable "region" {
description = "The region to start in"
type = string
}

variable "size" {
description = "The size of the Load Balancer. It must be either lb-small, lb-medium, or lb-large. Defaults to lb-small. Only one of size or size_unit may be provided."
type = string
default = "lb-small"
}

variable "size_unit" {
description = "The size of the Load Balancer. It must be in the range (1, 100). Defaults to 1. Only one of size or size_unit may be provided."
type = number
default = 1
}

variable "vpc_uuid" {
description = "The ID of the VPC where the load balancer will be located."
type = string
default = ""
}

variable "forwarding_rule" {
description = "List of objects for forwarding_rule."
type = list(any)
default = []
}

variable "droplet_ids" {
description = "A list of the IDs of each droplet to be attached to the Load Balancer."
type = list(string)
default = []
}

variable "droplet_tag" {
description = "The name of a Droplet tag corresponding to Droplets to be assigned to the Load Balancer."
type = string
default = null
}

variable "firewall" {
description = "List of objects that represent the configuration of each healthcheck."
type = list(any)
default = []
}
14 changes: 5 additions & 9 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
terraform {
required_version = ">= 1.3.1"
required_version = ">= 1.5.7"
required_providers {
# github = {
# source = "integrations/github"
# version = ">= 5.3.0"
# }
# azurerm = {
# source = "hashicorp/azurerm"
# version = ">= 3.22.0"
# }
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.34.1"
}
}
}
Loading