mammoth-machine-53860
01/08/2025, 1:16 PMstocky-restaurant-98004
01/08/2025, 4:18 PMmammoth-machine-53860
01/08/2025, 5:11 PMimport * as aws from "@pulumi/aws";
import * as pulumi from "@pulumi/pulumi";
import * as awsx from "@pulumi/awsx";
import { resourceNamePrefixer as p } from "@pick-mybrain/pmb-pulumi";
const adminStack = new pulumi.StackReference('pickmybrain/glob-infra/administrative');
const DEV_TLD_NAME = '<http://pmb.mobi|pmb.mobi>'
const DEV_TLD_ZONE_ID = 'Z0402468DWE5FS0XKI3T'
const PROD_TLD_NAME = 'pickmybrain.world'
const PROD_TLD_ZONE_ID = 'Z0178833WNXYMG3SH06P'
const availabilityZones = pulumi.output(aws.getAvailabilityZones({}));
// SHARED SERVICE INFRASTRUCTURE START
const vpc = new awsx.ec2.DefaultVpc(p('default-vpc'));
let currentCidr = 48;
const privateSubnets = availabilityZones.names.apply(zones =>
zones.map(zoneName => {
currentCidr += 16;
if (currentCidr >= 256) {
throw new Error("CIDR block third octet out of range");
}
return new aws.ec2.Subnet(p(`${zoneName}-subnet`), {
vpcId: vpc.vpcId,
cidrBlock: `172.31.${currentCidr}.0/20`,
availabilityZone: zoneName,
});
})
);
// SHARED SERVICE INFRASTRUCTURE END
const devRootZone = new aws.route53.Zone(DEV_TLD_NAME, {
name: DEV_TLD_NAME,
comment: 'HostedZone created by Route53 Registrar'
}, {
import: DEV_TLD_ZONE_ID, protect: true
});
const prodRootZone = new aws.route53.Zone(PROD_TLD_NAME, {
name: PROD_TLD_NAME,
comment: 'HostedZone from DNSSimple'
}, {
import: PROD_TLD_ZONE_ID, protect: true
});
const prodRedirectBucket = new aws.s3.Bucket('prod-s3-redirect', {
bucket: `${PROD_TLD_NAME}`,
website: {
redirectAllRequestsTo: `<https://www>.${PROD_TLD_NAME}`
}
});
const prodRedirectAccessBlock = new aws.s3.BucketPublicAccessBlock('prod-s3-redirect-block', {
bucket: prodRedirectBucket.id,
blockPublicAcls: false,
blockPublicPolicy: false,
});
const prodRedirectBucketAccessPolicy = new aws.s3.BucketPolicy(`yevai-www-s3-policy`, {
bucket: prodRedirectBucket.id,
policy: {
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: "*",
Action: ["s3:GetObject"],
Resource: pulumi.interpolate`${prodRedirectBucket.arn}/*`
}
]
}
}, { dependsOn: prodRedirectAccessBlock });
const prodRedirectCdnCert = new aws.acm.Certificate('prod-s3-redirect', {
domainName: PROD_TLD_NAME,
validationMethod: "DNS"
});
let prodAcmValidationRecord = new aws.route53.Record('prod-acm-validation-record', {
name: prodRedirectCdnCert.domainValidationOptions[0].resourceRecordName,
records: [prodRedirectCdnCert.domainValidationOptions[0].resourceRecordValue],
ttl: 60,
type: prodRedirectCdnCert.domainValidationOptions[0].resourceRecordType,
zoneId: prodRootZone.id,
}, { dependsOn: [prodRedirectCdnCert] });
let prodRedirectCdnCertValidation = new aws.acm.CertificateValidation('prod-s3-redirect-validation', {
certificateArn: prodRedirectCdnCert.arn,
validationRecordFqdns: [prodAcmValidationRecord.fqdn],
}, { dependsOn: [prodAcmValidationRecord] });
const prodRedirectCloudFront = new aws.cloudfront.Distribution('prod-redirect-cdn', {
origins: prodRedirectBucket.websiteEndpoint.apply(endpoint => {
return [{
domainName: endpoint,
originId: prodRedirectBucket.arn,
customOriginConfig: {
originProtocolPolicy: "http-only",
httpPort: 80,
httpsPort: 443,
originSslProtocols: ['TLSv1.2']
},
}]
}),
enabled: true,
isIpv6Enabled: true,
aliases: [PROD_TLD_NAME],
comment: "prod redirect CDN - do not touch",
defaultCacheBehavior: {
allowedMethods: ["GET", "HEAD"],
cachedMethods: ["GET", "HEAD"],
targetOriginId: prodRedirectBucket.arn,
viewerProtocolPolicy: "redirect-to-https",
forwardedValues: {
cookies: { forward: "none" },
queryString: false,
},
},
priceClass: "PriceClass_100",
viewerCertificate: {
acmCertificateArn: prodRedirectCdnCert.arn,
sslSupportMethod: "sni-only",
minimumProtocolVersion: "TLSv1.2_2021",
},
restrictions: {
geoRestriction: {
restrictionType: "none",
},
},
}, { dependsOn: [prodRedirectCdnCertValidation]});
const prodRedirectAlias = new aws.route53.Record('prod-redirect-alias', {
zoneId: prodRootZone.id,
name: PROD_TLD_NAME,
type: 'A',
aliases: [{
name: prodRedirectCloudFront.domainName,
zoneId: prodRedirectCloudFront.hostedZoneId,
evaluateTargetHealth: false,
}]
});
// Refactor this to be:
// accept list of target arns
// accept list of target permissions
// bind to cross account roles / policies.
const route53CrossAccountTargetArns = [
// devRootZone.arn, - TODO: deploy to this zone if the stack mode in ESC config is not production.
prodRootZone.arn,
"arn:aws:route53:::change/*"
]
const route53CrossAccountAllowedActions = [
"route53:ChangeResourceRecordSets",
"route53:GetChange",
"route53:GetHostedZone",
"route53:ListHostedZones",
"route53:ListResourceRecordSets"
]
const crossAccountAllowedArns = adminStack.getOutput('crossAccountPermissionPolicyTargets');
const route53AccessRole = new aws.iam.Role('r53-access-role', {
name: 'r53-access-role', // binds all target Arns to assume this specific role
assumeRolePolicy: crossAccountAllowedArns.apply(sourceArns => {
return JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Principal: {
AWS: sourceArns
},
Action: "sts:AssumeRole"
}]
})
})});
const route53AccessPolicy = new aws.iam.Policy('r53-access-policy', {
name: 'r53-access-policy', // This should basically be
policy: pulumi.all(route53CrossAccountTargetArns).apply(targetArns => {
return JSON.stringify({
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": route53CrossAccountAllowedActions,
"Resource": targetArns
}
]
})
})
});
const route53AccessPolicyAttachment = new aws.iam.RolePolicyAttachment('r53-access-attachment', {
role: route53AccessRole.name,
policyArn: route53AccessPolicy.arn
});
interface TenantInfo {
awsAccountId: pulumi.Output<string>;
awsAccountName: pulumi.Output<string>;
iamRoleArn: pulumi.Output<string>;
iamUserArn: pulumi.Output<string>;
}
interface ActiveTenantInfo {
[key: string]: pulumi.Output<TenantInfo>;
}
export const prodRootZoneId = prodRootZone.id;
export const prodRootZoneArn = prodRootZone.arn;
export const route53AccessRoleArn = route53AccessRole.arn;
// Hydrate ESC "glob-infra-administrative" tenant AWS account info with "glob-infra:shared" keyof ESC "glob-infra-engineering"
const engineeringSharedServicesConfig = (new pulumi.Config()).requireObject("shared") as {[key: string]: {}};
export const activeSharedInfo = pulumi.all(adminStack.getOutput('activeSharedInfo') as unknown as ActiveTenantInfo).apply(o => {
return Object.keys(o).map(tenantKey => {
return { [`${tenantKey}`]: {
...o[tenantKey],
...engineeringSharedServicesConfig[tenantKey]
}
};
})
}).apply(accounts => accounts.reduce((accumulator, current) => {
accumulator[Object.keys(current)[0]] = current[Object.keys(current)[0]]
return accumulator;
}));
// Hydrate ESC "glob-infra-administrative" shared AWS account info with "glob-infra:tenants" keyof ESC "glob-infra-engineering"
const engineeringTenantConfig = (new pulumi.Config()).requireObject("tenants") as {[key: string]: {}};
export const activeTenantInfo = pulumi.all(adminStack.getOutput('activeTenantInfo') as unknown as ActiveTenantInfo).apply(o => {
return Object.keys(o).map(tenantKey => {
return { [`${tenantKey}`]: {
...o[tenantKey],
...engineeringTenantConfig[tenantKey]
}
};
})
}).apply(accounts => accounts.reduce((accumulator, current) => {
accumulator[Object.keys(current)[0]] = current[Object.keys(current)[0]]
return accumulator;
}));
module.exports['vpcPrivateSubnetIds'] = privateSubnets.apply(subnets => subnets.map(subnet => subnet.id))
module.exports['vpcPublicSubnetIds'] = vpc.publicSubnetIds;
mammoth-machine-53860
01/08/2025, 5:12 PMstocky-restaurant-98004
01/08/2025, 5:22 PMmammoth-machine-53860
01/08/2025, 5:49 PMstocky-restaurant-98004
01/08/2025, 6:19 PMmammoth-machine-53860
01/08/2025, 6:36 PMstocky-restaurant-98004
01/08/2025, 6:41 PMmammoth-machine-53860
01/09/2025, 3:11 AMmammoth-machine-53860
01/09/2025, 4:20 AMmammoth-machine-53860
01/09/2025, 4:23 AMmammoth-machine-53860
01/09/2025, 4:24 AMmammoth-machine-53860
01/09/2025, 4:24 AMmammoth-machine-53860
01/09/2025, 4:24 AMmammoth-machine-53860
01/09/2025, 4:24 AMmammoth-machine-53860
01/09/2025, 8:15 AM