Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// VPC
const vpcTags = Object.assign({
Name: `${inputs.description} VPC`,
}, inputs.baseTags);
const vpc = new aws.ec2.Vpc(`${baseName}-vpc`, {
cidrBlock: inputs.baseCidr,
enableDnsSupport: true,
enableDnsHostnames: true,
tags: vpcTags,
}, instanceParent);
instance.vpcId = vpc.id;
const vpcParent = {parent: vpc};
// Private Hosted Zone
if (inputs.zoneName !== "") {
const privateZone = new aws.route53.Zone(`${baseName}-private-hosted-zone`, {
vpcId: vpc.id,
name: inputs.zoneName,
comment: `Private zone for ${inputs.zoneName}. Managed by Pulumi.`,
}, vpcParent);
instance.privateHostedZoneId = privateZone.id;
const dhcpOptionSetTags = Object.assign({
Name: `${inputs.description} DHCP Options`,
}, inputs.baseTags);
const dhcpOptionSet = new aws.ec2.VpcDhcpOptions(`${baseName}-dhcp-options`, {
domainName: "",
domainNameServers: ["AmazonProvidedDNS"],
tags: dhcpOptionSetTags,
}, vpcParent);
const dhcpOptionSetParent = {parent: dhcpOptionSet};
enableDnsSupport: true,
enableDnsHostnames: true,
tags: this.resourceTags({
Name: `${args.description} VPC`,
}),
}, { parent: this });
// Internet Gateway
this.internetGateway = new aws.ec2.InternetGateway(`${name}-igw`, {
vpcId: this.vpc.id,
tags: this.resourceTags({
Name: `${args.description} VPC Internet Gateway`,
}),
}, { parent: this.vpc });
// Private Hosted Zone and DHCP Options
if (args.zoneName) {
this.privateZone = new aws.route53.Zone(`${name}-private-zone`, {
vpcs: [{
vpcId: this.vpc.id,
}],
name: args.zoneName,
comment: `Private zone for ${args.zoneName}. Managed by Pulumi.`,
}, { parent: this });
this.dhcpOptionSet = new aws.ec2.VpcDhcpOptions(`${name}-dhcp-options`, {
domainName: this.privateZone.name,
domainNameServers: ["AmazonProvidedDNS"],
tags: this.resourceTags({
Name: `${args.description} DHCP Options`,
}),
}, { parent: this.vpc });
new aws.ec2.VpcDhcpOptionsAssociation(`${name}-dhcp-options-assoc`, {
vpcId: this.vpc.id,
dhcpOptionsId: this.dhcpOptionSet.id,
// Create an HTTP Endpoint.
let endpoint = new awscloud.API("endpoint");
endpoint.get("/", async (req, res) => {
res.json(req);
});
// Attach our custom domain using the AWS-specific ACM certificate.
endpoint.attachCustomDomain({
domainName: subdomain + "." + domainName,
certificateArn: certficateArn,
});
let deployment = endpoint.publish();
// Add a DNS CNAME record for the subdomain pointing to the API custom domain.
let recordSet = new aws.route53.Record(subdomain, {
name: subdomain,
zoneId: hostedZoneId,
type: "A",
aliases: [{
name: deployment.customDomains[0].cloudfrontDomainName,
zoneId: deployment.customDomains[0].cloudfrontZoneId,
evaluateTargetHealth: false,
}]
});
// Export the custom domain URL for the HTTP Endpoint.
export let url = pulumi.interpolate `https://${recordSet.fqdn}/`;
const baseName = name.toLowerCase();
// VPC
const vpcTags = Object.assign({
Name: `${inputs.description} VPC`,
}, inputs.baseTags);
const vpc = new aws.ec2.Vpc(`${baseName}-vpc`, {
cidrBlock: inputs.baseCidr,
enableDnsSupport: true,
enableDnsHostnames: true,
tags: vpcTags,
}, instanceParent);
instance.vpcId = vpc.id;
const vpcParent = { parent: vpc };
// Private Hosted Zone
if (inputs.zoneName !== "") {
const privateZone = new aws.route53.Zone(`${baseName}-private-hosted-zone`, {
vpcId: vpc.id,
name: inputs.zoneName,
comment: `Private zone for ${inputs.zoneName}. Managed by Pulumi.`,
}, vpcParent);
instance.privateHostedZoneId = privateZone.id;
const dhcpOptionSetTags = Object.assign({
Name: `${inputs.description} DHCP Options`,
}, inputs.baseTags);
const dhcpOptionSet = new aws.ec2.VpcDhcpOptions(`${baseName}-dhcp-options`, {
domainName: "",
domainNameServers: ["AmazonProvidedDNS"],
tags: dhcpOptionSetTags,
}, vpcParent);
const dhcpOptionSetParent = { parent: dhcpOptionSet };
new aws.ec2.VpcDhcpOptionsAssociation(`${baseName}-dhcp-options-assoc`, {
vpcId: vpc.id,
function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): aws.route53.Record {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZoneId = aws.route53.getZone({ name: domainParts.parentDomain }, { async: true }).then(zone => zone.zoneId);
return new aws.route53.Record(
targetDomain,
{
name: domainParts.subdomain,
zoneId: hostedZoneId,
type: "A",
aliases: [
{
name: distribution.domainName,
zoneId: distribution.hostedZoneId,
evaluateTargetHealth: true,
},
],
});
}
async function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): Promise {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZone = await aws.route53.getZone({ name: domainParts.parentDomain });
return new aws.route53.Record(
targetDomain,
{
name: domainParts.subdomain,
zoneId: hostedZone.zoneId,
type: "A",
aliases: [
{
name: distribution.domainName,
zoneId: distribution.hostedZoneId,
evaluateTargetHealth: true,
},
],
});
}
const aRecord = createAliasRecord(config.targetDomain, cdn);
async function aliasToCloudFront(
domain: string, subdomain: string,
cdn: aws.cloudfront.Distribution): Promise {
const targetDomain = cdn.domainName;
const cdnZoneId = cdn.hostedZoneId;
const hostedZone = await aws.route53.getZone({ name: domain });
const aRecord: aws.route53.Record = new aws.route53.Record(
`A-record-${subdomain}.${domain}`,
{
name: subdomain,
zoneId: hostedZone.zoneId,
type: "A",
aliases: [
{
name: targetDomain,
zoneId: cdnZoneId,
evaluateTargetHealth: true,
},
],
});
return aRecord;
function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): aws.route53.Record {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZoneId = aws.route53.getZone({ name: domainParts.parentDomain }, { async: true }).then(zone => zone.zoneId);
return new aws.route53.Record(
targetDomain,
{
name: domainParts.subdomain,
zoneId: hostedZoneId,
type: "A",
aliases: [
{
name: distribution.domainName,
zoneId: distribution.hostedZoneId,
evaluateTargetHealth: true,
},
],
});
}
async function createAliasRecord(
targetDomain: string, distribution: aws.cloudfront.Distribution): Promise {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZone = await aws.route53.getZone({ name: domainParts.parentDomain });
return new aws.route53.Record(
targetDomain,
{
name: domainParts.subdomain,
zoneId: hostedZone.zoneId,
type: "A",
aliases: [
{
name: distribution.domainName,
zoneId: distribution.hostedZoneId,
evaluateTargetHealth: true,
},
],
});
}
const aRecord = createAliasRecord(config.targetDomain, cdn);