def create_internal_zone(self): t = self.template variables = self.get_variables() self.zone = variables["InternalZone"] if self.zone: hosted_zone_vpc = route53.HostedZoneVPCs( VPCId=self.vpc.Ref(), VPCRegion=Region, ) self.zone.VPCs = [ hosted_zone_vpc, ] t.add_resource(self.zone) t.add_output(Output( "InternalZoneId", Value=self.zone.Ref(), )) t.add_output(Output( "InternalZoneName", Value=self.zone.Name, ))
def create_template(self): variables = self.get_variables() hosted_zone_name = variables["HostedZoneName"] hosted_zone_id = variables["HostedZoneId"] hosted_zone_comment = variables["Comment"] if all([hosted_zone_comment, hosted_zone_id]): logger.warning( "The Comment variable works when HostedZoneName is passed." "When HostedZoneId in variables, Comment is ignored." ) if all([hosted_zone_name, hosted_zone_id]): raise ValueError("Cannot specify both 'HostedZoneName' and " "'HostedZoneId' variables.") if not any([hosted_zone_name, hosted_zone_id]): raise ValueError("Please specify either a 'HostedZoneName' or " "'HostedZoneId' variable.") if hosted_zone_id: self.hosted_zone_id = hosted_zone_id else: hosted_zone_config = route53.HostedZoneConfiguration( "HostedZoneConfiguration", Comment=hosted_zone_comment ) hosted_zone = route53.HostedZone( "HostedZone", Name=hosted_zone_name, HostedZoneConfig=hosted_zone_config ) if variables["VPC"]: vpc = route53.HostedZoneVPCs( VPCId=variables["VPC"], VPCRegion=Region ) hosted_zone.VPCs = [vpc] else: nameservers = Join(',', GetAtt(hosted_zone, "NameServers")) self.template.add_output( Output("NameServers", Value=nameservers) ) self.template.add_resource(hosted_zone) self.hosted_zone_id = Ref(hosted_zone) self.template.add_output( Output("HostedZoneId", Value=self.hosted_zone_id) ) self.create_record_set_groups(variables["RecordSetGroups"]) return self.create_record_sets(variables["RecordSets"])
def create_dns_records(self, bastion_host): private_hosted_zone = self.add_resource( r53.HostedZone('dnsPrivateHostedZone', Name=Join( '', [Ref(self.private_hosted_zone_name), '.']), VPCs=[ r53.HostedZoneVPCs(VPCId=Ref(self.vpc), VPCRegion=self.region) ])) self.add_resource( r53.RecordSetGroup( 'dnsPublicRecords', HostedZoneName=Join('', [Ref(self.public_hosted_zone_name), '.']), RecordSets=[ r53.RecordSet( 'dnsMonitoringServer', Name=Join('', [ 'monitoring.', Ref(self.public_hosted_zone_name), '.' ]), Type='A', TTL='300', ResourceRecords=[GetAtt(bastion_host, 'PublicIp')]) ])) self.add_resource( r53.RecordSetGroup( 'dnsPrivateRecords', HostedZoneId=Ref(private_hosted_zone), RecordSets=[ r53.RecordSet( 'dnsBastionHost', Name=Join('', [ 'monitoring.service.', Ref(self.private_hosted_zone_name), '.' ]), Type='A', TTL='10', ResourceRecords=[GetAtt(bastion_host, 'PrivateIp')]) ])) return private_hosted_zone
def add_hosted_zone(self, name, region): """ Helper that creates a hosted zone @param name [string] name of the private hosted zone that will be attached to the vpc @param region [string] name of the region, as if it could be different than the vpc's """ return self.add_resource( route53.HostedZone( "PrivateHostedZone", HostedZoneConfig=route53.HostedZoneConfiguration( Comment="Private HostedZone"), Name=name, VPCs=[ route53.HostedZoneVPCs(VPCId=Ref(self.vpc_id), VPCRegion=region) ]))
def create_internal_zone(self): t = self.template variables = self.get_variables() if variables["InternalDomain"]: t.add_resource( route53.HostedZone("InternalZone", Name=variables["InternalDomain"], VPCs=[ route53.HostedZoneVPCs( VPCId=VPC_ID, VPCRegion=Ref("AWS::Region")) ])) t.add_output(Output( "InternalZoneId", Value=Ref("InternalZone"), )) t.add_output( Output( "InternalZoneName", Value=variables["InternalDomain"], ))
def build_template(self): t = self._init_template() zone = t.add_resource( route53.HostedZone("{}HostedZone".format(self.name), Name=self.domain_name)) if self.vpc: vpc_param = ensure_param(t, self.vpc.output_vpc()) zone.VPCs = [ route53.HostedZoneVPCs(VPCId=Ref(vpc_param), VPCRegion=Ref("AWS::Region")) ] group = t.add_resource( route53.RecordSetGroup( "{}RecordGroup".format(self.name), HostedZoneId=Ref(zone), DependsOn=zone, RecordSets=[rs.add_to_template(t) for rs in self.records])) return t
CidrBlock=options.cidr, EnableDnsHostnames=True, Tags=Tags( Application=Ref("AWS::StackId"), ), )) HostedZone = t.add_resource(route53.HostedZone( "HostedZone", HostedZoneConfig=route53.HostedZoneConfiguration( Comment="Cell hosted zone" ), Name=Join("", cell_domain()), VPCs=[ route53.HostedZoneVPCs( VPCId=Ref(VPC), VPCRegion=Ref("AWS::Region") ) ] )) # region domain is ec2.internal in us-east-1, REGION.compute.internal for # others, according to # http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_DHCP_Options.html DHCP = t.add_resource(ec2.DHCPOptions( 'DHCP', DomainName=If( "RegionIsUsEast1", "ec2.internal", Join("", [Ref("AWS::Region"), ".compute.internal"]) ), DomainNameServers=['AmazonProvidedDNS']
def hosted_zone(self): return route53.HostedZone( 'PilosaZone', Name=Join('', [Ref(self.cluster_name), '.{domain}'.format(domain=self.domain)]), VPCs=[route53.HostedZoneVPCs(VPCId=Ref(self.vpc), VPCRegion=Ref('AWS::Region'))])