forked from org-formation/org-formation-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subdomains.yml
91 lines (73 loc) · 2.81 KB
/
subdomains.yml
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
AWSTemplateFormatVersion: '2010-09-09-OC'
# Include file that contains Organization Section.
# The Organization Section describes Accounts, Organizational Units, etc.
Organization: !Include ../organization.yml
# Any Binding that does not explicitly specify a region will default to this.
# Value can be either string or list
DefaultOrganizationBindingRegion: eu-central-1
Parameters:
resourcePrefix:
Type: String
Default: my
rootHostedZoneName:
Type: String
# Section contains a named set of Bindings.
# Bindings determine what resources are deployed where
# These bindings can be !Ref'd from the Resources in the resource section
OrganizationBindings:
# binding for HostedZone, HostedZoneIdParam, HostedZoneNameParam
HostedZoneBinding:
AccountsWithTag: subdomain
# binding for RootHostedZone, ParentNsRecord
RootHostedZoneBinding:
IncludeMasterAccount: true
Resources:
#=========================================#
# Zone
#=========================================#
HostedZone:
Type: AWS::Route53::HostedZone
OrganizationBinding: !Ref HostedZoneBinding
Properties:
HostedZoneConfig:
Comment: Domain Hosted Zone
Name: !Sub '${AWSAccount.Tags.subdomain}.${rootHostedZoneName}.'
HostedZoneIdParam:
Type: AWS::SSM::Parameter
OrganizationBinding: !Ref HostedZoneBinding
Properties:
Name: !Sub '${resourcePrefix}-domains-hosted-zone-id'
Type: String
Value: !GetAtt AWSAccount.Resources.HostedZone
HostedZoneNameParam:
Type: AWS::SSM::Parameter
OrganizationBinding: !Ref HostedZoneBinding
Properties:
Name: !Sub '${resourcePrefix}-domains-hosted-zone-name'
Type: String
Value: !Sub '${AWSAccount.Tags.subdomain}.${rootHostedZoneName}.'
#=========================================#
# Parent Record
#=========================================#
RootHostedZone:
Type: AWS::Route53::HostedZone
OrganizationBinding: !Ref RootHostedZoneBinding
Properties:
HostedZoneConfig:
Comment: Root domain
Name: !Ref rootHostedZoneName
# be aware that changing the logicalName for a AWS::Route53::RecordSet resource
# might result in the Record being deleted. this unfortunately seems to be a cloudformation issue
# described here: https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/364
# workaround is to remove the resource and then add it.
ParentNsRecord:
DependsOn: RootHostedZone
Type: AWS::Route53::RecordSet
OrganizationBinding: !Ref RootHostedZoneBinding
ForeachAccount: !Ref HostedZoneBinding
Properties:
Type: NS
HostedZoneName: !Sub '${rootHostedZoneName}.'
Name: !Sub '${CurrentAccount.Tags.subdomain}.${rootHostedZoneName}.'
TTL: 86400
ResourceRecords: !GetAtt CurrentAccount.Resources.HostedZone.NameServers