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
45096d07
Commit
45096d07
authored
Jul 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon: extract StepKeyPair for both
parent
b3edb2fb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
8 deletions
+90
-8
builder/amazon/common/step_key_pair.go
builder/amazon/common/step_key_pair.go
+5
-7
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+1
-1
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+68
-0
builder/amazon/instance/builder_test.go
builder/amazon/instance/builder_test.go
+16
-0
No files found.
builder/amazon/
ebs/step_key
pair.go
→
builder/amazon/
common/step_key_
pair.go
View file @
45096d07
package
ebs
package
common
import
(
"cgl.tideland.biz/identifier"
...
...
@@ -10,11 +10,11 @@ import (
"log"
)
type
s
tepKeyPair
struct
{
type
S
tepKeyPair
struct
{
keyName
string
}
func
(
s
*
s
tepKeyPair
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
func
(
s
*
S
tepKeyPair
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
...
...
@@ -23,9 +23,7 @@ func (s *stepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
log
.
Printf
(
"temporary keypair name: %s"
,
keyName
)
keyResp
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error creating temporary keypair: %s"
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
state
[
"error"
]
=
fmt
.
Errorf
(
"Error creating temporary keypair: %s"
,
err
)
return
multistep
.
ActionHalt
}
...
...
@@ -39,7 +37,7 @@ func (s *stepKeyPair) Run(state map[string]interface{}) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
*
s
tepKeyPair
)
Cleanup
(
state
map
[
string
]
interface
{})
{
func
(
s
*
S
tepKeyPair
)
Cleanup
(
state
map
[
string
]
interface
{})
{
// If no key name is set, then we never created it, so just return
if
s
.
keyName
==
""
{
return
...
...
builder/amazon/ebs/builder.go
View file @
45096d07
...
...
@@ -90,7 +90,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
// Build the steps
steps
:=
[]
multistep
.
Step
{
&
s
tepKeyPair
{},
&
awscommon
.
S
tepKeyPair
{},
&
stepSecurityGroup
{},
&
stepRunSourceInstance
{},
&
common
.
StepConnectSSH
{
...
...
builder/amazon/instance/builder.go
View file @
45096d07
...
...
@@ -3,7 +3,11 @@
package
instance
import
(
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
awscommon
"github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer"
"log"
)
...
...
@@ -14,6 +18,9 @@ const BuilderId = "mitchellh.amazon.instance"
// Config is the configuration that is chained through the steps and
// settable from the template.
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
awscommon
.
RunConfig
`mapstructure:",squash"`
}
type
Builder
struct
{
...
...
@@ -22,10 +29,71 @@ type Builder struct {
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
error
{
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
if
err
!=
nil
{
return
err
}
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
()
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
()
...
)
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
errs
}
log
.
Printf
(
"Config: %+v"
,
b
.
config
)
return
nil
}
func
(
b
*
Builder
)
Run
(
ui
packer
.
Ui
,
hook
packer
.
Hook
,
cache
packer
.
Cache
)
(
packer
.
Artifact
,
error
)
{
region
,
ok
:=
aws
.
Regions
[
b
.
config
.
Region
]
if
!
ok
{
panic
(
"region not found"
)
}
auth
,
err
:=
b
.
config
.
AccessConfig
.
Auth
()
if
err
!=
nil
{
return
nil
,
err
}
ec2conn
:=
ec2
.
New
(
auth
,
region
)
// Setup the state bag and initial state for the steps
state
:=
make
(
map
[
string
]
interface
{})
state
[
"config"
]
=
b
.
config
state
[
"ec2"
]
=
ec2conn
state
[
"hook"
]
=
hook
state
[
"ui"
]
=
ui
// Build the steps
steps
:=
[]
multistep
.
Step
{
&
awscommon
.
StepKeyPair
{},
}
// Run!
if
b
.
config
.
PackerDebug
{
b
.
runner
=
&
multistep
.
DebugRunner
{
Steps
:
steps
,
PauseFn
:
common
.
MultistepDebugFn
(
ui
),
}
}
else
{
b
.
runner
=
&
multistep
.
BasicRunner
{
Steps
:
steps
}
}
b
.
runner
.
Run
(
state
)
// If there was an error, return that
if
rawErr
,
ok
:=
state
[
"error"
];
ok
{
return
nil
,
rawErr
.
(
error
)
}
// If there are no AMIs, then just return
if
_
,
ok
:=
state
[
"amis"
];
!
ok
{
return
nil
,
nil
}
return
nil
,
nil
}
...
...
builder/amazon/instance/builder_test.go
View file @
45096d07
...
...
@@ -5,6 +5,10 @@ import (
"testing"
)
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{}
}
func
TestBuilder_ImplementsBuilder
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
Builder
{}
...
...
@@ -12,3 +16,15 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
t
.
Fatalf
(
"Builder should be a builder"
)
}
}
func
TestBuilderPrepare_InvalidKey
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Add a random key
config
[
"i_should_not_be_valid"
]
=
true
err
:=
b
.
Prepare
(
config
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
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