I'm trying to reference a couple of subnets to create ec2 instances but I'm sort of stuck. Let's say I have this:
const vpc = new Vpc(this, 'gwc-vpc', {
cidr: "10.20.0.0/16",
maxAzs: 3,
subnetConfiguration: [
{
subnetType: SubnetType.PRIVATE,
name: 'gossipSubnet',
cidrMask: 24
},
{
subnetType: SubnetType.PRIVATE,
name: 'dbSubnet',
cidrMask: 24
},
{
subnetType: SubnetType.PUBLIC,
name: 'extSubnet',
cidrMask: 24
}
]
})
How can I create an instance in the dbSubnet for example? Even better, what if I want to create an EC2 instance with 2 interfaces each of one is sitting in a different subnet (dbSubnet and gossipSubnet)? Any ideas?
Thanks!
Not sure if this is relevant here, but couldn't you also use the built-ins to select/target the subnet you are interested in?
const vpc = new Vpc(this, 'ProductionVPC', {
cidr: '10.10.0.0/16',
enableDnsHostnames: true,
enableDnsSupport: true,
defaultInstanceTenancy: DefaultInstanceTenancy.DEFAULT,
maxAzs: 2,
natGateways: 1,
subnetConfiguration: [
{
cidrMask: 24,
name: 'Public',
subnetType: SubnetType.PUBLIC
},
{
cidrMask: 24,
name: 'Private - Application',
subnetType: SubnetType.PRIVATE,
},
{
cidrMask: 24,
name: 'Private - Database',
subnetType: SubnetType.ISOLATED,
},
]
});
Tag.add(vpc, 'Name', 'Production VPC');
const subnets = vpc.selectSubnets({subnetType: SubnetType.Public)).subnets;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With