-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from chhaj5236/feature/support_tags
support adding tags to image
- Loading branch information
Showing
6 changed files
with
168 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ecs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/denverdino/aliyungo/common" | ||
"github.com/denverdino/aliyungo/ecs" | ||
"github.com/hashicorp/packer/helper/multistep" | ||
"github.com/hashicorp/packer/packer" | ||
) | ||
|
||
type stepCreateTags struct { | ||
Tags map[string]string | ||
} | ||
|
||
func (s *stepCreateTags) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { | ||
config := state.Get("config").(Config) | ||
client := state.Get("client").(*ecs.Client) | ||
ui := state.Get("ui").(packer.Ui) | ||
imageId := state.Get("alicloudimage").(string) | ||
|
||
if len(s.Tags) == 0 { | ||
return multistep.ActionContinue | ||
} | ||
|
||
ui.Say(fmt.Sprintf("Adding tags(%s) to image: %s", s.Tags, imageId)) | ||
|
||
err := client.AddTags(&ecs.AddTagsArgs{ | ||
ResourceId: imageId, | ||
ResourceType: ecs.TagResourceImage, | ||
RegionId: common.Region(config.AlicloudRegion), | ||
Tag: s.Tags, | ||
}) | ||
|
||
if err != nil { | ||
err := fmt.Errorf("Error Adding tags to image: %s", err) | ||
state.Put("error", err) | ||
ui.Say(err.Error()) | ||
return multistep.ActionHalt | ||
} | ||
|
||
return multistep.ActionContinue | ||
} | ||
|
||
func (s *stepCreateTags) Cleanup(state multistep.StateBag) { | ||
// Nothing need to do, tags will be cleaned when the resource is cleaned | ||
} |