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
0ea19cf8
Commit
0ea19cf8
authored
May 20, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Create a temporary keypair for use
parent
15f215d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+28
-6
No files found.
builder/amazonebs/builder.go
View file @
0ea19cf8
...
...
@@ -6,6 +6,8 @@
package
amazonebs
import
(
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2"
...
...
@@ -20,11 +22,10 @@ type config struct {
AccessKey
string
`mapstructure:"access_key"`
SecretKey
string
`mapstructure:"secret_key"`
// Information for the source AMI
Region
string
SourceAmi
string
`mapstructure:"source_ami"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHKeyPath
string
`mapstructure:"ssh_private_key_path"`
// Information for the source instance
Region
string
SourceAmi
string
`mapstructure:"source_ami"`
InstanceType
string
`mapstructure:"instance_type"`
// Configuration of the resulting AMI
AMIName
string
`mapstructure:"ami_name"`
...
...
@@ -51,9 +52,30 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) {
region
:=
aws
.
Regions
[
b
.
config
.
Region
]
ec2conn
:=
ec2
.
New
(
auth
,
region
)
// Create a new keypair that we'll use to access the instance.
keyName
:=
fmt
.
Sprintf
(
"packer %s"
,
hex
.
EncodeToString
(
identifier
.
NewUUID
()
.
Raw
()))
ui
.
Say
(
"Creating temporary keypair for this instance...
\n
"
)
log
.
Printf
(
"temporary keypair name: %s
\n
"
,
keyName
)
_
,
err
:=
ec2conn
.
CreateKeyPair
(
keyName
)
if
err
!=
nil
{
ui
.
Error
(
"%s
\n
"
,
err
.
Error
())
return
}
// Make sure the keypair is properly deleted when we exit
defer
func
()
{
ui
.
Say
(
"Deleting temporary keypair...
\n
"
)
_
,
err
:=
ec2conn
.
DeleteKeyPair
(
keyName
)
if
err
!=
nil
{
ui
.
Error
(
"Error cleaning up keypair. Please delete the key manually: %s"
,
keyName
)
}
}()
runOpts
:=
&
ec2
.
RunInstances
{
KeyName
:
keyName
,
ImageId
:
b
.
config
.
SourceAmi
,
InstanceType
:
"m1.small"
,
InstanceType
:
b
.
config
.
InstanceType
,
MinCount
:
0
,
MaxCount
:
0
,
}
...
...
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