-
Notifications
You must be signed in to change notification settings - Fork 878
/
Copy pathDropletStack.cs
62 lines (55 loc) · 1.67 KB
/
DropletStack.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016-2025, Pulumi Corporation. All rights reserved.
using Pulumi;
using Pulumi.DigitalOcean;
using Pulumi.DigitalOcean.Inputs;
class DropletStack : Stack
{
public DropletStack()
{
var dropletCount = 2;
var region = "nyc3";
var dropletTypeTag = new Tag($"demo-app-{Pulumi.Deployment.Instance.ProjectName}");
var userData = @"
#!/bin/bash
sudo apt-get update
sudo apt-get install -y nginx
";
var droplets = new Droplet[dropletCount];
for (var i = 0; i < dropletCount; i++)
{
var nameTag = new Tag($"web-{i}");
droplets[i] = new Droplet($"web-{i}", new DropletArgs
{
Image = "ubuntu-20-04-x64",
Region = region,
PrivateNetworking = true,
Size = "s-1vcpu-1gb",
Tags =
{
dropletTypeTag.Id,
nameTag.Id
},
UserData = userData.Trim()
});
}
var loadbalancer = new LoadBalancer("public", new LoadBalancerArgs
{
DropletTag = dropletTypeTag.Name,
ForwardingRules = new LoadBalancerForwardingRuleArgs
{
EntryPort = 80,
EntryProtocol = "http",
TargetPort = 80,
TargetProtocol = "http"
},
Healthcheck = new LoadBalancerHealthcheckArgs
{
Port = 80,
Protocol = "tcp"
},
Region = region
});
this.Endpoint = loadbalancer.Ip;
}
[Output] public Output<string> Endpoint { get; set; }
}