Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Created January 15, 2020 15:39
Show Gist options
  • Save nsisodiya/d3535c78c8c95499b7efcd5805f8bda7 to your computer and use it in GitHub Desktop.
Save nsisodiya/d3535c78c8c95499b7efcd5805f8bda7 to your computer and use it in GitHub Desktop.
problem with hostedZoneId
const router = new k8s.networking.v1beta1.Ingress(
'syngenta-platform',
{
metadata: {
name: 'syngenta-platform',
labels: {
app: 'syngenta-platform'
},
namespace: synPlatformNS.metadata.name,
annotations: {
// 'alb.ingress.kubernetes.io/healthcheck-protocol': 'HTTP', // TODO it should be https, I guesss
// 'alb.ingress.kubernetes.io/success-codes': '200',
// 'alb.ingress.kubernetes.io/healthcheck-interval-seconds': '10',
// 'alb.ingress.kubernetes.io/healthcheck-path': '/health',
// 'alb.ingress.kubernetes.io/healthcheck-port': '80',
'kubernetes.io/ingress.class': 'alb',
'alb.ingress.kubernetes.io/scheme': 'internet-facing'
}
},
spec: {
rules: [
{
host: 'api.syn-platform.com', // TODO what is this?
http: {
paths: [
{
path: '/ndvi/*',
backend: {
serviceName: syngentaPlatformNdvi.service.metadata.name,
servicePort: 'http'
}
},
{
path: '/ngnix/*',
backend: {
serviceName: syngentaPlatformNgnix.service.metadata.name,
servicePort: 'http'
}
}
]
}
}
]
}
},
{
provider: synPlatformCluster.provider
}
);
export let ingressUrl = router.status.loadBalancer.ingress[0].hostname;
// Split a domain name into its subdomain and parent domain names.
// e.g. "www.example.com" => "www", "example.com".
function getDomainAndSubdomain(domain: string): { subdomain: string; parentDomain: string } {
const parts = domain.split('.');
if (parts.length < 2) {
throw new Error(`No TLD found on ${domain}`);
}
// No subdomain, e.g. awesome-website.com.
if (parts.length === 2) {
return { subdomain: '', parentDomain: domain };
}
const subdomain = parts[0];
parts.shift(); // Drop first element.
return {
subdomain,
// Trailing "." to canonicalize domain.
parentDomain: parts.join('.') + '.'
};
}
function createAliasRecord(targetDomain: string, url: pulumi.Output<string>): aws.route53.Record {
const domainParts = getDomainAndSubdomain(targetDomain);
const hostedZoneId = aws.route53
.getZone({ name: domainParts.parentDomain }, { async: true })
.then((zone) => zone.zoneId);
const domainPartsALB = getDomainAndSubdomain(url);
const hostedZoneIdALB = aws.route53
.getZone({ name: domainPartsALB.parentDomain }, { async: true })
.then((zone) => zone.zoneId);
return new aws.route53.Record(targetDomain, {
name: domainParts.subdomain,
zoneId: hostedZoneId,
type: 'A',
aliases: [
{
name: url,
zoneId: hostedZoneIdALB, // TODO, how to get it, need to be checked.
evaluateTargetHealth: false
}
]
});
}
export let aRecord = createAliasRecord('api.syn-platform.com', ingressUrl);
@nsisodiya
Copy link
Author

Line 80 --> const domainPartsALB = getDomainAndSubdomain(url);
is giving error - Argument of type 'Output<string>' is not assignable to parameter of type 'string'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment