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

extended vpc struct to support cidrblock,cidr associations and ipv6 a… #1422

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions modules/aws/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import (

// Vpc is an Amazon Virtual Private Cloud.
type Vpc struct {
Id string // The ID of the VPC
Name string // The name of the VPC
Subnets []Subnet // A list of subnets in the VPC
Tags map[string]string // The tags associated with the VPC
Id string // The ID of the VPC
Name string // The name of the VPC
Subnets []Subnet // A list of subnets in the VPC
Tags map[string]string // The tags associated with the VPC
CidrBlock *string // The primary IPv4 CIDR block for the VPC.
CidrAssociations []*string // Information about the IPv4 CIDR blocks associated with the VPC.
Ipv6CidrAssociations []*string // Information about the IPv6 CIDR blocks associated with the VPC.
}

// Subnet is a subnet in an availability zone.
Expand Down Expand Up @@ -105,7 +108,31 @@ func GetVpcsE(t testing.TestingT, filters []*ec2.Filter, region string) ([]*Vpc,
return nil, err
}

retVal[i] = &Vpc{Id: aws.StringValue(vpc.VpcId), Name: FindVpcName(vpc), Subnets: subnets, Tags: tags}
// cidr block associations
var cidrBlockAssociations = func() (list []*string) {
for _, cidr := range vpc.CidrBlockAssociationSet {
list = append(list, cidr.CidrBlock)
}
return
}()

// ipv6 cidr block associations
var Ipv6CidrAssociations = func() (list []*string) {
for _, cidr := range vpc.Ipv6CidrBlockAssociationSet {
list = append(list, cidr.Ipv6CidrBlock)
}
return
}()

retVal[i] = &Vpc{
Id: aws.StringValue(vpc.VpcId),
Name: FindVpcName(vpc),
Subnets: subnets,
Tags: tags,
CidrBlock: vpc.CidrBlock,
CidrAssociations: cidrBlockAssociations,
Ipv6CidrAssociations: Ipv6CidrAssociations,
}
}

return retVal, nil
Expand Down
1 change: 1 addition & 0 deletions modules/aws/vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestGetVpcById(t *testing.T) {

vpcTest := GetVpcById(t, *vpc.VpcId, region)
assert.Equal(t, *vpc.VpcId, vpcTest.Id)
assert.NotEmpty(t, vpcTest.CidrAssociations)
}

func TestGetVpcsE(t *testing.T) {
Expand Down