github-vet / github-vet/rangeloop-pointer-findings

davidddw/packer-builder-cloud: src/github.com/mitchellh/packer/builder/amazon/common/step_create_tags.go; 63 LoC

Open
#11,445 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [davidddw/packer-builder-cloud](https://www.github.com/davidddw/packer-builder-cloud) at [src/github.com/mitchellh/packer/builder/amazon/common/step_create_tags.go](https://github.com/davidddw/packer-builder-cloud/blob/0d733c5ea51135e6d335bcb7ae73c6c5821624db/src/github.com/mitchellh/packer/builder/amazon/common/step_create_tags.go#L23-L85)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to ami was used in a composite literal at line 36

[Click here to see the code in its original context.](https://github.com/davidddw/packer-builder-cloud/blob/0d733c5ea51135e6d335bcb7ae73c6c5821624db/src/github.com/mitchellh/packer/builder/amazon/common/step_create_tags.go#L23-L85)

Click here to show the 63 line(s) of Go which triggered the analyzer.

```go
for region, ami := range amis {
ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami))

var ec2Tags []*ec2.Tag
for key, value := range s.Tags {
ui.Message(fmt.Sprintf("Adding tag: \"%s\": \"%s\"", key, value))
ec2Tags = append(ec2Tags, &ec2.Tag{
Key: aws.String(key),
Value: aws.String(value),
})
}

// Declare list of resources to tag
resourceIds := []*string{&ami}
awsConfig := aws.Config{
Credentials: ec2conn.Config.Credentials,
Region: aws.String(region),
}
session := session.New(&awsConfig)

regionconn := ec2.New(session)

// Retrieve image list for given AMI
imageResp, err := regionconn.DescribeImages(&ec2.DescribeImagesInput{
ImageIds: resourceIds,
})

if err != nil {
err := fmt.Errorf("Error retrieving details for AMI (%s): %s", ami, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

if len(imageResp.Images) == 0 {
err := fmt.Errorf("Error retrieving details for AMI (%s), no images found", ami)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}

image := imageResp.Images[0]

// Add only those with a Snapshot ID, i.e. not Ephemeral
for _, device := range image.BlockDeviceMappings {
if device.Ebs != nil && device.Ebs.SnapshotId != nil {
ui.Say(fmt.Sprintf("Tagging snapshot: %s", *device.Ebs.SnapshotId))
resourceIds = append(resourceIds, device.Ebs.SnapshotId)
}
}

_, err = regionconn.CreateTags(&ec2.CreateTagsInput{
Resources: resourceIds,
Tags: ec2Tags,
})

if err != nil {
err := fmt.Errorf("Error adding tags to Resources (%#v): %s", resourceIds, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 0d733c5ea51135e6d335bcb7ae73c6c5821624db

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.