sparse-intern-71089
03/12/2023, 6:53 PMacceptable-lawyer-72941
03/12/2023, 7:28 PMconst rdsSubnets = ptech_vpc.subnets.apply((subnets) => subnets
.filter((subnet) =>
subnet.tags.apply((tags) => tags?.Name === "rds")
)
.map((subnet) => subnet.id)
);
const rdsSubnetGroup = new aws.rds.SubnetGroup("rds-subnet-group", {
subnetIds: rdsSubnets,
tags: {
Environment: env,
},
});
Is this an acceptable approach or should I be doing this differently?
Thanks again.billowy-army-68599
privateSubnetIds
and publicSubnetIds
output
https://www.pulumi.com/registry/packages/awsx/api-docs/ec2/vpc/#privatesubnetids_nodejs
You can just use that, no need to do an applyacceptable-lawyer-72941
03/12/2023, 10:27 PMbillowy-army-68599
acceptable-lawyer-72941
03/12/2023, 11:01 PMcareful-family-14644
04/14/2023, 9:27 PMacceptable-lawyer-72941
04/15/2023, 1:05 PMconst rdsSubnets = ptech_vpc.subnets.apply((subnets) => subnets
.filter((subnet) =>
subnet.tags.apply((tags) => tags?.Name === "rds")
)
.map((subnet) => subnet.id)
);
const rdsSubnetGroup = new aws.rds.SubnetGroup("rds-subnet-group", {
subnetIds: rdsSubnets,
tags: {
Environment: env,
},
});
careful-family-14644
04/17/2023, 2:11 PMconst awsRegion = aws.getRegion({}).then(region => region.name);
export const eksSubnets = vpc.subnets.apply((subnets) => subnets
.filter((subnet) =>
subnet.tags.apply((tags) => tags?.Name === "dev-vpc-eks-1")
)
);
export const eksSubnets2 = vpc.subnets.apply((subnets) => subnets
.filter((subnet) =>
subnet.tags.apply((tags) => tags?.Purpose === "eks")
)
);
export const eksSubnetsIds = vpc.subnets.apply((subnets) => subnets
.filter((subnet) =>
subnet.tags.apply((tags) => tags?.Purpose === "eks")
)
.map((subnet) => subnet.id)
);
export const rdsSubnets = vpc.subnets.apply(subnets =>
subnets.filter((subnet) =>
subnet.tags.apply((tags) => {
if ((tags?.Name.indexOf("rds") ?? -1) >= 0) { return true } return false;
})
).map((subnet) => subnet.id)
);
billowy-army-68599
careful-family-14644
04/17/2023, 2:49 PMcareful-family-14644
04/17/2023, 2:49 PMcareful-family-14644
04/17/2023, 3:34 PMacceptable-lawyer-72941
04/17/2023, 5:09 PMimport * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";
const MAX_AZS = 2;
// Cluster tags for public subnets
const publicSubnetClusterTags: { [key: string]: string } = {};
publicSubnetClusterTags[`<http://kubernetes.io/cluster/clusterName`|kubernetes.io/cluster/clusterName`>] =
"shared";
publicSubnetClusterTags["<http://kubernetes.io/role/elb|kubernetes.io/role/elb>"] = "1";
// Cluster tags for private subnets
const privateSubnetClusterTags: { [key: string]: string } = {};
privateSubnetClusterTags[`<http://kubernetes.io/cluster/clusterName`|kubernetes.io/cluster/clusterName`>] =
"shared";
privateSubnetClusterTags["<http://kubernetes.io/role/internal-elb|kubernetes.io/role/internal-elb>"] = "1";
// Subnet specs
const subnetSpecs: awsx.types.input.ec2.SubnetSpecArgs[] = [
{
type: awsx.ec2.SubnetType.Public,
name: "public",
cidrMask: 24,
tags: {
Name: "public",
...publicSubnetClusterTags,
},
},
{
type: awsx.ec2.SubnetType.Private,
name: "corporate",
cidrMask: 24,
tags: {
Name: "corp-k8s",
...privateSubnetClusterTags,
},
},
{
type: awsx.ec2.SubnetType.Private,
name: "corp-rds",
cidrMask: 24,
tags: {
Group: "corp-rds",
},
},
];
export const vpc = new awsx.ec2.Vpc("corp-vpc", {
numberOfAvailabilityZones: MAX_AZS,
cidrBlock: "10.10.0.0/16",
enableDnsHostnames: true,
subnetSpecs,
tags: {
Environment: "dev",
},
});
const corpRdsSubnets = vpc.subnets.apply((subnets) =>
subnets
.filter((subnet) =>
subnet.tags.apply((tag) => tag?.Group === "corp-rds")
)
.map((subnet) => subnet.id)
);
export const corpRdsSubnetGroup = new aws.rds.SubnetGroup(
"corp-rds-subnet-group",
{
subnetIds: corpRdsSubnets,
tags: {
Environment: "dev",
},
}
);
careful-family-14644
04/17/2023, 5:36 PMexport const vpc = new awsx.ec2.Vpc(resourcePrefix + "vpc", {
...networkArgs,
numberOfAvailabilityZones: cfgNetwork.requireNumber("num-azs"),
subnetSpecs: [
{
name: "pub",
type: awsx.ec2.SubnetType.Public,
cidrMask: cfgNetwork.requireNumber("public-subnetmask"),
tags: {
"<http://kubernetes.io/role/elb|kubernetes.io/role/elb>": "1"
}
},
{
name: "eks",
type: awsx.ec2.SubnetType.Private,
cidrMask: cfgNetwork.requireNumber("private-subnetmask"),
tags: {
"<http://kubernetes.io/role/internal-elb|kubernetes.io/role/internal-elb>": "1",
Purpose: "eks"
}
},
{
name: "rds",
type: awsx.ec2.SubnetType.Private,
cidrMask: Number(cfgNetwork.requireNumber("rds-subnetmask")),
tags: {
"<http://kubernetes.io/role/internal-elb|kubernetes.io/role/internal-elb>": "1",
Purpose: "rds"
}
}
],
tags: {
Name: resourcePrefix + "vpc",
}
});
export const eksSubnetsIds = vpc.subnets.apply((subnets) =>
subnets
.filter((subnet) =>
subnet.tags.apply((tag) => tag?.Purpose === "eks")
)
.map((subnet) => subnet.id)
);
With this code I get the following returned
eksSubnetsIds : [
[0]: "subnet-0dc................................"
[1]: "subnet-0ac................................"
[2]: "subnet-0fe................................"
[3]: "subnet-05b................................"
[4]: "subnet-05d................................"
[5]: "subnet-03b................................"
]
All 6 subnets are being returned as opposed to just the 2 I'm wanting (Only 2 AZs configured in this case).acceptable-lawyer-72941
04/17/2023, 5:58 PMacceptable-lawyer-72941
04/17/2023, 10:35 PMcorpRdsSubnetGroup: {
arn : "arn:aws:rds:ca-central-1:888002373489:subgrp:corp-rds-subnet-group-3b94ada"
description : "Managed by Pulumi"
id : "corp-rds-subnet-group-3b94ada"
name : "corp-rds-subnet-group-3b94ada"
namePrefix : ""
subnetIds : [
[0]: "subnet-0458e38521bb9608a"
[1]: "subnet-0c902192e9f676853"
[2]: "subnet-0d21a2f225347805e"
[3]: "subnet-07a7cee228eaee44f"
[4]: "subnet-0c0d64a8837f9df68"
[5]: "subnet-0212cb68b71c5f704"
]
supportedNetworkTypes: [
[0]: "IPV4"
]
tags : {
Environment: "dev"
}
tagsAll : {
Environment: "dev"
}
urn : "urn:pulumi:test::help::aws:rds/subnetGroup:SubnetGroup::corp-rds-subnet-group"
}
This is the output I get when I run the above script.
I am also using only 2 AZs. and 2 AZs x 3 Subnets = 6 and all 6 are being included for some reason. The filtering is not working the way I would expect.careful-family-14644
04/18/2023, 1:01 PMwitty-candle-66007
04/18/2023, 1:43 PMPurpose
tag set to eks
?careful-family-14644
04/18/2023, 2:10 PMbillowy-army-68599
careful-family-14644
04/18/2023, 2:48 PMacceptable-lawyer-72941
04/18/2023, 2:56 PMcareful-family-14644
04/19/2023, 6:51 PMbillowy-army-68599
export const eksSubnetsIds = vpc.privateSubnetIds.apply(ids => {
let subnets = aws.ec2.getSubnetsOutput({
filters: [{
name: "tag:Purpose",
values: ["eks"]
}]
})
return subnets.ids
})
This will return the correct subnet idsbillowy-army-68599
export const eksSubnetsIds = vpc.subnets.apply((subnets) =>
subnets
.filter((subnet) =>
subnet.tags.apply((tag) => tag?.Purpose === "eks")
)
.map((subnet) => subnet.id)
);
Doesn’t work is because this: subnet.tags.apply((tag) => tag?.Purpose === "eks")
returns an Output, so you can’t run a map
operation on it, so it returns everythingcareful-family-14644
04/19/2023, 7:17 PMbillowy-army-68599
billowy-army-68599
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by