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

aws: added new resources #300

Merged
merged 3 commits into from
Jun 2, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
- `aws_lb_target_group_attachment` was raising a nil pointer exception
([Issue #297](https://github.com/cycloidio/terracognita/issues/297))


### Added
- Added new AWS resources: `aws_ec2_transit_gateway_peering_attachment`, `aws_ec2_transit_gateway_peering_attachment_accepter`, `aws_ec2_transit_gateway_prefix_list_reference`, `aws_ec2_transit_gateway_route`, `aws_ec2_transit_gateway_route_table_association`, `aws_ec2_transit_gateway_route_table_propagation`, `aws_ec2_transit_gateway_vpc_attachment_accepter`
([Issue #299](https://github.com/cycloidio/terracognita/issues/299))

## [0.7.6] _2022-05-11_

### Changed
Expand Down
37 changes: 37 additions & 0 deletions aws/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,40 @@ func getGlueDatabasesNames(ctx context.Context, a *aws, rt string, filters *filt

return names, nil
}

func cacheTransitGatewayRouteTables(ctx context.Context, a *aws, rt string, filters *filter.Filter) ([]provider.Resource, error) {
rs, err := a.cache.Get(rt)
if err != nil {
if errors.Cause(err) != errcode.ErrCacheKeyNotFound {
return nil, errors.WithStack(err)
}

rs, err = ec2TransitGatewayRouteTable(ctx, a, rt, filters)
if err != nil {
return nil, err
}

err = a.cache.Set(rt, rs)
if err != nil {
return nil, err
}
}

return rs, nil
}

func getTransitGatewayRouteTablesIDs(ctx context.Context, a *aws, rt string, filters *filter.Filter) ([]string, error) {
rs, err := cacheTransitGatewayRouteTables(ctx, a, rt, filters)
if err != nil {
return nil, err
}

// Get the actual needed value
// TODO cach this result too
ids := make([]string, 0, len(rs))
for _, i := range rs {
ids = append(ids, i.ID())
}

return ids, nil
}
53 changes: 53 additions & 0 deletions aws/cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,59 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetTransitGatewayPeeringAttachments",
Entity: "TransitGatewayPeeringAttachments",
Prefix: "Describe",
Service: "ec2",
Documentation: `
// GetTransitGatewayPeeringAttachments returns the ec2 Transit Gateway Peering Attachments on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetTransitGatewayPrefixListReference",
Entity: "TransitGatewayPrefixListReferences",
Prefix: "Get",
Service: "ec2",
Documentation: `
// GetTransitGatewayPrefixListReference returns the ec2 Transit Gateway Prefix List References on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetTransitGatewayRoutes",
Entity: "TransitGatewayRoutes",
Prefix: "Search",
Service: "ec2",
HasNotPagination: true,
FnAttributeList: "Routes",
Documentation: `
// GetTransitGatewayRoutes returns the ec2 Transit Gateway Routes on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetTransitGatewayRouteTableAssociations",
Entity: "TransitGatewayRouteTableAssociations",
FnAttributeList: "Associations",
Prefix: "Get",
Service: "ec2",
Documentation: `
// GetTransitGatewayRouteTableAssociations returns the ec2 Transit Gateway Route Table Associations on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetTransitGatewayRouteTablePropagations",
Entity: "TransitGatewayRouteTablePropagations",
Prefix: "Get",
Service: "ec2",
Documentation: `
// GetTransitGatewayRouteTablePropagations returns the ec2 Transit Gateway Route Table Propagations on the given input
// Returned values are commented in the interface doc comment block.
`,
},
// ECS
Function{
FnName: "GetECSClustersArns",
Expand Down
171 changes: 171 additions & 0 deletions aws/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ type Reader interface {
// Returned values are commented in the interface doc comment block.
GetTransitGatewayMulticast(ctx context.Context, input *ec2.DescribeTransitGatewayMulticastDomainsInput) ([]*ec2.TransitGatewayMulticastDomain, error)

// GetTransitGatewayPeeringAttachments returns the ec2 Transit Gateway Peering Attachments on the given input
// Returned values are commented in the interface doc comment block.
GetTransitGatewayPeeringAttachments(ctx context.Context, input *ec2.DescribeTransitGatewayPeeringAttachmentsInput) ([]*ec2.TransitGatewayPeeringAttachment, error)

// GetTransitGatewayPrefixListReference returns the ec2 Transit Gateway Prefix List References on the given input
// Returned values are commented in the interface doc comment block.
GetTransitGatewayPrefixListReference(ctx context.Context, input *ec2.GetTransitGatewayPrefixListReferencesInput) ([]*ec2.TransitGatewayPrefixListReference, error)

// GetTransitGatewayRoutes returns the ec2 Transit Gateway Routes on the given input
// Returned values are commented in the interface doc comment block.
GetTransitGatewayRoutes(ctx context.Context, input *ec2.SearchTransitGatewayRoutesInput) ([]*ec2.TransitGatewayRoute, error)

// GetTransitGatewayRouteTableAssociations returns the ec2 Transit Gateway Route Table Associations on the given input
// Returned values are commented in the interface doc comment block.
GetTransitGatewayRouteTableAssociations(ctx context.Context, input *ec2.GetTransitGatewayRouteTableAssociationsInput) ([]*ec2.TransitGatewayRouteTableAssociation, error)

// GetTransitGatewayRouteTablePropagations returns the ec2 Transit Gateway Route Table Propagations on the given input
// Returned values are commented in the interface doc comment block.
GetTransitGatewayRouteTablePropagations(ctx context.Context, input *ec2.GetTransitGatewayRouteTablePropagationsInput) ([]*ec2.TransitGatewayRouteTablePropagation, error)

// GetECSClustersArns returns the ecs clusters arns on the given input
// Returned values are commented in the interface doc comment block.
GetECSClustersArns(ctx context.Context, input *ecs.ListClustersInput) ([]*string, error)
Expand Down Expand Up @@ -1900,6 +1920,157 @@ func (c *connector) GetTransitGatewayMulticast(ctx context.Context, input *ec2.D
return opt, nil
}

func (c *connector) GetTransitGatewayPeeringAttachments(ctx context.Context, input *ec2.DescribeTransitGatewayPeeringAttachmentsInput) ([]*ec2.TransitGatewayPeeringAttachment, error) {
if c.svc.ec2 == nil {
c.svc.ec2 = ec2.New(c.svc.session)
}

opt := make([]*ec2.TransitGatewayPeeringAttachment, 0)

hasNextToken := true
for hasNextToken {
o, err := c.svc.ec2.DescribeTransitGatewayPeeringAttachmentsWithContext(ctx, input)
if err != nil {
return nil, err
}
if o.TransitGatewayPeeringAttachments == nil {
hasNextToken = false
continue
}

if input == nil {
input = &ec2.DescribeTransitGatewayPeeringAttachmentsInput{}
}
input.NextToken = o.NextToken
hasNextToken = o.NextToken != nil

opt = append(opt, o.TransitGatewayPeeringAttachments...)

}

return opt, nil
}

func (c *connector) GetTransitGatewayPrefixListReference(ctx context.Context, input *ec2.GetTransitGatewayPrefixListReferencesInput) ([]*ec2.TransitGatewayPrefixListReference, error) {
if c.svc.ec2 == nil {
c.svc.ec2 = ec2.New(c.svc.session)
}

opt := make([]*ec2.TransitGatewayPrefixListReference, 0)

hasNextToken := true
for hasNextToken {
o, err := c.svc.ec2.GetTransitGatewayPrefixListReferencesWithContext(ctx, input)
if err != nil {
return nil, err
}
if o.TransitGatewayPrefixListReferences == nil {
hasNextToken = false
continue
}

if input == nil {
input = &ec2.GetTransitGatewayPrefixListReferencesInput{}
}
input.NextToken = o.NextToken
hasNextToken = o.NextToken != nil

opt = append(opt, o.TransitGatewayPrefixListReferences...)

}

return opt, nil
}

func (c *connector) GetTransitGatewayRoutes(ctx context.Context, input *ec2.SearchTransitGatewayRoutesInput) ([]*ec2.TransitGatewayRoute, error) {
if c.svc.ec2 == nil {
c.svc.ec2 = ec2.New(c.svc.session)
}

opt := make([]*ec2.TransitGatewayRoute, 0)

hasNextToken := true
for hasNextToken {
o, err := c.svc.ec2.SearchTransitGatewayRoutesWithContext(ctx, input)
if err != nil {
return nil, err
}
if o.Routes == nil {
hasNextToken = false
continue
}

hasNextToken = false

opt = append(opt, o.Routes...)

}

return opt, nil
}

func (c *connector) GetTransitGatewayRouteTableAssociations(ctx context.Context, input *ec2.GetTransitGatewayRouteTableAssociationsInput) ([]*ec2.TransitGatewayRouteTableAssociation, error) {
if c.svc.ec2 == nil {
c.svc.ec2 = ec2.New(c.svc.session)
}

opt := make([]*ec2.TransitGatewayRouteTableAssociation, 0)

hasNextToken := true
for hasNextToken {
o, err := c.svc.ec2.GetTransitGatewayRouteTableAssociationsWithContext(ctx, input)
if err != nil {
return nil, err
}
if o.Associations == nil {
hasNextToken = false
continue
}

if input == nil {
input = &ec2.GetTransitGatewayRouteTableAssociationsInput{}
}
input.NextToken = o.NextToken
hasNextToken = o.NextToken != nil

opt = append(opt, o.Associations...)

}

return opt, nil
}

func (c *connector) GetTransitGatewayRouteTablePropagations(ctx context.Context, input *ec2.GetTransitGatewayRouteTablePropagationsInput) ([]*ec2.TransitGatewayRouteTablePropagation, error) {
if c.svc.ec2 == nil {
c.svc.ec2 = ec2.New(c.svc.session)
}

opt := make([]*ec2.TransitGatewayRouteTablePropagation, 0)

hasNextToken := true
for hasNextToken {
o, err := c.svc.ec2.GetTransitGatewayRouteTablePropagationsWithContext(ctx, input)
if err != nil {
return nil, err
}
if o.TransitGatewayRouteTablePropagations == nil {
hasNextToken = false
continue
}

if input == nil {
input = &ec2.GetTransitGatewayRouteTablePropagationsInput{}
}
input.NextToken = o.NextToken
hasNextToken = o.NextToken != nil

opt = append(opt, o.TransitGatewayRouteTablePropagations...)

}

return opt, nil
}

func (c *connector) GetECSClustersArns(ctx context.Context, input *ecs.ListClustersInput) ([]*string, error) {
if c.svc.ecs == nil {
c.svc.ecs = ecs.New(c.svc.session)
Expand Down
Loading