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
91670cea
Commit
91670cea
authored
Aug 15, 2013
by
Mark Peek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon: add block device mappings [GH-90]
parent
c0721bc3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
97 additions
and
2 deletions
+97
-2
builder/amazon/common/block_device.go
builder/amazon/common/block_device.go
+46
-0
builder/amazon/common/block_device_test.go
builder/amazon/common/block_device_test.go
+41
-0
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+2
-0
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+2
-0
builder/amazon/ebs/step_create_ami.go
builder/amazon/ebs/step_create_ami.go
+3
-2
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+2
-0
builder/amazon/instance/step_register_ami.go
builder/amazon/instance/step_register_ami.go
+1
-0
No files found.
builder/amazon/common/block_device.go
0 → 100644
View file @
91670cea
package
common
import
(
"github.com/mitchellh/goamz/ec2"
)
// BlockDevice
type
BlockDevice
struct
{
DeviceName
string
`mapstructure:"device_name"`
VirtualName
string
`mapstructure:"virtual_name"`
SnapshotId
string
`mapstructure:"snapshot_id"`
VolumeType
string
`mapstructure:"volume_type"`
VolumeSize
int64
`mapstructure:"volume_size"`
DeleteOnTermination
bool
`mapstructure:"delete_on_termination"`
IOPS
int64
`mapstructure:"iops"`
}
type
BlockDevices
struct
{
AMIMappings
[]
BlockDevice
`mapstructure:"ami_block_device_mappings,squash"`
LaunchMappings
[]
BlockDevice
`mapstructure:"launch_block_device_mappings,squash"`
}
func
buildBlockDevices
(
b
[]
BlockDevice
)
[]
ec2
.
BlockDeviceMapping
{
var
blockDevices
[]
ec2
.
BlockDeviceMapping
for
_
,
blockDevice
:=
range
b
{
blockDevices
=
append
(
blockDevices
,
ec2
.
BlockDeviceMapping
{
DeviceName
:
blockDevice
.
DeviceName
,
VirtualName
:
blockDevice
.
VirtualName
,
SnapshotId
:
blockDevice
.
SnapshotId
,
VolumeType
:
blockDevice
.
VolumeType
,
VolumeSize
:
blockDevice
.
VolumeSize
,
DeleteOnTermination
:
blockDevice
.
DeleteOnTermination
,
IOPS
:
blockDevice
.
IOPS
,
})
}
return
blockDevices
}
func
(
b
*
BlockDevices
)
BuildAMIDevices
()
[]
ec2
.
BlockDeviceMapping
{
return
buildBlockDevices
(
b
.
AMIMappings
)
}
func
(
b
*
BlockDevices
)
BuildLaunchDevices
()
[]
ec2
.
BlockDeviceMapping
{
return
buildBlockDevices
(
b
.
LaunchMappings
)
}
builder/amazon/common/block_device_test.go
0 → 100644
View file @
91670cea
package
common
import
(
"cgl.tideland.biz/asserts"
"github.com/mitchellh/goamz/ec2"
"testing"
)
func
TestBlockDevice
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
ec2Mapping
:=
[]
ec2
.
BlockDeviceMapping
{
ec2
.
BlockDeviceMapping
{
DeviceName
:
"/dev/sdb"
,
VirtualName
:
"ephemeral0"
,
SnapshotId
:
"snap-1234"
,
VolumeType
:
"standard"
,
VolumeSize
:
8
,
DeleteOnTermination
:
true
,
IOPS
:
1000
,
},
}
blockDevice
:=
BlockDevice
{
DeviceName
:
"/dev/sdb"
,
VirtualName
:
"ephemeral0"
,
SnapshotId
:
"snap-1234"
,
VolumeType
:
"standard"
,
VolumeSize
:
8
,
DeleteOnTermination
:
true
,
IOPS
:
1000
,
}
blockDevices
:=
BlockDevices
{
AMIMappings
:
[]
BlockDevice
{
blockDevice
},
LaunchMappings
:
[]
BlockDevice
{
blockDevice
},
}
assert
.
Equal
(
ec2Mapping
,
blockDevices
.
BuildAMIDevices
(),
"should match output"
)
assert
.
Equal
(
ec2Mapping
,
blockDevices
.
BuildLaunchDevices
(),
"should match output"
)
}
builder/amazon/common/step_run_source_instance.go
View file @
91670cea
...
...
@@ -17,6 +17,7 @@ type StepRunSourceInstance struct {
SourceAMI
string
IamInstanceProfile
string
SubnetId
string
BlockDevices
BlockDevices
instance
*
ec2
.
Instance
}
...
...
@@ -48,6 +49,7 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
SecurityGroups
:
[]
ec2
.
SecurityGroup
{
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}},
IamInstanceProfile
:
s
.
IamInstanceProfile
,
SubnetId
:
s
.
SubnetId
,
BlockDevices
:
s
.
BlockDevices
.
BuildLaunchDevices
(),
}
ui
.
Say
(
"Launching a source AWS instance..."
)
...
...
builder/amazon/ebs/builder.go
View file @
91670cea
...
...
@@ -22,6 +22,7 @@ type config struct {
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
awscommon
.
AMIConfig
`mapstructure:",squash"`
awscommon
.
BlockDevices
`mapstructure:",squash"`
awscommon
.
RunConfig
`mapstructure:",squash"`
// Tags for the AMI
...
...
@@ -119,6 +120,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
SourceAMI
:
b
.
config
.
SourceAmi
,
IamInstanceProfile
:
b
.
config
.
IamInstanceProfile
,
SubnetId
:
b
.
config
.
SubnetId
,
BlockDevices
:
b
.
config
.
BlockDevices
,
},
&
common
.
StepConnectSSH
{
SSHAddress
:
awscommon
.
SSHAddress
(
ec2conn
,
b
.
config
.
SSHPort
),
...
...
builder/amazon/ebs/step_create_ami.go
View file @
91670cea
...
...
@@ -19,8 +19,9 @@ func (s *stepCreateAMI) Run(state map[string]interface{}) multistep.StepAction {
// Create the image
ui
.
Say
(
fmt
.
Sprintf
(
"Creating the AMI: %s"
,
config
.
AMIName
))
createOpts
:=
&
ec2
.
CreateImage
{
InstanceId
:
instance
.
InstanceId
,
Name
:
config
.
AMIName
,
InstanceId
:
instance
.
InstanceId
,
Name
:
config
.
AMIName
,
BlockDevices
:
config
.
BlockDevices
.
BuildAMIDevices
(),
}
createResp
,
err
:=
ec2conn
.
CreateImage
(
createOpts
)
...
...
builder/amazon/instance/builder.go
View file @
91670cea
...
...
@@ -24,6 +24,7 @@ type Config struct {
common
.
PackerConfig
`mapstructure:",squash"`
awscommon
.
AccessConfig
`mapstructure:",squash"`
awscommon
.
AMIConfig
`mapstructure:",squash"`
awscommon
.
BlockDevices
`mapstructure:",squash"`
awscommon
.
RunConfig
`mapstructure:",squash"`
AccountId
string
`mapstructure:"account_id"`
...
...
@@ -198,6 +199,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
UserDataFile
:
b
.
config
.
UserDataFile
,
SourceAMI
:
b
.
config
.
SourceAmi
,
SubnetId
:
b
.
config
.
SubnetId
,
BlockDevices
:
b
.
config
.
BlockDevices
,
},
&
common
.
StepConnectSSH
{
SSHAddress
:
awscommon
.
SSHAddress
(
ec2conn
,
b
.
config
.
SSHPort
),
...
...
builder/amazon/instance/step_register_ami.go
View file @
91670cea
...
...
@@ -20,6 +20,7 @@ func (s *StepRegisterAMI) Run(state map[string]interface{}) multistep.StepAction
registerOpts
:=
&
ec2
.
RegisterImage
{
ImageLocation
:
manifestPath
,
Name
:
config
.
AMIName
,
BlockDevices
:
config
.
BlockDevices
.
BuildAMIDevices
(),
}
registerResp
,
err
:=
ec2conn
.
RegisterImage
(
registerOpts
)
...
...
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