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
3a416bb1
Commit
3a416bb1
authored
Jul 29, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/chroot: step to gather instance info
parent
fa92377a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
1 deletion
+58
-1
builder/amazon/chroot/builder.go
builder/amazon/chroot/builder.go
+1
-1
builder/amazon/chroot/step_instance_info.go
builder/amazon/chroot/step_instance_info.go
+57
-0
No files found.
builder/amazon/chroot/builder.go
View file @
3a416bb1
...
...
@@ -72,7 +72,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps
steps
:=
[]
multistep
.
Step
{
&
Step
CheckEC2
{},
&
Step
InstanceInfo
{},
&
StepSourceAMIInfo
{},
&
StepCreateVolume
{},
}
...
...
builder/amazon/chroot/step_
check_ec2
.go
→
builder/amazon/chroot/step_
instance_info
.go
View file @
3a416bb1
...
...
@@ -3,19 +3,22 @@ package chroot
import
(
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// Step
CheckEC2
verifies that this builder is running on an EC2 instance.
type
Step
CheckEC2
struct
{}
// Step
InstanceInfo
verifies that this builder is running on an EC2 instance.
type
Step
InstanceInfo
struct
{}
func
(
s
*
StepCheckEC2
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
func
(
s
*
StepInstanceInfo
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Verifying we're on an EC2 instance..."
)
id
,
err
:=
aws
.
GetMetaData
(
"instance-id"
)
// Get our own instance ID
ui
.
Say
(
"Gathering information about this EC2 instance..."
)
instanceIdBytes
,
err
:=
aws
.
GetMetaData
(
"instance-id"
)
if
err
!=
nil
{
log
.
Printf
(
"Error: %s"
,
err
)
err
:=
fmt
.
Errorf
(
...
...
@@ -25,9 +28,30 @@ func (s *StepCheckEC2) Run(state map[string]interface{}) multistep.StepAction {
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
log
.
Printf
(
"Instance ID: %s"
,
string
(
id
))
instanceId
:=
string
(
instanceIdBytes
)
log
.
Printf
(
"Instance ID: %s"
,
instanceId
)
// Query the entire instance metadata
instancesResp
,
err
:=
ec2conn
.
Instances
([]
string
{
instanceId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error getting instance data: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
if
len
(
instancesResp
.
Reservations
)
==
0
{
err
:=
fmt
.
Errorf
(
"Error getting instance data: no instance found."
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
instance
:=
instancesResp
.
Reservations
[
0
]
.
Instances
[
0
]
state
[
"instance"
]
=
instance
return
multistep
.
ActionContinue
}
func
(
s
*
Step
CheckEC2
)
Cleanup
(
map
[
string
]
interface
{})
{}
func
(
s
*
Step
InstanceInfo
)
Cleanup
(
map
[
string
]
interface
{})
{}
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