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
09f40112
Commit
09f40112
authored
Oct 02, 2013
by
Matt Whiteley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon: instances can be launched with a list of security groups
parent
8821ef4d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
28 deletions
+65
-28
builder/amazon/common/run_config.go
builder/amazon/common/run_config.go
+37
-13
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+7
-2
builder/amazon/common/step_security_group.go
builder/amazon/common/step_security_group.go
+7
-7
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+3
-3
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+3
-3
website/source/docs/builders/amazon-ebs.html.markdown
website/source/docs/builders/amazon-ebs.html.markdown
+4
-0
website/source/docs/builders/amazon-instance.html.markdown
website/source/docs/builders/amazon-instance.html.markdown
+4
-0
No files found.
builder/amazon/common/run_config.go
View file @
09f40112
...
@@ -20,6 +20,7 @@ type RunConfig struct {
...
@@ -20,6 +20,7 @@ type RunConfig struct {
SSHUsername
string
`mapstructure:"ssh_username"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPort
int
`mapstructure:"ssh_port"`
SSHPort
int
`mapstructure:"ssh_port"`
SecurityGroupId
string
`mapstructure:"security_group_id"`
SecurityGroupId
string
`mapstructure:"security_group_id"`
SecurityGroupIds
[]
string
`mapstructure:"security_group_ids"`
SubnetId
string
`mapstructure:"subnet_id"`
SubnetId
string
`mapstructure:"subnet_id"`
TemporaryKeyPairName
string
`mapstructure:"temporary_key_pair_name"`
TemporaryKeyPairName
string
`mapstructure:"temporary_key_pair_name"`
VpcId
string
`mapstructure:"vpc_id"`
VpcId
string
`mapstructure:"vpc_id"`
...
@@ -73,11 +74,19 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
...
@@ -73,11 +74,19 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
}
}
}
}
if
c
.
SecurityGroupId
!=
""
{
if
len
(
c
.
SecurityGroupIds
)
>
0
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Only one of security_group_id or security_group_ids can be specified."
))
}
else
{
c
.
SecurityGroupIds
=
[]
string
{
c
.
SecurityGroupId
}
c
.
SecurityGroupId
=
""
}
}
templates
:=
map
[
string
]
*
string
{
templates
:=
map
[
string
]
*
string
{
"iam_instance_profile"
:
&
c
.
IamInstanceProfile
,
"iam_instance_profile"
:
&
c
.
IamInstanceProfile
,
"instance_type"
:
&
c
.
InstanceType
,
"instance_type"
:
&
c
.
InstanceType
,
"ssh_timeout"
:
&
c
.
RawSSHTimeout
,
"ssh_timeout"
:
&
c
.
RawSSHTimeout
,
"security_group_id"
:
&
c
.
SecurityGroupId
,
"ssh_username"
:
&
c
.
SSHUsername
,
"ssh_username"
:
&
c
.
SSHUsername
,
"source_ami"
:
&
c
.
SourceAmi
,
"source_ami"
:
&
c
.
SourceAmi
,
"subnet_id"
:
&
c
.
SubnetId
,
"subnet_id"
:
&
c
.
SubnetId
,
...
@@ -94,6 +103,21 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
...
@@ -94,6 +103,21 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
}
}
}
}
sliceTemplates
:=
map
[
string
][]
string
{
"security_group_ids"
:
c
.
SecurityGroupIds
,
}
for
n
,
slice
:=
range
sliceTemplates
{
for
i
,
elem
:=
range
slice
{
var
err
error
slice
[
i
],
err
=
t
.
Process
(
elem
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s[%d]: %s"
,
n
,
i
,
err
))
}
}
}
c
.
sshTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
c
.
sshTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
if
err
!=
nil
{
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
...
...
builder/amazon/common/step_run_source_instance.go
View file @
09f40112
...
@@ -26,7 +26,7 @@ type StepRunSourceInstance struct {
...
@@ -26,7 +26,7 @@ type StepRunSourceInstance struct {
func
(
s
*
StepRunSourceInstance
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepRunSourceInstance
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
keyName
:=
state
.
Get
(
"keyPair"
)
.
(
string
)
keyName
:=
state
.
Get
(
"keyPair"
)
.
(
string
)
securityGroupId
:=
state
.
Get
(
"securityGroupId"
)
.
(
string
)
securityGroupId
s
:=
state
.
Get
(
"securityGroupIds"
)
.
([]
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
userData
:=
s
.
UserData
userData
:=
s
.
UserData
...
@@ -40,6 +40,11 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -40,6 +40,11 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
userData
=
string
(
contents
)
userData
=
string
(
contents
)
}
}
securityGroups
:=
make
([]
ec2
.
SecurityGroup
,
len
(
securityGroupIds
))
for
n
,
securityGroupId
:=
range
securityGroupIds
{
securityGroups
[
n
]
=
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}
}
runOpts
:=
&
ec2
.
RunInstances
{
runOpts
:=
&
ec2
.
RunInstances
{
KeyName
:
keyName
,
KeyName
:
keyName
,
ImageId
:
s
.
SourceAMI
,
ImageId
:
s
.
SourceAMI
,
...
@@ -47,7 +52,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -47,7 +52,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
UserData
:
[]
byte
(
userData
),
UserData
:
[]
byte
(
userData
),
MinCount
:
0
,
MinCount
:
0
,
MaxCount
:
0
,
MaxCount
:
0
,
SecurityGroups
:
[]
ec2
.
SecurityGroup
{
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}}
,
SecurityGroups
:
securityGroups
,
IamInstanceProfile
:
s
.
IamInstanceProfile
,
IamInstanceProfile
:
s
.
IamInstanceProfile
,
SubnetId
:
s
.
SubnetId
,
SubnetId
:
s
.
SubnetId
,
BlockDevices
:
s
.
BlockDevices
.
BuildLaunchDevices
(),
BlockDevices
:
s
.
BlockDevices
.
BuildLaunchDevices
(),
...
...
builder/amazon/common/step_security_group.go
View file @
09f40112
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
)
)
type
StepSecurityGroup
struct
{
type
StepSecurityGroup
struct
{
SecurityGroupId
string
SecurityGroupId
s
[]
string
SSHPort
int
SSHPort
int
VpcId
string
VpcId
string
...
@@ -23,9 +23,9 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -23,9 +23,9 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ec2conn
:=
state
.
Get
(
"ec2"
)
.
(
*
ec2
.
EC2
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
if
s
.
SecurityGroupId
!=
""
{
if
len
(
s
.
SecurityGroupIds
)
>
0
{
log
.
Printf
(
"Using specified security group
: %s"
,
s
.
SecurityGroupId
)
log
.
Printf
(
"Using specified security group
s: %v"
,
s
.
SecurityGroupIds
)
state
.
Put
(
"securityGroupId
"
,
s
.
SecurityGroupId
)
state
.
Put
(
"securityGroupId
s"
,
s
.
SecurityGroupIds
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
...
@@ -70,7 +70,7 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -70,7 +70,7 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
}
}
// Set some state data for use in future steps
// Set some state data for use in future steps
state
.
Put
(
"securityGroupId
"
,
s
.
createdGroupId
)
state
.
Put
(
"securityGroupId
s"
,
[]
string
{
s
.
createdGroupId
}
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
...
...
builder/amazon/ebs/builder.go
View file @
09f40112
...
@@ -88,7 +88,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -88,7 +88,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
},
},
&
awscommon
.
StepSecurityGroup
{
&
awscommon
.
StepSecurityGroup
{
SecurityGroupId
:
b
.
config
.
SecurityGroupId
,
SecurityGroupId
s
:
b
.
config
.
SecurityGroupIds
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
SSHPort
,
VpcId
:
b
.
config
.
VpcId
,
VpcId
:
b
.
config
.
VpcId
,
},
},
...
...
builder/amazon/instance/builder.go
View file @
09f40112
...
@@ -191,7 +191,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -191,7 +191,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
KeyPairName
:
b
.
config
.
TemporaryKeyPairName
,
},
},
&
awscommon
.
StepSecurityGroup
{
&
awscommon
.
StepSecurityGroup
{
SecurityGroupId
:
b
.
config
.
SecurityGroupId
,
SecurityGroupId
s
:
b
.
config
.
SecurityGroupIds
,
SSHPort
:
b
.
config
.
SSHPort
,
SSHPort
:
b
.
config
.
SSHPort
,
VpcId
:
b
.
config
.
VpcId
,
VpcId
:
b
.
config
.
VpcId
,
},
},
...
...
website/source/docs/builders/amazon-ebs.html.markdown
View file @
09f40112
...
@@ -97,6 +97,10 @@ Optional:
...
@@ -97,6 +97,10 @@ Optional:
access. Note that if this is specified, you must be sure the security
access. Note that if this is specified, you must be sure the security
group allows access to the
`ssh_port`
given below.
group allows access to the
`ssh_port`
given below.
*
`security_group_ids`
(array of string) - A list of security groups as
described above. Note that if this is specified, you must omit the
security_group_id.
*
`ssh_port`
(int) - The port that SSH will be available on. This defaults
*
`ssh_port`
(int) - The port that SSH will be available on. This defaults
to port 22.
to port 22.
...
...
website/source/docs/builders/amazon-instance.html.markdown
View file @
09f40112
...
@@ -129,6 +129,10 @@ Optional:
...
@@ -129,6 +129,10 @@ Optional:
access. Note that if this is specified, you must be sure the security
access. Note that if this is specified, you must be sure the security
group allows access to the
`ssh_port`
given below.
group allows access to the
`ssh_port`
given below.
*
`security_group_ids`
(array of string) - A list of security groups as
described above. Note that if this is specified, you must omit the
security_group_id.
*
`ssh_port`
(int) - The port that SSH will be available on. This defaults
*
`ssh_port`
(int) - The port that SSH will be available on. This defaults
to port 22.
to port 22.
...
...
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