From 903a0497acbeaadc2452d1e70301c5496c6ded7d Mon Sep 17 00:00:00 2001 From: talset Date: Wed, 13 Nov 2019 11:56:53 +0100 Subject: [PATCH] aws: Add LaunchConfiguration LaunchTemplate AutoscalingGroup LaunchConfiguration is now supported on cycloid-raws. LaunchTemplate is now supported on cycloid-raws. AutoscalingGroup is now supported on cycloid-raws. import.go: All read error is now ignored (continue) and logged. --- aws/resources.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++ cmd/aws.go | 1 + provider/import.go | 13 ++++----- 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/aws/resources.go b/aws/resources.go index 6f51e58c4e..0678da2812 100644 --- a/aws/resources.go +++ b/aws/resources.go @@ -88,6 +88,9 @@ const ( // SESEventDestination SESIdentityNotificationTopic SESTemplate + LaunchConfiguration + LaunchTemplate + AutoscalingGroup ) type rtFn func(ctx context.Context, a *aws, resourceType string, tags []tag.Tag) ([]provider.Resource, error) @@ -148,6 +151,9 @@ var ( SESConfigurationSet: sesConfigurationSets, SESIdentityNotificationTopic: sesIdentityNotificationTopics, SESTemplate: sesTemplates, + LaunchConfiguration: launchConfigurations, + LaunchTemplate: launchtemplates, + AutoscalingGroup: autoscalinggroups, } ) @@ -1225,6 +1231,69 @@ func sesTemplates(ctx context.Context, a *aws, resourceType string, tags []tag.T return resources, nil } +func launchConfigurations(ctx context.Context, a *aws, resourceType string, tags []tag.Tag) ([]provider.Resource, error) { + launchConfigurations, err := a.awsr.GetLaunchConfigurations(ctx, nil) + + if err != nil { + return nil, err + } + + resources := make([]provider.Resource, 0) + for _, i := range launchConfigurations[a.Region()].LaunchConfigurations { + + r, err := initializeResource(a, *i.LaunchConfigurationName, resourceType) + if err != nil { + return nil, err + } + + resources = append(resources, r) + } + + return resources, nil +} + +func launchtemplates(ctx context.Context, a *aws, resourceType string, tags []tag.Tag) ([]provider.Resource, error) { + launchtemplates, err := a.awsr.GetLaunchTemplates(ctx, nil) + + if err != nil { + return nil, err + } + + resources := make([]provider.Resource, 0) + for _, i := range launchtemplates[a.Region()].LaunchTemplates { + + r, err := initializeResource(a, *i.LaunchTemplateId, resourceType) + if err != nil { + return nil, err + } + + resources = append(resources, r) + } + + return resources, nil +} + +func autoscalinggroups(ctx context.Context, a *aws, resourceType string, tags []tag.Tag) ([]provider.Resource, error) { + autoscalinggroups, err := a.awsr.GetAutoScalingGroups(ctx, nil) + + if err != nil { + return nil, err + } + + resources := make([]provider.Resource, 0) + for _, i := range autoscalinggroups[a.Region()].AutoScalingGroups { + + r, err := initializeResource(a, *i.AutoScalingGroupName, resourceType) + if err != nil { + return nil, err + } + + resources = append(resources, r) + } + + return resources, nil +} + func toEC2Filters(tags []tag.Tag) []*ec2.Filter { if len(tags) == 0 { return nil diff --git a/cmd/aws.go b/cmd/aws.go index ef5cd04c99..8f146740c7 100644 --- a/cmd/aws.go +++ b/cmd/aws.go @@ -100,6 +100,7 @@ func init() { awsCmd.Flags().String("secret-key", "", "Secret Key (required)") awsCmd.Flags().String("region", "", "Region to search in, for now * it's not supported (required)") + // Filter flags awsCmd.Flags().StringSliceVarP(&tags, "tags", "t", []string{}, "List of tags to filter with format 'NAME:VALUE'") } diff --git a/provider/import.go b/provider/import.go index 53af7b20d3..15cd5661ac 100644 --- a/provider/import.go +++ b/provider/import.go @@ -80,16 +80,13 @@ func Import(ctx context.Context, p Provider, hcl, tfstate writer.Writer, f *filt err = util.RetryDefault(func() error { return r.Read(f) }) if err != nil { cause := errors.Cause(err) + // All those ignored errors are types of errors to identify that something happend, but not that something went wrong // some of them are to skip the resource and others just informative - if cause != errcode.ErrProviderResourceNotRead && cause != errcode.ErrProviderResourceDoNotMatchTag && cause != errcode.ErrProviderResourceAutogenerated { - return errors.Wrapf(err, "could not read resource %s: ", r.Type()) - } - if cause == errcode.ErrProviderResourceNotRead || cause == errcode.ErrProviderResourceAutogenerated { - // As the resource could not be Read, meaning an ID == "" - // we'll continue to the next resource - continue - } + // we'll continue to the next resource + fmt.Fprintf(out, "\ncould not read resource: %s.%s\n", re.Type(), re.ID()) + logger.Log("error", cause) + continue } if hcl != nil {