Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add AWS VPC subnet resource #1827

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

mariuskimmina
Copy link
Contributor

#1794

first time making changes to providers, so please review carefully.
Example usage

image

I wasn't sure what kind of fields to add here. Just went with id and cidrs for now - there's probably more that could make sense.

@mariuskimmina mariuskimmina force-pushed the add-aws-vpc-subnet-resource branch 2 times, most recently from 39f3623 to 3dd30ab Compare September 21, 2023 07:11
@mariuskimmina
Copy link
Contributor Author

mariuskimmina commented Sep 21, 2023

Added the filed mapPublicIpOnLaunch which is the actual requirement for AWS security recommendation discussed in #1794

cnquery> aws.vpcs.where( arn == "arn:aws:vpc:eu-central-1:455954587013:id/vpc-091edd43468ca60e5" )[0].subnets[0].mapPublicIpOnLaunch
[ok] value: true

@mariuskimmina mariuskimmina force-pushed the add-aws-vpc-subnet-resource branch from 43fcabf to 0f9ace5 Compare September 22, 2023 05:35
Copy link
Contributor

@vjeffrey vjeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks awesome!! thank you! ✨ I'll pull it down and try it out later this morning

Copy link
Contributor

@vjeffrey vjeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add in the subnet arn, and add an id function for the subnet func (s *mqlAwsVpcSubnet) id() (string, error) { that returns the arn?

this will help ensure the objects are uniquely identifiable

@mariuskimmina
Copy link
Contributor Author

mariuskimmina commented Sep 23, 2023

I have added the arn field, I noticed a bug tho.
Currently I have 3 subnets in AWS, the output in cnquery looks like this

aws.vpcs.where[0].subnets: [
  0: aws.vpc.subnet id="subnet-021eb62bc781a5ed5"
  1: aws.vpc.subnet id="subnet-021eb62bc781a5ed5"
  2: aws.vpc.subnet id="subnet-021eb62bc781a5ed5"
]

So the number of subnets is correct but they all have the same id.
I copied this part from the exisiting routeTables function and found that the same bug exists there as well

I have 2 route tables in my aws account

cnquery> aws.vpcs.where( arn == "arn:aws:vpc:eu-central-1:455954587013:id/vpc-091edd43468ca60e5" )[0].routeTables
aws.vpcs.where[0].routeTables: [
  0: aws.vpc.routetable id="rtb-0d28b6f55dfe767c2"
  1: aws.vpc.routetable id="rtb-0d28b6f55dfe767c2"
]

I see two route tables here but they both have the same id

@vjeffrey
Copy link
Contributor

did you add in the id function?

func (s *mqlAwsVpcSubnet) id() (string, error) {
  return s.Arn.Data, nil
}

route table might also need the id fix

@mariuskimmina
Copy link
Contributor Author

did you add in the id function?

func (s *mqlAwsVpcSubnet) id() (string, error) {
  return s.Arn.Data, nil
}

route table might also need the id fix

Ah, adding the id function does seem to fix it.

I also saw now this comment

to override the _id implement id()

But, doesn't that mean that there is probably a bug in the default _id implementation because it should have been able to use the correct id field for each subnet and not the same one three times?

@mariuskimmina mariuskimmina force-pushed the add-aws-vpc-subnet-resource branch 2 times, most recently from cf43826 to 664e630 Compare September 24, 2023 09:27
@vjeffrey
Copy link
Contributor

using the arn as the id guarantees we get the unique one since it includes the region and account id - whenever dealing with aws we always want to use the arn where possible because of that.

good question about the _id thing tho, i haven't looked at it much yet in our new v9 world...i'll dig around for an answer for u on that

Signed-off-by: Marius Kimmina <[email protected]>
@mariuskimmina mariuskimmina force-pushed the add-aws-vpc-subnet-resource branch from 2559871 to d91a05e Compare September 24, 2023 19:24
@mariuskimmina
Copy link
Contributor Author

Anything still needs to be done here from my side? @vjeffrey

@vjeffrey
Copy link
Contributor

vjeffrey commented Oct 2, 2023

sorry for the delay! this is great, thank you!

@vjeffrey vjeffrey merged commit 59f7065 into mondoohq:main Oct 2, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants