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

Added: AWS 'launch_configuration', 'launch_template' and 'autoscaling_group' resources #68

Merged
merged 4 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
talset marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(out, "\ncould not read resource: %s.%s\n", re.Type(), re.ID())
logger.Log("error", cause)
talset marked this conversation as resolved.
Show resolved Hide resolved
continue
}

if hcl != nil {
Expand Down