Skip to content

Commit

Permalink
Merge pull request #87 from cycloidio/fl-awsresources
Browse files Browse the repository at this point in the history
aws: new resources
  • Loading branch information
talset authored Mar 27, 2020
2 parents bba72ce + 84133a8 commit acf4a56
Show file tree
Hide file tree
Showing 6 changed files with 667 additions and 180 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Added

- aws resources: `aws_db_subnet_group`, `aws_key_pair`, `aws_vpc_peering_connection`, `aws_alb_target_group`, `aws_alb_listener`, `aws_alb_listener_rule`
([PR #87](https://github.com/cycloidio/terracognita/pull/87))
- Terraform variable interpolation is available on string values
([PR #81](https://github.com/cycloidio/terracognita/pull/81))
- aws resource: `aws_db_parameter_group`, `aws_iam_access_key`, `aws_cloudwatch_metric_alarm`, `aws_autoscaling_policy`, `aws_iam_user_ssh_key`
Expand Down
74 changes: 74 additions & 0 deletions aws/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,80 @@ import (
"github.com/pkg/errors"
)

func cacheLoadBalancersV2(ctx context.Context, a *aws, rt string, tags []tag.Tag) ([]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 = albs(ctx, a, rt, tags)
if err != nil {
return nil, err
}

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

return rs, nil
}

func getLoadBalancersV2Arns(ctx context.Context, a *aws, rt string, tags []tag.Tag) ([]string, error) {
rs, err := cacheLoadBalancersV2(ctx, a, rt, tags)
if err != nil {
return nil, err
}

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

return names, nil
}

func cacheLoadBalancersV2Listeners(ctx context.Context, a *aws, rt string, tags []tag.Tag) ([]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 = albListeners(ctx, a, rt, tags)
if err != nil {
return nil, err
}

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

return rs, nil
}

func getLoadBalancersV2ListenersArns(ctx context.Context, a *aws, rt string, tags []tag.Tag) ([]string, error) {
rs, err := cacheLoadBalancersV2Listeners(ctx, a, rt, tags)
if err != nil {
return nil, err
}

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

return names, nil
}

func cacheIAMGroups(ctx context.Context, a *aws, rt string, tags []tag.Tag) ([]provider.Resource, error) {
rs, err := a.cache.Get(rt)
if err != nil {
Expand Down
67 changes: 67 additions & 0 deletions aws/cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "VpcPeeringConnections",
Prefix: "Describe",
Service: "ec2",
Documentation: `
// GetVpcPeeringConnections returns all VpcPeeringConnections based on the input given.
// Returned values are commented in the interface doc comment block.
`,
},

Function{
Entity: "Images",
Prefix: "Describe",
Expand All @@ -53,6 +63,15 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "KeyPairs",
Prefix: "Describe",
Service: "ec2",
Documentation: `
// GetKeyPairs returns all KeyPairs based on the input given.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "SecurityGroups",
Prefix: "Describe",
Expand Down Expand Up @@ -204,6 +223,45 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetLoadBalancersV2Listeners",
Entity: "Listeners",
Prefix: "Describe",
Service: "elbv2",
Documentation: `
// GetLoadBalancersV2Listeners returns a list of Listeners based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetLoadBalancersV2TargetGroups",
Entity: "TargetGroups",
Prefix: "Describe",
Service: "elbv2",
Documentation: `
// GetLoadBalancersV2TargetGroups returns a list of TargetGroups based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "ListenerCertificates",
Prefix: "Describe",
Service: "elbv2",
Documentation: `
// GetListenerCertificates returns a list of ListenerCertificates based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetLoadBalancersV2Rules",
Entity: "Rules",
Prefix: "Describe",
Service: "elbv2",
Documentation: `
// GetLoadBalancersV2Rules returns a list of Rules based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},

// rds
Function{
Expand Down Expand Up @@ -234,6 +292,15 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "DBSubnetGroups",
Prefix: "Describe",
Service: "rds",
Documentation: `
// GetDBSubnetGroups returns all DB DBSubnetGroups based on the input given.
// Returned values are commented in the interface doc comment block.
`,
},

// s3
Function{
Expand Down
119 changes: 119 additions & 0 deletions aws/reader/reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit acf4a56

Please sign in to comment.