Skip to content

Commit

Permalink
1 create load balancer terraform module (#3)
Browse files Browse the repository at this point in the history
* Load balancer module (#2)

* initial commit

* changed name

* path change

* repo

* ip range

* module name corr

* corr

* example change

* some corrections

* added firewal deny allow
  • Loading branch information
Browix authored Apr 17, 2024
1 parent 9e1bf4a commit 9f1a161
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 63 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,48 @@ 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_allow"></a> [firewall\_allow](#input\_firewall\_allow) | List of objects that represent the configuration of firewall allow variables. | `list(string)` | `[]` | no |
| <a name="input_firewall_deny"></a> [firewall\_deny](#input\_firewall\_deny) | List of objects that represent the configuration of firewall deny variables. | `list(string)` | `[]` | no |
| <a name="input_forwarding_rules"></a> [forwarding\_rules](#input\_forwarding\_rules) | List of objects for forwarding\_rule. | `list(any)` | `[]` | no |
| <a name="input_healthcheck"></a> [healthcheck](#input\_healthcheck) | List of objects that represent the configuration of each healthcheck. | `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` | `null` | 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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# Example title

Brief description of an example.

## Required tools

### AZ CLI

Before you start, you need to install Azure CLI according to the official [documentation](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli).

Use the `az login` command to login to your Azure subscription.
# Basic example of loadbalancer usage

### asdf and direnv

Expand Down
35 changes: 35 additions & 0 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module "do_vpc" {
source = "github.com/opsd-io/terraform-module-digitalocean-vpc"
vpc_name = "your-vpc"
region = "nyc1"
ip_range = "192.168.0.0/24"
description = "VPC added by terraform module"
}


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

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

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

target_port = 80
target_protocol = "http"
}
]
}
14 changes: 14 additions & 0 deletions examples/basic/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 1.5.7"

required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.34.1"
}
}
}

provider "digitalocean" {
token = var.do_token
}
5 changes: 5 additions & 0 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "do_token" {
description = "Token to digitalOcean API."
type = string
default = null
}
4 changes: 0 additions & 4 deletions examples/example_of_use/main.tf

This file was deleted.

13 changes: 0 additions & 13 deletions examples/example_of_use/versions.tf

This file was deleted.

51 changes: 50 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# Terraform code goes here
terraform {
required_version = ">= 1.5.7"

required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.34.1"
}
}
}

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_rules
content {
entry_port = forwarding_rules.value.entry_port
entry_protocol = forwarding_rules.value.entry_protocol
target_port = forwarding_rules.value.target_port
target_protocol = forwarding_rules.value.target_protocol
certificate_name = forwarding_rules.value.certificate_name
tls_passthrough = forwarding_rule.value.tls_passthrough
}
}

firewall {
allow = var.firewall_allow
deny = var.firewall_deny
}

dynamic "healthcheck" {
for_each = var.healthcheck
content {
port = healthcheck.value.port
protocol = healthcheck.value.protocol
path = healthcheck.value.path
check_interval_seconds = healthcheck.value.check_interval_seconds
response_timeout_seconds = healthcheck.value.response_timeout_seconds
unhealthy_threshold = healthcheck.value.unhealthy_threshold
healthy_threshold = healthcheck.value.healthy_threshold
}
}
}
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
}
75 changes: 63 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,63 @@
# 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 = null
}

variable "forwarding_rules" {
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 "healthcheck" {
type = list(any)
default = []
description = "List of objects that represent the configuration of each healthcheck."
}

variable "firewall_allow" {
description = "List of objects that represent the configuration of firewall allow variables."
type = list(string)
default = []
}

variable "firewall_deny" {
description = "List of objects that represent the configuration of firewall deny variables."
type = list(string)
default = []
}
13 changes: 0 additions & 13 deletions versions.tf

This file was deleted.

0 comments on commit 9f1a161

Please sign in to comment.