Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
1fbf8b7f
Commit
1fbf8b7f
authored
Jun 11, 2015
by
Clint Shryock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update create_tags for new sdk
parent
a8155e17
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
15 deletions
+36
-15
builder/amazon/common/step_create_tags.go
builder/amazon/common/step_create_tags.go
+36
-15
No files found.
builder/amazon/common/step_create_tags.go
View file @
1fbf8b7f
...
...
@@ -3,6 +3,7 @@ package common
import
(
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
...
...
@@ -19,41 +20,61 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
if
len
(
s
.
Tags
)
>
0
{
for
region
,
ami
:=
range
amis
{
ui
.
Say
(
fmt
.
Sprintf
(
"Preparing tags for AMI (%s) and related snapshots"
,
ami
))
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
}
resourceIds
:=
[]
*
string
{
&
ami
}
// Retrieve image list for given AMI
imageResp
,
err
:=
ec2conn
.
Images
([]
string
{
ami
},
ec2
.
NewFilter
())
imageResp
,
err
:=
ec2conn
.
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
}
image
:=
&
imageResp
.
Images
[
0
]
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
.
BlockDevices
{
if
device
.
SnapshotId
!=
""
{
ui
.
Say
(
fmt
.
Sprintf
(
"Tagging snapshot: %s"
,
device
.
SnapshotId
))
resourceIds
=
append
(
resourceIds
,
device
.
SnapshotId
)
for
_
,
device
:=
range
image
.
BlockDevice
Mapping
s
{
if
device
.
EBS
!=
nil
&&
device
.
EBS
.
SnapshotID
!=
nil
{
ui
.
Say
(
fmt
.
Sprintf
(
"Tagging snapshot: %s"
,
*
device
.
EBS
.
SnapshotID
))
resourceIds
=
append
(
resourceIds
,
device
.
EBS
.
SnapshotID
)
}
}
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
:
&
key
,
Value
:
&
value
})
}
regionconn
:=
ec2
.
New
(
&
aws
.
Config
{
Credentials
:
ec2conn
.
Config
.
Credentials
,
Region
:
region
,
})
_
,
err
:
=
regionconn
.
CreateTags
(
&
ec2
.
CreateTagsInput
{
_
,
err
=
regionconn
.
CreateTags
(
&
ec2
.
CreateTagsInput
{
Resources
:
resourceIds
,
Tags
:
ec2Tags
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error adding tags to
AMI (%s): %s"
,
ami
,
err
)
err
:=
fmt
.
Errorf
(
"Error adding tags to
Resources (%#v): %s"
,
resourceIds
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment