AWSTemplateFormatVersion: "2010-09-09"
|
Mappings:
|
RegionMapping:
|
us-east-1:
|
RHELAMI: ami-c998b6b2
|
WIN2012R2AMI: ami-01a2180a66e81fae2 # Windows_Server-2012-R2_RTM-English-64Bit-Base-
|
us-east-2:
|
RHELAMI: ami-cfdafaaa
|
WIN2012R2AMI: ami-0f472fb9bdac629b0 # Windows_Server-2012-R2_RTM-English-64Bit-Base-
|
us-west-1:
|
RHELAMI: ami-66eec506
|
us-west-2:
|
RHELAMI: ami-9fa343e7
|
eu-central-1:
|
RHELAMI: ami-d74be5b8
|
WIN2012R2AMI: ami-0297bc3628de600e3 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019
|
eu-west-1:
|
RHELAMI: ami-bb9a6bc2
|
eu-west-2:
|
WIN2012R2AMI: ami-0416ae4f6060116ad # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
eu-west-3:
|
WIN2012R2AMI: ami-09d8c503ec9b242e0 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
ca-central-1:
|
WIN2012R2AMI: ami-067e4426b17364c26 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
ap-northeast-1:
|
RHELAMI: ami-30ef0556
|
WIN2012R2AMI: ami-0eeeab3e23597eaae # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
ap-northeast-2:
|
RHELAMI: ami-44db152a
|
WIN2012R2AMI: ami-033a1501143ab3c9a # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
ap-southeast-1:
|
RHELAMI: ami-10bb2373
|
WIN2012R2AMI: ami-0c506e54506222e59 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019
|
ap-southeast-2:
|
RHELAMI: ami-ccecf5af
|
WIN2012R2AMI: ami-01048eb9bccc4829d # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
sa-east-1:
|
RHELAMI: ami-a789ffcb
|
WIN2012R2AMI: ami-0a0f24f427c390730 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
ap-south-1:
|
RHELAMI: ami-cdbdd7a2
|
WIN2012R2AMI: ami-0d46eaf1c637bc632 # Windows_Server-2012-R2_RTM-English-64Bit-Base-2019.02.09
|
DNSMapping:
|
"us-east-1":
|
domain: "us-east-1.compute.internal"
|
"us-west-1":
|
domain: "us-west-1.compute.internal"
|
"us-west-2":
|
domain: "us-west-2.compute.internal"
|
"eu-west-1":
|
domain: "eu-west-1.compute.internal"
|
"eu-central-1":
|
domain: "eu-central-1.compute.internal"
|
"ap-northeast-1":
|
domain: "ap-northeast-1.compute.internal"
|
"ap-northeast-2":
|
domain: "ap-northeast-2.compute.internal"
|
"ap-southeast-1":
|
domain: "ap-southeast-1.compute.internal"
|
"ap-southeast-2":
|
domain: "ap-southeast-2.compute.internal"
|
"sa-east-1":
|
domain: "sa-east-1.compute.internal"
|
"ap-south-1":
|
domain: "ap-south-1.compute.internal"
|
Resources:
|
Vpc:
|
Type: "AWS::EC2::VPC"
|
Properties:
|
CidrBlock: "{{vpcid_cidr_block}}"
|
EnableDnsSupport: true
|
EnableDnsHostnames: true
|
Tags:
|
- Key: Name
|
Value: "{{vpcid_name_tag}}"
|
- Key: Hostlication
|
Value:
|
Ref: "AWS::StackId"
|
VpcInternetGateway:
|
Type: "AWS::EC2::InternetGateway"
|
VpcGA:
|
Type: "AWS::EC2::VPCGatewayAttachment"
|
Properties:
|
InternetGatewayId:
|
Ref: VpcInternetGateway
|
VpcId:
|
Ref: Vpc
|
VpcRouteTable:
|
Type: "AWS::EC2::RouteTable"
|
Properties:
|
VpcId:
|
Ref: Vpc
|
VPCRouteInternetGateway:
|
DependsOn: VpcGA
|
Type: "AWS::EC2::Route"
|
Properties:
|
GatewayId:
|
Ref: VpcInternetGateway
|
DestinationCidrBlock: "0.0.0.0/0"
|
RouteTableId:
|
Ref: VpcRouteTable
|
|
{% for subnet in subnets %}
|
{{subnet['name']}}:
|
Type: "AWS::EC2::Subnet"
|
DependsOn:
|
- Vpc
|
Properties:
|
CidrBlock: "{{subnet['cidr']}}"
|
Tags:
|
- Key: Name
|
Value: "{{project_tag}}"
|
MapPublicIpOnLaunch: true
|
VpcId:
|
Ref: Vpc
|
{% endfor %}
|
|
PublicSubnetRTA:
|
Type: "AWS::EC2::SubnetRouteTableAssociation"
|
Properties:
|
RouteTableId:
|
Ref: VpcRouteTable
|
SubnetId:
|
Ref: PublicSubnet
|
{% for security_group in security_groups %}
|
{{security_group['name']}}:
|
Type: "AWS::EC2::SecurityGroup"
|
Properties:
|
GroupDescription: Host
|
VpcId:
|
Ref: Vpc
|
Tags:
|
- Key: Name
|
Value: "{{security_group['name']}}"
|
{% endfor %}
|
|
{% for security_group in security_groups %}
|
{% for rule in security_group['rules'] %}
|
{{security_group['name']}}{{rule['name']}}:
|
Type: "AWS::EC2::SecurityGroup{{rule['rule_type']}}"
|
Properties:
|
GroupId:
|
Fn::GetAtt:
|
- "{{security_group['name']}}"
|
- GroupId
|
IpProtocol: {{rule['protocol']}}
|
FromPort: {{rule['from_port']}}
|
ToPort: {{rule['to_port']}}
|
{% if rule['cidr'] is defined %}
|
CidrIp: "{{rule['cidr']}}"
|
{% endif %}
|
{% if rule['group'] is defined %}
|
SourceSecurityGroupId:
|
Fn::GetAtt:
|
- "{{rule['group']}}"
|
- GroupId
|
{% endif %}
|
{% endfor %}
|
{% endfor %}
|
|
zoneinternalidns:
|
Type: "AWS::Route53::HostedZone"
|
Properties:
|
Name: "{{ zone_internal_dns }}"
|
VPCs:
|
- VPCId:
|
Ref: Vpc
|
VPCRegion:
|
Ref: "AWS::Region"
|
HostedZoneConfig:
|
Comment: "Created By ansible agnostic deployer"
|
BastionDNS:
|
Type: "AWS::Route53::RecordSetGroup"
|
DependsOn:
|
- BastionEIP
|
Properties:
|
HostedZoneId: "{{HostedZoneId}}"
|
RecordSets:
|
- Name: "bastion.{{subdomain_base}}."
|
Type: A
|
TTL: 10
|
ResourceRecords:
|
- "Fn::GetAtt":
|
- Bastion
|
- PublicIp
|
Bastion:
|
Type: "AWS::EC2::Instance"
|
Properties:
|
ImageId:
|
"Fn::FindInMap":
|
- RegionMapping
|
- Ref: "AWS::Region"
|
- RHELAMI
|
InstanceType: "{{bastion_instance_type}}"
|
KeyName: "{{key_name}}"
|
SecurityGroupIds:
|
- "Fn::GetAtt":
|
- BastionSG
|
- GroupId
|
SubnetId:
|
Ref: PublicSubnet
|
Tags:
|
- Key: Name
|
Value: bastion
|
- Key: AnsibleGroup
|
Value: bastions
|
- Key: Project
|
Value: "{{project_tag}}"
|
- Key: "{{project_tag}}"
|
Value: bastion
|
- Key: internaldns
|
Value: "bastion.{{chomped_zone_internal_dns}}"
|
- Key: owner
|
Value: "{{ email | default('unknown')}}"
|
BastionEIP:
|
Type: "AWS::EC2::EIP"
|
DependsOn:
|
- VpcGA
|
Properties:
|
InstanceId:
|
Ref: Bastion
|
BastionInternalDNS:
|
Type: "AWS::Route53::RecordSetGroup"
|
Properties:
|
HostedZoneId:
|
Ref: zoneinternalidns
|
RecordSets:
|
- Name: "bastion.{{zone_internal_dns}}"
|
Type: A
|
TTL: 10
|
ResourceRecords:
|
- "Fn::GetAtt":
|
- Bastion
|
- PrivateIp
|
|
{% for instance in instances %}
|
{% if instance['dns_loadbalancer']|d(false)|bool %}
|
{{instance['name']}}DNSLoadBalancer:
|
Type: "AWS::Route53::RecordSetGroup"
|
DependsOn:
|
{% for c in range(1,(instance['count'] |int)+1) %}
|
- {{instance['name']}}{{c}}EIP
|
{% endfor %}
|
Properties:
|
HostedZoneId: {{HostedZoneId}}
|
RecordSets:
|
- Name: "{{instance['name']}}.{{subdomain_base}}."
|
Type: A
|
TTL: 900
|
ResourceRecords:
|
{% for c in range(1,(instance['count'] |int)+1) %}
|
{% set instancecount = loop %}
|
- "Fn::GetAtt":
|
- {{instance['name']}}{{loop.index}}
|
- PublicIp
|
{% endfor %}
|
{% endif %}
|
|
{% for c in range(1,(instance['count'] |int)+1) %}
|
{% set instancecount = loop %}
|
#this is host {{instance['name']}}{{loop.index}}
|
|
{{instance['name']}}{{loop.index}}:
|
Type: "AWS::EC2::Instance"
|
Properties:
|
ImageId:
|
"Fn::FindInMap":
|
- RegionMapping
|
- Ref: "AWS::Region"
|
- {{ instance['image_id'] | default('RHELAMI') }}
|
|
InstanceType: "{{instance['flavor'][cloud_provider]}}"
|
KeyName: "{{instance['key_name'] | default(key_name)}}"
|
{% if instance['UserData'] is defined %}
|
{{instance['UserData']}}
|
{% endif %}
|
SecurityGroupIds:
|
- "Fn::GetAtt":
|
- {{instance['security_group']}}
|
- GroupId
|
SubnetId:
|
Ref: PublicSubnet
|
Tags:
|
- Key: Name
|
Value: {{instance['name']}}{{instancecount.index}}
|
- Key: internaldns
|
Value: {{instance['name']}}{{loop.index}}.{{chomped_zone_internal_dns}}
|
- Key: "owner"
|
Value: "{{ email | default('unknownuser') }}"
|
- Key: "Project"
|
Value: "{{project_tag}}"
|
- Key: "{{project_tag}}"
|
Value: "{{ instance['name'] }}"
|
{% for tag in instance['tags'] %}
|
- Key: {{tag['key']}}
|
Value: {{tag['value']}}
|
{% endfor %}
|
BlockDeviceMappings:
|
- DeviceName: "/dev/sda1"
|
Ebs:
|
VolumeSize: 50
|
- DeviceName: "/dev/xvdb"
|
Ebs:
|
VolumeType: gp2
|
VolumeSize: 20
|
{{instance['name']}}{{loop.index}}InternalDNS:
|
Type: "AWS::Route53::RecordSetGroup"
|
Properties:
|
HostedZoneId:
|
Ref: zoneinternalidns
|
RecordSets:
|
- Name: "{{instance['name']}}{{loop.index}}.{{zone_internal_dns}}"
|
Type: A
|
TTL: 10
|
ResourceRecords:
|
- "Fn::GetAtt":
|
- {{instance['name']}}{{loop.index}}
|
- PrivateIp
|
{% if instance['public_dns'] %}
|
{{instance['name']}}{{loop.index}}EIP:
|
Type: "AWS::EC2::EIP"
|
DependsOn:
|
- VpcGA
|
Properties:
|
InstanceId:
|
Ref: {{instance['name']}}{{loop.index}}
|
{{instance['name']}}{{loop.index}}PubliclDNS:
|
Type: "AWS::Route53::RecordSetGroup"
|
DependsOn:
|
- {{instance['name']}}{{loop.index}}EIP
|
Properties:
|
HostedZoneId: {{HostedZoneId}}
|
RecordSets:
|
- Name: "{{instance['name']}}{{loop.index}}.{{subdomain_base}}."
|
Type: A
|
TTL: 10
|
ResourceRecords:
|
- "Fn::GetAtt":
|
- {{instance['name']}}{{loop.index}}
|
- PublicIp
|
{% endif %}
|
|
{% endfor %}
|
{% endfor %}
|