-
Notifications
You must be signed in to change notification settings - Fork 879
/
WebServerStack.cs
56 lines (47 loc) · 1.45 KB
/
WebServerStack.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
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
using Pulumi;
using Pulumi.Aws.Ec2;
using Pulumi.Aws.Ec2.Inputs;
class WebServerStack : Stack
{
public WebServerStack()
{
var ami = GetAmi.Invoke(new GetAmiInvokeArgs
{
MostRecent = true,
Owners = {"137112412989"},
Filters = {new GetAmiFilterInputArgs {Name = "name", Values = "amzn-ami-hvm-*"}}
});
var group = new SecurityGroup("web-secgrp", new SecurityGroupArgs
{
Description = "Enable HTTP access",
Ingress =
{
new SecurityGroupIngressArgs
{
Protocol = "tcp",
FromPort = 80,
ToPort = 80,
CidrBlocks = {"0.0.0.0/0"}
}
}
});
var userData = @"
#!/bin/bash
echo ""Hello, World!"" > index.html
nohup python -m SimpleHTTPServer 80 &
";
var server = new Instance("web-server-www", new InstanceArgs
{
InstanceType = Size,
VpcSecurityGroupIds = {group.Id},
UserData = userData,
Ami = ami.Apply(a => a.Id)
});
this.PublicIp = server.PublicIp;
this.PublicDns = server.PublicDns;
}
[Output] public Output<string> PublicIp { get; set; }
[Output] public Output<string> PublicDns { get; set; }
private const string Size = "t2.micro";
}