Wolfgang Kulhanek
2018-05-14 83a3b0fd4ebc36adbe8eb5b644e2a905047eb921
commit | author | age
83a3b0 1 #jinja2: lstrip_blocks: True
3668b6 2 ---
d4b5bf 3 AWSTemplateFormatVersion: "2010-09-09"
3668b6 4 Mappings:
S 5   RegionMapping:
6     us-east-1:
83a3b0 7       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 8       RHELAMI: ami-6871a115
9       {% else %}
3668b6 10       RHELAMI: ami-c998b6b2
83a3b0 11       {% endif %}
3668b6 12     us-east-2:
83a3b0 13       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 14       RHELAMI: ami-03291866
15       {% else %}
3668b6 16       RHELAMI: ami-cfdafaaa
83a3b0 17       {% endif %}
3668b6 18     us-west-1:
83a3b0 19       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 20       RHELAMI: ami-18726478
21       {% else %}
22       RHELAMI: ami-66eec506
23       {% endif %}
3668b6 24     us-west-2:
83a3b0 25       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 26       RHELAMI: ami-223f945a
27       {% else %}
3668b6 28       RHELAMI: ami-9fa343e7
83a3b0 29       {% endif %}
3668b6 30     eu-west-1:
83a3b0 31       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 32       RHELAMI: ami-7c491f05
33       {% else %}
3668b6 34       RHELAMI: ami-bb9a6bc2
83a3b0 35       {% endif %}
3668b6 36     eu-central-1:
83a3b0 37       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 38       RHELAMI: ami-c86c3f23
39       {% else %}
3668b6 40       RHELAMI: ami-d74be5b8
83a3b0 41       {% endif %}
3668b6 42     ap-northeast-1:
83a3b0 43       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 44       RHELAMI: ami-6b0d5f0d
45       {% else %}
3668b6 46       RHELAMI: ami-30ef0556
83a3b0 47       {% endif %}
3668b6 48     ap-northeast-2:
83a3b0 49       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 50       RHELAMI: ami-3eee4150
51       {% else %}
3668b6 52       RHELAMI: ami-0f5a8361
83a3b0 53       {% endif %}
3668b6 54     ap-southeast-1:
83a3b0 55       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 56       RHELAMI: ami-76144b0a
57       {% else %}
3668b6 58       RHELAMI: ami-10bb2373
83a3b0 59       {% endif %}
3668b6 60     ap-southeast-2:
83a3b0 61       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 62       RHELAMI: ami-67589505
63       {% else %}
3668b6 64       RHELAMI: ami-ccecf5af
83a3b0 65       {% endif %}
3668b6 66     ap-south-1:
83a3b0 67       {% if osrelease | version_compare('3.9.25', '>=') %}
WK 68       RHELAMI: ami-5b673c34
69       {% else %}
3668b6 70       RHELAMI: ami-cdbdd7a2
83a3b0 71       {% endif %}
WK 72     sa-east-1:
73       {% if osrelease | version_compare('3.9.25', '>=') %}
74       RHELAMI: ami-b0b7e3dc
75       {% else %}
76       RHELAMI: ami-a789ffcb
77       {% endif %}
3668b6 78   DNSMapping:
S 79     us-east-1:
80       domain: "us-east-1.compute.internal"
81     us-west-1:
82       domain: "us-west-1.compute.internal"
83     us-west-2:
84       domain: "us-west-2.compute.internal"
85     eu-west-1:
86       domain: "eu-west-1.compute.internal"
87     eu-central-1:
88       domain: "eu-central-1.compute.internal"
89     ap-northeast-1:
90       domain: "ap-northeast-1.compute.internal"
91     ap-northeast-2:
92       domain: "ap-northeast-2.compute.internal"
93     ap-southeast-1:
94       domain: "ap-southeast-1.compute.internal"
95     ap-southeast-2:
96       domain: "ap-southeast-2.compute.internal"
97     sa-east-1:
98       domain: "sa-east-1.compute.internal"
99     ap-south-1:
100       domain: "ap-south-1.compute.internal"
101
102 Resources:
103   Vpc:
104     Type: "AWS::EC2::VPC"
105     Properties:
106       CidrBlock: "{{vpcid_cidr_block}}"
107       EnableDnsSupport: true
108       EnableDnsHostnames: true
109       Tags:
110         - Key: Name
111           Value: "{{vpcid_name_tag}}"
112         - Key: Hostlication
113           Value:
114             Ref: "AWS::StackId"
115
116   VpcInternetGateway:
117     Type: "AWS::EC2::InternetGateway"
118
119   VpcGA:
120     Type: "AWS::EC2::VPCGatewayAttachment"
121     Properties:
122       InternetGatewayId:
123         Ref: VpcInternetGateway
124       VpcId:
125         Ref: Vpc
126
127   VpcRouteTable:
128     Type: "AWS::EC2::RouteTable"
129     Properties:
130       VpcId:
131         Ref: Vpc
132
133   VPCRouteInternetGateway:
134     DependsOn: VpcGA
135     Type: "AWS::EC2::Route"
136     Properties:
137       GatewayId:
138         Ref: VpcInternetGateway
139       DestinationCidrBlock: "0.0.0.0/0"
140       RouteTableId:
141         Ref: VpcRouteTable
142
3f3183 143 {% for subnet in subnets %}
S 144   {{subnet['name']}}:
3668b6 145     Type: "AWS::EC2::Subnet"
S 146     DependsOn:
147       - Vpc
148     Properties:
3f3183 149       CidrBlock: "{{subnet['cidr']}}"
3668b6 150       Tags:
S 151         - Key: Name
152           Value: "{{project_tag}}"
153       MapPublicIpOnLaunch: true
154       VpcId:
155         Ref: Vpc
fcfbaa 156 {% endfor %}
3668b6 157
S 158   PublicSubnetRTA:
159     Type: "AWS::EC2::SubnetRouteTableAssociation"
160     Properties:
161       RouteTableId:
162         Ref: VpcRouteTable
163       SubnetId:
164         Ref: PublicSubnet
165
fcfbaa 166 {% for security_group in security_groups %}
PS 167   {{security_group['name']}}:
3668b6 168     Type: "AWS::EC2::SecurityGroup"
S 169     Properties:
170       GroupDescription: Host
171       VpcId:
172         Ref: Vpc
173       Tags:
174         - Key: Name
fcfbaa 175           Value: "{{security_group['name']}}"
PS 176 {% endfor %}
3668b6 177
acb370 178
fcfbaa 179 {% for security_group in security_groups %}
1e1b1d 180 {% for rule in security_group['rules'] %}
3e6fe7 181   {{security_group['name']}}{{rule['name']}}:
74d512 182     Type: "AWS::EC2::SecurityGroup{{rule['rule_type']}}"
3668b6 183     Properties:
1e1b1d 184      GroupId:
acb370 185        Fn::GetAtt:
PS 186          - "{{security_group['name']}}"
187          - GroupId
74d512 188      IpProtocol: {{rule['protocol']}}
acb370 189      FromPort: {{rule['from_port']}}
PS 190      ToPort: {{rule['to_port']}}
191 {% if rule['cidr'] is defined %}
192      CidrIp: "{{rule['cidr']}}"
193 {% endif  %}
194 {% if rule['from_group'] is defined %}
973a97 195      SourceSecurityGroupId:
PS 196        Fn::GetAtt:
197         - "{{rule['from_group']}}"
198         - GroupId
acb370 199 {% endif  %}
3668b6 200 {% endfor %}
S 201 {% endfor %}
202
fcfbaa 203
acb370 204   zoneinternalidns:
PS 205     Type: "AWS::Route53::HostedZone"
206     Properties:
207       Name: "{{ zone_internal_dns }}"
208       VPCs:
209         - VPCId:
210             Ref: Vpc
211           VPCRegion:
212             Ref: "AWS::Region"
213       HostedZoneConfig:
214         Comment: "Created By ansible agnostic deployer"
215
216   CloudDNS:
217     Type: AWS::Route53::RecordSetGroup
218     DependsOn:
2fc19b 219 {% for c in range(1,(loadbalancer_instance_count|int)+1) %}
S 220       - "loadbalancer{{loop.index}}EIP"
acb370 221 {% endfor %}
PS 222     Properties:
223       HostedZoneId: "{{HostedZoneId}}"
224       RecordSets:
225         - Name: "{{cloudapps_dns}}"
226           Type: A
227           TTL: 900
228           ResourceRecords:
2fc19b 229 {% for c in range(1,(loadbalancer_instance_count|int)+1) %}
acb370 230             - Fn::GetAtt:
2fc19b 231                 - loadbalancer{{loop.index}}
acb370 232                 - PublicIp
PS 233 {% endfor %}
234
235 {% for instance in instances %}
236 {% if instance['dns_loadbalancer']|d(false)|bool and not instance['unique']|d(false)|bool %}
237   {{instance['name']}}DNSLoadBalancer:
238     Type: "AWS::Route53::RecordSetGroup"
239     DependsOn:
240 {% for c in range(1, (instance['count']|int)+1) %}
241       - {{instance['name']}}{{c}}EIP
242 {% endfor %}
243     Properties:
244       HostedZoneId: {{HostedZoneId}}
245       RecordSets:
246       - Name: "{{instance['name']}}.{{subdomain_base}}."
247         Type: A
248         TTL: 900
249         ResourceRecords:
250 {% for c in range(1,(instance['count'] |int)+1) %}
251           - "Fn::GetAtt":
252             - {{instance['name']}}{{c}}
253             - PublicIp
254 {% endfor %}
255 {% endif %}
256
257 {% for c in range(1,(instance['count'] |int)+1) %}
258   {{instance['name']}}{{loop.index}}:
259     Type: "AWS::EC2::Instance"
260     Properties:
261       ImageId:
262         Fn::FindInMap:
263         - RegionMapping
264         - Ref: AWS::Region
265         - {{ instance['image_id'] | default('RHELAMI') }}
266       InstanceType: "{{instance['flavor'][cloud_provider]}}"
267       KeyName: "{{instance['key_name'] | default(key_name)}}"
268 {% if instance['UserData'] is defined %}
269       {{instance['UserData']}}
270 {% endif %}
271       SecurityGroupIds:
272         - "Fn::GetAtt":
273           - {{instance['security_group']}}
274           - GroupId
275       SubnetId:
276         Ref: {{instance['subnet']}}
277       Tags:
278 {% if instance['unique'] | d(false) | bool %}
279         - Key: Name
280           Value: {{instance['name']}}
281         - Key: internaldns
282           Value: {{instance['name']}}.{{chomped_zone_internal_dns}}
283 {% else %}
284         - Key: Name
285           Value: {{instance['name']}}{{loop.index}}
286         - Key: internaldns
287           Value: {{instance['name']}}{{loop.index}}.{{chomped_zone_internal_dns}}
288 {% endif %}
289         - Key: "owner"
290           Value: "{{ email | default('unknownuser') }}"
291         - Key: "Project"
292           Value: "{{project_tag}}"
293         - Key: "{{project_tag}}"
294           Value: "{{ instance['name'] }}"
295 {% for tag in instance['tags'] %}
296         - Key: {{tag['key']}}
297           Value: {{tag['value']}}
298 {% endfor %}
299       BlockDeviceMappings:
300         - DeviceName: "/dev/sda1"
301           Ebs:
302             VolumeSize: {{ instance['rootfs_size'] | default('50') }}
303 {% for vol in instance['volumes']|default([]) %}
304         - DeviceName: "{{ vol['device_name'] }}"
305           Ebs:
306             VolumeType: "{{ vol['volume_type'] | d('gp2') }}"
307             VolumeSize: "{{ vol['volume_size'] | d('20') }}"
308 {% endfor %}
309
310   {{instance['name']}}{{loop.index}}InternalDNS:
311     Type: "AWS::Route53::RecordSetGroup"
312     Properties:
313       HostedZoneId:
314         Ref: zoneinternalidns
315       RecordSets:
316 {% if instance['unique'] | d(false) | bool %}
317       - Name: "{{instance['name']}}.{{zone_internal_dns}}"
318 {% else %}
319       - Name: "{{instance['name']}}{{loop.index}}.{{zone_internal_dns}}"
320 {% endif %}
321         Type: A
322         TTL: 10
323         ResourceRecords:
324           - "Fn::GetAtt":
325             - {{instance['name']}}{{loop.index}}
326             - PrivateIp
327
328 {% if instance['public_dns'] %}
329   {{instance['name']}}{{loop.index}}EIP:
330     Type: "AWS::EC2::EIP"
331     DependsOn:
332     - VpcGA
333     Properties:
334       InstanceId:
335         Ref: {{instance['name']}}{{loop.index}}
336
337   {{instance['name']}}{{loop.index}}PublicDNS:
338     Type: "AWS::Route53::RecordSetGroup"
339     DependsOn:
340       - {{instance['name']}}{{loop.index}}EIP
341     Properties:
342       HostedZoneId: {{HostedZoneId}}
343       RecordSets:
344 {% if instance['unique'] | d(false) | bool %}
345           - Name: "{{instance['name']}}.{{subdomain_base}}."
346 {% else %}
347           - Name: "{{instance['name']}}{{loop.index}}.{{subdomain_base}}."
348 {% endif %}
349             Type: A
350             TTL: 10
351             ResourceRecords:
352             - "Fn::GetAtt":
353               - {{instance['name']}}{{loop.index}}
354               - PublicIp
355 {% endif %}
356 {% endfor %}
357 {% endfor %}
358
359 Outputs:
360   Route53internalzoneOutput:
361     Description: The ID of the internal route 53 zone
362     Value:
363       Ref: zoneinternalidns