Skip to content

Commit

Permalink
Merge pull request #1422 from gruntwork-io/feature/vpc-cidr-block-sup…
Browse files Browse the repository at this point in the history
…port

extended vpc struct to support cidrblock,cidr associations and ipv6 a…
  • Loading branch information
james03160927 authored Jul 22, 2024
2 parents 710d6af + cc2f9ff commit fc3c632
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
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

0 comments on commit fc3c632

Please sign in to comment.