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
dc641324
Commit
dc641324
authored
Jun 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Create temporary security group as well
parent
3b3efab8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
5 deletions
+79
-5
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+1
-0
builder/amazonebs/step_run_source_instance.go
builder/amazonebs/step_run_source_instance.go
+7
-5
builder/amazonebs/step_security_group.go
builder/amazonebs/step_security_group.go
+71
-0
No files found.
builder/amazonebs/builder.go
View file @
dc641324
...
...
@@ -133,6 +133,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
// Build the steps
steps
:=
[]
multistep
.
Step
{
&
stepKeyPair
{},
&
stepSecurityGroup
{},
&
stepRunSourceInstance
{},
&
stepConnectSSH
{},
&
stepProvision
{},
...
...
builder/amazonebs/step_run_source_instance.go
View file @
dc641324
...
...
@@ -16,14 +16,16 @@ func (s *stepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
config
:=
state
[
"config"
]
.
(
config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
keyName
:=
state
[
"keyPair"
]
.
(
string
)
securityGroupId
:=
state
[
"securityGroupId"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
runOpts
:=
&
ec2
.
RunInstances
{
KeyName
:
keyName
,
ImageId
:
config
.
SourceAmi
,
InstanceType
:
config
.
InstanceType
,
MinCount
:
0
,
MaxCount
:
0
,
KeyName
:
keyName
,
ImageId
:
config
.
SourceAmi
,
InstanceType
:
config
.
InstanceType
,
MinCount
:
0
,
MaxCount
:
0
,
SecurityGroups
:
[]
ec2
.
SecurityGroup
{
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}},
}
ui
.
Say
(
"Launching a source AWS instance..."
)
...
...
builder/amazonebs/step_security_group.go
0 → 100644
View file @
dc641324
package
amazonebs
import
(
"cgl.tideland.biz/identifier"
"encoding/hex"
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
type
stepSecurityGroup
struct
{
groupId
string
}
func
(
s
*
stepSecurityGroup
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
config
:=
state
[
"config"
]
.
(
config
)
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
// Create the group
ui
.
Say
(
"Creating temporary security group for this instance..."
)
groupName
:=
fmt
.
Sprintf
(
"packer %s"
,
hex
.
EncodeToString
(
identifier
.
NewUUID
()
.
Raw
()))
log
.
Printf
(
"Temporary group name: %s"
,
groupName
)
groupResp
,
err
:=
ec2conn
.
CreateSecurityGroup
(
groupName
,
"Temporary group for Packer"
)
if
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Set the group ID so we can delete it later
s
.
groupId
=
groupResp
.
Id
// Authorize the SSH access
perms
:=
[]
ec2
.
IPPerm
{
ec2
.
IPPerm
{
Protocol
:
"tcp"
,
FromPort
:
config
.
SSHPort
,
ToPort
:
config
.
SSHPort
,
SourceIPs
:
[]
string
{
"0.0.0.0/0"
},
},
}
ui
.
Say
(
"Authorizing SSH access on the temporary security group..."
)
if
_
,
err
:=
ec2conn
.
AuthorizeSecurityGroup
(
groupResp
.
SecurityGroup
,
perms
);
err
!=
nil
{
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
// Set some state data for use in future steps
state
[
"securityGroupId"
]
=
s
.
groupId
return
multistep
.
ActionContinue
}
func
(
s
*
stepSecurityGroup
)
Cleanup
(
state
map
[
string
]
interface
{})
{
if
s
.
groupId
==
""
{
return
}
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
ui
.
Say
(
"Deleting temporary security group..."
)
_
,
err
:=
ec2conn
.
DeleteSecurityGroup
(
ec2
.
SecurityGroup
{
Id
:
s
.
groupId
})
if
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error cleaning up security group. Please delete the group manually: %s"
,
s
.
groupId
))
}
}
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