forked from dxctechnology/dxcf-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon-PublicHostedZone.yaml
165 lines (165 loc) · 5.92 KB
/
Common-PublicHostedZone.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Description: Common-PublicHostedZone Template.
This creates a Public HostedZone.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Stack Dependencies
Parameters:
- DomainFunctionsStackName
- Label:
default: Environment Configuration
Parameters:
- EnvironmentName
- Label:
default: HostedZone Configuration
Parameters:
- PublicDomain
- Label:
default: Integration Configuration
Parameters:
- AccountId
- UseHostedZoneDelegation
- UseDomainNameServers
ParameterLabels:
DomainFunctionsStackName:
default: DomainFunctions Stack Name
EnvironmentName:
default: Environment Name
PublicDomain:
default: PublicDomain
AccountId:
default: Account Id
UseHostedZoneDelegation:
default: Use HostedZone Delegation Method
UseDomainNameServers:
default: Use Domain NameServers Method
Parameters:
DomainFunctionsStackName:
Description: Name of the CloudFormation Stack containing the Domain Functions
Type: String
MinLength: 8
MaxLength: 64
Default: DomainFunctions
AllowedPattern: ^[A-Z][-a-zA-Z0-9]*$
ConstraintDescription: must begin with an upper case letter and contain alphanumeric characters and dashes.
EnvironmentName:
Description: Name of the Environment associated with the Stack
Type: String
Default: Production
AllowedValues:
- Production
- Staging
- UAT
- QA
- Testing
- Development
- Build
- Core
- Recovery
- Log
- Identity
- Management
- Organization
ConstraintDescription: must be Production, Staging, UAT, QA, Testing, Development, Build, Core, Recovery, Log, Identity, Management or Organization.
PublicDomain:
Description: Public Domain associated with the Stack
Type: String
MinLength: 7
MaxLength: 64
Default: us-west-2.dxcp.technology
AllowedPattern: ^((?!-)[a-z0-9-]{1,63}(?<!-)\.)+[a-z]{2,10}$
ConstraintDescription: must be a valid domain name and contain only lower-case letters, numbers, dashes and periods.
AccountId:
Description: Optional Account which contains the Parent HostedZone or Matching Registered Domain
Type: String
Default: ''
AllowedPattern: (^$|^[0-9]{12}$)
ConstraintDescription: must be a valid 12-digit AWS Account Id, if specified. Leave blank to use current Account Id.
UseHostedZoneDelegation:
Description: Create a Sub-Domain Delegation in a Parent HostedZone
Type: String
Default: false
AllowedValues:
- true
- false
ConstraintDescription: must be either true or false.
UseDomainNameServers:
Description: Update the NameServers in a matching Registered Domain
Type: String
Default: false
AllowedValues:
- true
- false
ConstraintDescription: must be either true or false.
Rules:
UseSingleIntegrationMethod:
Assertions:
- Assert: !Not [ !And [ !Equals [ !Ref UseHostedZoneDelegation, 'true' ], !Equals [ !Ref UseDomainNameServers, 'true' ]]]
AssertDescription: UseHostedZoneDelegation and UseDomainNameServers can not both be set to true
Conditions:
ConfigureAccountId: !Not [ !Equals [ !Ref AccountId, '' ]]
ConfigureHostedZoneDelegation: !And [ !Equals [ !Ref UseHostedZoneDelegation, true ], !Not [ !Condition ConfigureAccountId ]]
ConfigureHostedZoneDelegationProxy: !And [ !Equals [ !Ref UseHostedZoneDelegation, true ], !Condition ConfigureAccountId ]
ConfigureDomainNameServers: !And [ !Equals [ !Ref UseDomainNameServers, true ], !Not [ !Condition ConfigureAccountId ]]
ConfigureDomainNameServersProxy: !And [ !Equals [ !Ref UseDomainNameServers, true ], !Condition ConfigureAccountId ]
Resources:
PublicHostedZone:
Type: AWS::Route53::HostedZone
Properties:
HostedZoneConfig:
Comment: !Sub Public Zone for ${PublicDomain}
Name: !Sub ${PublicDomain}.
HostedZoneTags:
- Key: Name
Value: !Sub ${EnvironmentName}-PublicHostedZone
PublicHostedZoneDelegation:
Type: Custom::HostedZoneDelegation
Properties:
ServiceToken: !ImportValue
Fn::Sub: ${DomainFunctionsStackName}-HostedZoneDelegationFunctionArn
DomainName: !Ref PublicDomain
NameServers: !GetAtt PublicHostedZone.NameServers
DependsOn: PublicHostedZone
Condition: ConfigureHostedZoneDelegation
PublicHostedZoneDelegationProxy:
Type: Custom::HostedZoneDelegationProxy
Properties:
ServiceToken: !ImportValue
Fn::Sub: ${DomainFunctionsStackName}-HostedZoneDelegationProxyFunctionArn
AccountId: !Ref AccountId
DomainName: !Ref PublicDomain
NameServers: !GetAtt PublicHostedZone.NameServers
DependsOn: PublicHostedZone
Condition: ConfigureHostedZoneDelegationProxy
PublicDomainNameServers:
Type: Custom::DomainNameServers
Properties:
ServiceToken: !ImportValue
Fn::Sub: ${DomainFunctionsStackName}-DomainNameServersFunctionArn
DomainName: !Ref PublicDomain
NameServers: !GetAtt PublicHostedZone.NameServers
DependsOn: PublicHostedZone
Condition: ConfigureDomainNameServers
PublicDomainNameServersProxy:
Type: Custom::DomainNameServersProxy
Properties:
ServiceToken: !ImportValue
Fn::Sub: ${DomainFunctionsStackName}-DomainNameServersProxyFunctionArn
AccountId: !Ref AccountId
DomainName: !Sub ${PublicDomain}.
NameServers: !GetAtt PublicHostedZone.NameServers
DependsOn: PublicHostedZone
Condition: ConfigureDomainNameServersProxy
Outputs:
PublicDomain:
Description: The PublicDomain
Value: !Ref PublicDomain
Export:
Name: !Sub ${AWS::StackName}-PublicDomain
PublicHostedZone:
Description: The PublicHostedZone
Value: !Ref PublicHostedZone
Export:
Name: !Sub ${AWS::StackName}-PublicHostedZone