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/resources: aws_alb_listener_certificate aws_lb_cookie_stickiness_policy #128

Merged
merged 3 commits into from
Jul 30, 2020
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
@@ -1,5 +1,10 @@
## [Unreleased]

### Added

- aws resource: `aws_alb_listener_certificate`, `aws_lb_cookie_stickiness_policy`, `aws_lb_target_group_attachment`, `aws_volume_attachment`, `aws_elasticsearch_domain`, `aws_elasticsearch_domain_policy`, `aws_lambda_function`, `aws_api_gateway_rest_api`, `aws_api_gateway_deployment`, `aws_api_gateway_stage`, `aws_api_gateway_resource`.
([PR #128](https://github.com/cycloidio/terracognita/pull/128))

## [0.5.1] _2020-07-17_

### Fixed
Expand Down
38 changes: 38 additions & 0 deletions aws/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ import (
"github.com/pkg/errors"
)

func cacheAPIGatewayRestApis(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 = apiGatewayRestApis(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 getAPIGatewayRestApis(ctx context.Context, a *aws, rt string, filters *filter.Filter) ([]string, error) {
rs, err := cacheAPIGatewayRestApis(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
}

func cacheLoadBalancersV2(ctx context.Context, a *aws, rt string, filters *filter.Filter) ([]provider.Resource, error) {
// if both aws_alb and aws_lb defined, keep only aws_alb
if filters.IsIncluded("aws_alb", "aws_lb") && (!filters.IsExcluded("aws_alb") && rt == "aws_lb") {
Expand Down
152 changes: 152 additions & 0 deletions aws/cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,63 @@ var (
// functions is the list of fuctions that will be added
// to the AWSReader with the corresponding implementation
functions = []Function{
// apigateway
Function{
FnName: "GetAPIGatewayDeployments",
Entity: "Deployments",
FnAttributeList: "Items",
SingularEntity: "Deployment",
Prefix: "Get",
Service: "apigateway",
FnPaginationAttribute: "Position",
FnInputPaginationAttribute: "Position",
Documentation: `
// GetAPIGatewayDeployments returns the Deployment Functions on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetAPIGatewayRestAPIs",
Entity: "RestApis",
FnAttributeList: "Items",
SingularEntity: "RestApi",
Prefix: "Get",
Service: "apigateway",
FnPaginationAttribute: "Position",
FnInputPaginationAttribute: "Position",
Documentation: `
// GetAPIGatewayRestAPIs returns the RestApi Functions on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetAPIGatewayStages",
Entity: "Stages",
FnAttributeList: "Item",
SingularEntity: "Stage",
Prefix: "Get",
Service: "apigateway",
HasNotPagination: true,
Documentation: `
// GetAPIGatewayStages returns the Stage Functions on the given input
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetAPIGatewayResources",
Entity: "Resources",
FnAttributeList: "Items",
SingularEntity: "Resource",
Prefix: "Get",
Service: "apigateway",
FnPaginationAttribute: "Position",
FnInputPaginationAttribute: "Position",
Documentation: `
// GetAPIGatewayResources returns the Resource Functions on the given input
// Returned values are commented in the interface doc comment block.
`,
},

// cloudwatch
Function{
Entity: "MetricAlarms",
Expand Down Expand Up @@ -192,6 +249,34 @@ var (
`,
},

// elasticsearch
Function{
HasNotPagination: true,
Entity: "ElasticsearchDomains",
SingularEntity: "ElasticsearchDomainStatus",
FnAttributeList: "DomainStatusList",
Prefix: "Describe",
Service: "elasticsearchservice",
Documentation: `
// GetElasticsearchDomains returns a list of domains of Elasticsearch resources.
// Returned values are commented in the interface doc comment block.
`,
},

Function{
HasNotPagination: true,
FnName: "GetElasticsearchDomainNames",
Entity: "DomainNames",
SingularEntity: "DomainInfo",
FnAttributeList: "DomainNames",
Prefix: "List",
Service: "elasticsearchservice",
Documentation: `
// GetElasticsearchDomainNames returns a list of domainNames of Elasticsearch resources.
// Returned values are commented in the interface doc comment block.
`,
},

// elb
Function{
Entity: "LoadBalancers",
Expand Down Expand Up @@ -219,6 +304,30 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "LoadBalancerAttributes",
SingularEntity: "AdditionalAttribute",
FnAttributeList: "LoadBalancerAttributes.AdditionalAttributes",
Prefix: "Describe",
HasNotPagination: true,
Service: "elb",
Documentation: `
// GetLoadBalancerAttributes returns a list of Attributes based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "LoadBalancerPolicies",
SingularEntity: "PolicyDescription",
FnAttributeList: "PolicyDescriptions",
Prefix: "Describe",
HasNotPagination: true,
Service: "elb",
Documentation: `
// GetLoadBalancerPolicies returns a list of Policies based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},

// elbv2
Function{
Expand Down Expand Up @@ -270,6 +379,19 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},
Function{
FnName: "GetLoadBalancersV2TargetHealth",
Entity: "TargetHealth",
SingularEntity: "TargetHealthDescription",
FnAttributeList: "TargetHealthDescriptions",
Prefix: "Describe",
Service: "elbv2",
HasNotPagination: true,
Documentation: `
// GetLoadBalancersV2TargetHealth returns a list of TargetHealth based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},
Function{
Entity: "ListenerCertificates",
SingularEntity: "Certificate",
Expand All @@ -296,6 +418,20 @@ var (
`,
},

Function{
FnName: "GetLoadBalancersV2TargetGroupAttributes",
SingularEntity: "TargetGroupAttribute",
FnAttributeList: "Attributes",
HasNotPagination: true,
Entity: "TargetGroupAttributes",
Prefix: "Describe",
Service: "elbv2",
Documentation: `
// GetLoadBalancersV2TargetGroupAttributes returns a list of TargetGroupAttributes based on the input from the different regions.
// Returned values are commented in the interface doc comment block.
`,
},

// rds
Function{
Entity: "DBInstances",
Expand Down Expand Up @@ -865,5 +1001,21 @@ var (
// Returned values are commented in the interface doc comment block.
`,
},

// Lambda
Function{
FnName: "GetLambdaFunctions",
Entity: "Functions",
FnAttributeList: "Functions",
SingularEntity: "FunctionConfiguration",
Prefix: "List",
Service: "lambda",
FnPaginationAttribute: "NextMarker",
FnInputPaginationAttribute: "Marker",
Documentation: `
// GetLambdaFunctions returns the lambda Functions on the given input
// Returned values are commented in the interface doc comment block.
`,
},
}
)
40 changes: 23 additions & 17 deletions aws/reader/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/apigateway/apigatewayiface"
"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
"github.com/aws/aws-sdk-go/service/cloudfront/cloudfrontiface"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
"github.com/aws/aws-sdk-go/service/configservice/configserviceiface"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/elasticache/elasticacheiface"
"github.com/aws/aws-sdk-go/service/elasticsearchservice/elasticsearchserviceiface"
"github.com/aws/aws-sdk-go/service/elb/elbiface"
"github.com/aws/aws-sdk-go/service/elbv2/elbv2iface"
"github.com/aws/aws-sdk-go/service/iam/iamiface"
"github.com/aws/aws-sdk-go/service/lambda/lambdaiface"
"github.com/aws/aws-sdk-go/service/rds/rdsiface"
"github.com/aws/aws-sdk-go/service/route53/route53iface"
"github.com/aws/aws-sdk-go/service/route53resolver/route53resolveriface"
Expand Down Expand Up @@ -85,23 +88,26 @@ func (c *connector) GetRegion() string {
}

type serviceConnector struct {
region string
session *session.Session
ec2 ec2iface.EC2API
elb elbiface.ELBAPI
elbv2 elbv2iface.ELBV2API
rds rdsiface.RDSAPI
s3 s3iface.S3API
s3downloader s3manageriface.DownloaderAPI
elasticache elasticacheiface.ElastiCacheAPI
configservice configserviceiface.ConfigServiceAPI
cloudfront cloudfrontiface.CloudFrontAPI
cloudwatch cloudwatchiface.CloudWatchAPI
iam iamiface.IAMAPI
ses sesiface.SESAPI
route53 route53iface.Route53API
route53resolver route53resolveriface.Route53ResolverAPI
autoscaling autoscalingiface.AutoScalingAPI
apigateway apigatewayiface.APIGatewayAPI
autoscaling autoscalingiface.AutoScalingAPI
cloudfront cloudfrontiface.CloudFrontAPI
cloudwatch cloudwatchiface.CloudWatchAPI
configservice configserviceiface.ConfigServiceAPI
ec2 ec2iface.EC2API
elasticache elasticacheiface.ElastiCacheAPI
elasticsearchservice elasticsearchserviceiface.ElasticsearchServiceAPI
elb elbiface.ELBAPI
elbv2 elbv2iface.ELBV2API
iam iamiface.IAMAPI
lambda lambdaiface.LambdaAPI
rds rdsiface.RDSAPI
region string
route53resolver route53resolveriface.Route53ResolverAPI
route53 route53iface.Route53API
s3downloader s3manageriface.DownloaderAPI
s3 s3iface.S3API
ses sesiface.SESAPI
session *session.Session
}

// configureAWS creates a new static credential with the passed accessKey and
Expand Down
Loading