-
Notifications
You must be signed in to change notification settings - Fork 34
/
cloudformation-template.json
225 lines (225 loc) · 5.82 KB
/
cloudformation-template.json
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Runs an instance of aws-name-server",
"Parameters": {
"InstanceType": {
"Description": "EC2 instance type",
"Type": "String",
"Default": "t2.micro"
},
"KeyName": {
"Description": "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type": "String"
},
"Ami": {
"Description": "The EC2 AMI (64bit HVM-based EBS-backed Ubuntu 14.04 recommended)",
"Type": "String",
"Default": "ami-acff23c4"
},
"DnsPrefix": {
"Description": "Prefix for the NS record (<prefix>.<zone>)",
"Type": "String",
"Default": "aws"
},
"DnsZone": {
"Description": "Route53-hosted zone to use for the NS record (<prefix>.<zone>)",
"Type": "String"
},
"SubnetId": {
"Description": "The Subnet ID for the instance",
"Type": "String"
},
"VpcId": {
"Description": "VPC associated with the provided subnet",
"Type": "String"
},
"AdminSecurityGroup": {
"Description": "Existing security group that should be granted administrative access (e.g., 'sg-123456')",
"Type": "String"
},
"GoPackage": {
"Description": "The go package to build",
"Type": "String",
"Default": "github.com/ConradIrwin/aws-name-server"
}
},
"Resources": {
"Role": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"ec2.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Path": "/",
"Policies": [
{
"PolicyName": "Ec2DescribeInstances",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:DescribeInstances",
"Resource": "*"
}
]
}
}
]
}
},
"InstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [
{
"Ref": "Role"
}
]
}
},
"NameServer": {
"Type": "AWS::EC2::Instance",
"Properties": {
"KeyName": {
"Ref": "KeyName"
},
"ImageId": {
"Ref": "Ami"
},
"IamInstanceProfile": {
"Ref": "InstanceProfile"
},
"InstanceType": {
"Ref": "InstanceType"
},
"NetworkInterfaces": [
{
"AssociatePublicIpAddress": "true",
"DeviceIndex": "0",
"SubnetId": {
"Ref": "SubnetId"
},
"GroupSet": [
{
"Ref": "ServerSecurityGroup"
},
{
"Ref": "AdminSecurityGroup"
}
]
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -ex\n",
"apt-get update\n",
"apt-get install -y golang git unattended-upgrades\n",
"# Automatic security updates\n",
"cat > /etc/apt/apt.conf.d/20auto-upgrades <<EOF\n",
"APT::Periodic::Update-Package-Lists \"1\";\n",
"APT::Periodic::Unattended-Upgrade \"1\";\n",
"EOF\n",
"export GOPATH=/usr/local\n",
"go get ", { "Ref": "GoPackage" }, "\n",
"setcap cap_net_bind_service=+ep /usr/local/bin/aws-name-server\n",
"cat << EOF > /etc/init/aws-name-server.conf\n",
"# upstart script for aws-name-server\n",
"description \"AWS Name Server\"\n\n",
"start on filesystem or runlevel [2345]\n",
"stop on runlevel [!2345]\n\n",
"respawn\n",
"respawn limit 10 5\n",
"setuid nobody\n",
"setgid nogroup\n\n",
"exec /usr/local/bin/aws-name-server --domain ", { "Ref": "DnsPrefix" }, ".", { "Ref": "DnsZone" },
"\nEOF\n\n",
"initctl start aws-name-server\n"
]
]
}
}
}
},
"ServerSecurityGroup": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Enable SSH and Registry access",
"VpcId": {
"Ref": "VpcId"
},
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "53",
"ToPort": "53",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "udp",
"FromPort": "53",
"ToPort": "53",
"CidrIp": "0.0.0.0/0"
}
]
}
},
"DnsRecord": {
"Type": "AWS::Route53::RecordSet",
"Properties": {
"HostedZoneName": {
"Fn::Join": [
"",
[
{
"Ref": "DnsZone"
},
"."
]
]
},
"Comment": "AWS Name Server",
"Name": {
"Fn::Join": [
"",
[
{
"Ref": "DnsPrefix"
},
".",
{
"Ref": "DnsZone"
},
"."
]
]
},
"Type": "NS",
"TTL": "300",
"ResourceRecords": [
{
"Fn::GetAtt": [
"NameServer",
"PublicDnsName"
]
}
]
}
}
}
}