forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
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
119 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,3 @@ | ||
name: digitalocean-ts-loadbalanced-droplets | ||
runtime: nodejs | ||
description: Basic example of load balanced droplets on DigitalOcean |
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,67 @@ | ||
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new) | ||
|
||
# Pulumi DigitalOcean Droplets | ||
|
||
Starting point for building a Pulumi sample architecture on DigitalOcean. | ||
|
||
## Running the App | ||
|
||
1. Create a new stack: | ||
|
||
``` | ||
$ pulumi stack init digitalocean-ts-loadbalanced-droplets | ||
``` | ||
|
||
1. Configure the project: | ||
|
||
``` | ||
$ pulumi config set --secret digitalocean:token YOURDIGITALOCEANTOKEN | ||
``` | ||
|
||
1. Restore NPM dependencies: | ||
|
||
``` | ||
$ npm install | ||
``` | ||
|
||
1. Run `pulumi up` to preview and deploy changes: | ||
|
||
``` | ||
$ pulumi up | ||
Previewing update (digitalocean-ts-loadbalanced-droplets): | ||
... | ||
Updating (digitalocean-ts-loadbalanced-droplets): | ||
Type Name Status | ||
+ pulumi:pulumi:Stack digitalocean-ts-loadbalanced-droplets-digitalocean-ts-loadbalanced-droplets created | ||
+ ├─ digitalocean:index:Tag demo-app created | ||
+ ├─ digitalocean:index:Tag web-2 created | ||
+ ├─ digitalocean:index:Tag web-0 created | ||
+ ├─ digitalocean:index:Tag web-1 created | ||
+ ├─ digitalocean:index:LoadBalancer public created | ||
+ ├─ digitalocean:index:Droplet web-0 created | ||
+ ├─ digitalocean:index:Droplet web-2 created | ||
+ └─ digitalocean:index:Droplet web-1 created | ||
Outputs: | ||
endpoint: "138.197.62.183" | ||
Resources: | ||
+ 9 created | ||
Duration: 3m2s | ||
``` | ||
|
||
1. Curl the HTTP server: | ||
|
||
``` | ||
curl "$(pulumi stack output endpoint)" | ||
``` | ||
|
||
1. Cleanup | ||
|
||
``` | ||
$ pulumi destroy | ||
$ pulumi stack rm | ||
``` |
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,40 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as digitalocean from "@pulumi/digitalocean"; | ||
|
||
const dropletCount = 3; | ||
const region = digitalocean.Regions.NYC3; | ||
|
||
const dropletTypeTag = new digitalocean.Tag("demo-app"); | ||
const userData = | ||
`#!/bin/bash | ||
sudo apt-get update | ||
sudo apt-get install -y nginx`; | ||
const droplets = []; | ||
for (let i = 0; i < dropletCount; i ++) { | ||
let nameTag = new digitalocean.Tag(`web-${i}`); | ||
droplets.push(new digitalocean.Droplet(`web-${i}`, { | ||
image: "ubuntu-18-04-x64", | ||
region: region, | ||
privateNetworking: true, | ||
size: digitalocean.DropletSlugs.Droplet512mb, | ||
tags: [nameTag.id, dropletTypeTag.id], | ||
userData: userData, | ||
})); | ||
} | ||
|
||
const lb = new digitalocean.LoadBalancer("public", { | ||
dropletTag: dropletTypeTag.name, | ||
forwardingRules: [{ | ||
entryPort: 80, | ||
entryProtocol: digitalocean.Protocols.HTTP, | ||
targetPort: 80, | ||
targetProtocol: digitalocean.Protocols.HTTP, | ||
}], | ||
healthcheck: { | ||
port: 80, | ||
protocol: digitalocean.Protocols.TCP, | ||
}, | ||
region: region, | ||
}); | ||
|
||
export const endpoint = lb.ip; |
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 @@ | ||
{ | ||
"name": "webserver-linode", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"dependencies": { | ||
"@pulumi/pulumi": "latest", | ||
"@pulumi/digitalocean": "latest" | ||
} | ||
} |