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
b5fdab40
Commit
b5fdab40
authored
Jul 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/instance: register AMI using API
parent
0552bc73
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
16 deletions
+13
-16
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+13
-16
No files found.
builder/amazon/instance/step_register_ami.go
View file @
b5fdab40
...
...
@@ -3,6 +3,7 @@ package instance
import
(
"bytes"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"strconv"
...
...
@@ -17,8 +18,8 @@ type amiNameData struct {
type
StepRegisterAMI
struct
{}
func
(
s
*
StepRegisterAMI
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
comm
:=
state
[
"communicator"
]
.
(
packer
.
Communicator
)
config
:=
state
[
"config"
]
.
(
*
Config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
manifestPath
:=
state
[
"remote_manifest_path"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
...
...
@@ -33,27 +34,23 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
amiName
:=
amiNameBuf
.
String
()
ui
.
Say
(
"Registering the AMI..."
)
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
fmt
.
Sprintf
(
"ec2-register %s -n '%s' -O '%s' -W '%s'"
,
manifestPath
,
amiName
,
config
.
AccessKey
,
config
.
SecretKey
),
registerOpts
:=
&
ec2
.
RegisterImage
{
ImageLocation
:
manifestPath
,
Name
:
amiName
,
}
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Error registering AMI: %s"
,
err
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
if
cmd
.
ExitStatus
!=
0
{
state
[
"error"
]
=
fmt
.
Errorf
(
"AMI registration failed. Please see the output above for more
\n
"
+
"details on what went wrong."
)
ui
.
Error
(
state
[
"error"
]
.
(
error
)
.
Error
())
return
multistep
.
ActionHalt
}
// Set the AMI ID in the state
ui
.
Say
(
fmt
.
Sprintf
(
"AMI: %s"
,
registerResp
.
ImageId
))
amis
:=
make
(
map
[
string
]
string
)
amis
[
config
.
Region
]
=
registerResp
.
ImageId
state
[
"amis"
]
=
amis
return
multistep
.
ActionContinue
}
...
...
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