Skip to content

Commit

Permalink
VPC -> vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshsonawane1372 committed May 17, 2023
1 parent 2a67815 commit fa8832f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/spf13/cobra"
"github.com/surajincloud/awsctl/pkg/VPC"
"github.com/surajincloud/awsctl/pkg/vpc"
)

var vpcCmd = &cobra.Command{
Expand Down
53 changes: 53 additions & 0 deletions pkg/vpc/getVPC.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package vpc

import (
"context"
"log"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
)

type Vpc struct {
Name *string
State *string
Ipv4Cidr *string
Default bool
VpcID *string
}

func GetVPC() ([]Vpc, error) {

var vpcList []Vpc

ctx := context.TODO()
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
log.Fatal(err)
}

client := ec2.NewFromConfig(cfg)

info, err := client.DescribeVpcs(ctx, &ec2.DescribeVpcsInput{})
if err != nil {
return nil, err
}
for _, i := range info.Vpcs {
for _, j := range i.Tags {
if *j.Key == "Name" {
vpcList = append(vpcList, Vpc{
Name: aws.String(*j.Value),
State: aws.String(string(i.State)),
Ipv4Cidr: aws.String(*i.CidrBlock),
Default: *i.IsDefault,
VpcID: aws.String(*i.VpcId),
})
}

}
}

return vpcList, err

}

0 comments on commit fa8832f

Please sign in to comment.