amplify-education / serverless-vpc-discovery

Serverless plugin for discovering VPC / Subnet / Security Group configuration by name.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support wildcard lookup

jalaziz opened this issue · comments

When looking up subnet IDs, there is a step to "[Compare] the valid subnets with ones given to find invalid subnet names". This validation prevents using wildcards in the subnet names.

For example, instead of listing all subnets explicitly, I'd like to have a configuration that looks like:

vpc:
  vpcName: dev
  subnetNames:
    - 'dev-private-*'

We're having the same issue. We use our own fork from a way earlier stage of this repo. For us the wildcard lookup accidentally works. When we tried to go back to the base, instead of our fork, we noticed that wildcards are not supported

@rddimon Is there a reason why subnetNames and securityGroupNames are filtered out manually? They should be already filtered out correctly by the Filter when using AWS API

const missingSubnetNames = subnetNames.filter((subnetName) => {
// collect subnets by name
const subnetsByName = subnets.filter((subnet) => {
const nameTag = subnet.Tags.find((tag) => tag.Key === "Name");
return nameTag.Value === subnetName;
});
return subnetsByName.length === 0;
});

const missingGroupsNames = securityGroupNames.filter((groupName) => {
// collect security groups by name
const securityGroupsByName = securityGroups.filter((securityGroup) => {
return securityGroup.GroupName === groupName;
});
return securityGroupsByName.length === 0;
});

If the reason for this is that we want to make sure we have subnets matching each line in the configuration, then this logic needs to be smarter and support wildcards

Hi @RLRabinowitz
Thank you for your question.

This logic for excluding the case when you specify a subnet name or security group name but there are no items found
So we need to check if names are correct or remove the not existing name

Got it.

So in order to support wildcards, the pieces of code I referred to above should lookup with a regex matching AWS wildcard logic, instead of matching of exact name.

I might create a PR for this

I've started working on a PR, and when I worked on the tests I noticed that there are issues with them.
I've opened a PR to fix the tests as a prerequisite to this fix