Skip to content

Commit

Permalink
aws: Add LaunchConfiguration LaunchTemplate AutoscalingGroup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
talset committed Nov 26, 2019
1 parent 000789d commit 903a049
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
69 changes: 69 additions & 0 deletions aws/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -148,6 +151,9 @@ var (
SESConfigurationSet: sesConfigurationSets,
SESIdentityNotificationTopic: sesIdentityNotificationTopics,
SESTemplate: sesTemplates,
LaunchConfiguration: launchConfigurations,
LaunchTemplate: launchtemplates,
AutoscalingGroup: autoscalinggroups,
}
)

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
13 changes: 5 additions & 8 deletions provider/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 903a049

Please sign in to comment.