Skip to content

Commit

Permalink
Also tag AWS EC2 EBS volumes
Browse files Browse the repository at this point in the history
Use the input from --amazonec2-tags to also tag EBS volumes

Resolves docker#4678
  • Loading branch information
Gabriel Féron committed Jul 21, 2020
1 parent e927003 commit d90c334
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions drivers/amazonec2/amazonec2.go
Expand Up @@ -877,6 +877,19 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser
}

func (d *Driver) getEbsVolumeId() (string, error) {
inst, err := d.getInstance()
if err != nil {
return "", err
}

if len(inst.BlockDeviceMappings) == 0 || inst.BlockDeviceMappings[0].Ebs == nil {
return "", err
}

return *inst.BlockDeviceMappings[0].Ebs.VolumeId, nil
}

func (d *Driver) Start() error {
_, err := d.getClient().StartInstances(&ec2.StartInstancesInput{
InstanceIds: []*string{&d.InstanceId},
Expand Down Expand Up @@ -1091,8 +1104,17 @@ func (d *Driver) configureTags(tagGroups string) error {
}
}

_, err := d.getClient().CreateTags(&ec2.CreateTagsInput{
Resources: []*string{&d.InstanceId},
volumeId, err := d.getEbsVolumeId()
resources := []*string{}
if err != nil {
log.Warnf("failed to get EBS volume ID: %s", err)
resources = []*string{&d.InstanceId}
} else {
resources = []*string{&d.InstanceId, &volumeId}
}

_, err = d.getClient().CreateTags(&ec2.CreateTagsInput{
Resources: resources,
Tags: tags,
})

Expand Down

0 comments on commit d90c334

Please sign in to comment.