alert-monitor-93874
08/27/2019, 9:09 AMconst subnetIds = [
...vpc.privateSubnetIds,
...vpc.publicSubnetIds,
];
const cluster = new eks.Cluster(name, {
deployDashboard: false,
enabledClusterLogTypes: ['api', 'audit', 'authenticator', 'controllerManager', 'scheduler'],
instanceRoles: [role],
skipDefaultNodeGroup: true,
subnetIds,
vpcId: vpc.id,
}, { dependsOn: [vpc] });
I then need to go back through all the subnets and add a tag <http://kubernetes.io/cluster/<cluster-name>:shared|kubernetes.io/cluster/<cluster-name>:shared>
, but I don't see how I can go back over the existing subnets to add the tags.
Does anyone know the correct way to do this?glamorous-printer-66548
08/27/2019, 7:53 PMalert-monitor-93874
08/27/2019, 8:51 PMimport { VpcSubnetArgs } from '@pulumi/awsx/ec2';
import { Netmask } from 'netmask';
interface Zone {
id: string;
privateSubnet: VpcSubnetArgs;
publicSubnet: VpcSubnetArgs;
}
function privateSubnet(zoneId: string, cidr: Netmask): VpcSubnetArgs {
return {
location: {
availabilityZoneId: zoneId,
cidrBlock: cidr.toString(),
},
mapPublicIpOnLaunch: false,
name: `${zoneId}-private`,
tags: {
'<http://kubernetes.io/role/internal-elb|kubernetes.io/role/internal-elb>': '1',
},
type: 'private',
};
}
function publicSubnet(zoneId: string, cidr: Netmask): VpcSubnetArgs {
return {
location: {
availabilityZoneId: zoneId,
cidrBlock: cidr.toString(),
},
mapPublicIpOnLaunch: true,
name: `${zoneId}-public`,
tags: {
'<http://kubernetes.io/role/elb|kubernetes.io/role/elb>': '1',
},
type: 'public',
};
}
export function createSubnets(zoneIds: string[], cidr: Netmask): VpcSubnetArgs[] {
// define a public & private subnet for each zone
const { zones } = zoneIds.reduce((acc, id) => {
const { privateBlock, publicBlock } = acc;
return {
privateBlock: privateBlock.next(),
publicBlock: publicBlock.next(),
zones: [...acc.zones, {
id,
privateSubnet: privateSubnet(id, privateBlock),
publicSubnet: publicSubnet(id, publicBlock),
}],
};
}, {
privateBlock: new Netmask(`${cidr.base}/20`).next(),
publicBlock: new Netmask(`${cidr.base}/24`).next(),
zones: [],
} as { privateBlock: Netmask, publicBlock: Netmask, zones: Zone[] });
// return array of public and private subnets
return zones.reduce((all, zone) => ([
...all,
zone.privateSubnet,
zone.publicSubnet,
]), [] as VpcSubnetArgs[]);
}
and being called
export function createVpc(name: string, options: VpcOptions) {
const { networkBlock, tags } = options;
const cidr = networkBlock.toString();
const { zoneIds } = aws.getAvailabilityZones();
zoneIds.sort();
const subnets = createSubnets(zoneIds, networkBlock);
const vpc = new awsx.ec2.Vpc(name, {
cidrBlock: cidr,
numberOfAvailabilityZones: 'all',
subnets,
tags: {
...tags,
Name: name,
},
});
return { cidr, subnets, vpc };
}
chilly-crayon-57653
08/28/2019, 9:06 PMalert-monitor-93874
08/28/2019, 9:09 PM