-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Loadbalancer example | ||
|
||
An example of provisioning Droplets attached to a Load Balancer using tags. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Now visit your Load Balancer IP in a browser and refresh. You should see the | ||
requests are sent to each Droplet. | ||
|
||
Note that this example may create resources which can cost money. | ||
Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|:----:|:-----:|:-----:| | ||
| do\_token | - | string | - | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| loadbalancer\_ip | IP address of the Load Balancer | | ||
| web\_ipv4\_address | List of IPv4 addresses of web Droplets | | ||
|
||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
variable "do_token" {} | ||
|
||
provider "digitalocean" { | ||
token = "${var.do_token}" | ||
} | ||
|
||
resource "digitalocean_tag" "ENV_example" { | ||
name = "ENV:example" | ||
} | ||
|
||
resource "digitalocean_tag" "ROLE_web" { | ||
name = "ROLE:web" | ||
} | ||
|
||
module "web" { | ||
source = "../../" | ||
|
||
droplet_count = 2 | ||
|
||
droplet_name = "example-web" | ||
droplet_size = "nano" | ||
tags = ["${digitalocean_tag.ENV_example.id}", "${digitalocean_tag.ROLE_web.id}"] | ||
user_data = "${file("user-data.web")}" | ||
} | ||
|
||
resource "digitalocean_loadbalancer" "public" { | ||
name = "web-balancer" | ||
region = "ams3" | ||
|
||
forwarding_rule { | ||
entry_port = 80 | ||
entry_protocol = "http" | ||
|
||
target_port = 80 | ||
target_protocol = "http" | ||
} | ||
|
||
healthcheck { | ||
port = 22 | ||
protocol = "tcp" | ||
} | ||
|
||
droplet_tag = "${digitalocean_tag.ROLE_web.name}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "loadbalancer_ip" { | ||
description = "IP address of the Load Balancer" | ||
value = "${digitalocean_loadbalancer.public.ip}" | ||
} | ||
|
||
output "web_ipv4_address" { | ||
description = "List of IPv4 addresses of web Droplets" | ||
value = "${module.web.ipv4_address}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#cloud-config | ||
|
||
runcmd: | ||
- apt-get install -y nginx | ||
- 'echo "<html><body><h2>$(hostname)</h2></body></html>" > /var/www/html/index.html' |