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
2ba59617
Commit
2ba59617
authored
Aug 08, 2013
by
James Massara
Committed by
Mitchell Hashimoto
Aug 08, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/all: Added support for setting attributes on the AMI
parent
d2f1ba36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
0 deletions
+94
-0
builder/amazon/common/step_modify_attributes.go
builder/amazon/common/step_modify_attributes.go
+72
-0
builder/amazon/ebs/builder.go
builder/amazon/ebs/builder.go
+10
-0
builder/amazon/instance/builder.go
builder/amazon/instance/builder.go
+12
-0
No files found.
builder/amazon/common/step_modify_attributes.go
0 → 100644
View file @
2ba59617
package
common
import
(
"fmt"
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type
StepModifyAttributes
struct
{
Users
[]
string
Groups
[]
string
ProductCodes
[]
string
Description
string
}
func
(
s
*
StepModifyAttributes
)
Run
(
state
map
[
string
]
interface
{})
multistep
.
StepAction
{
ec2conn
:=
state
[
"ec2"
]
.
(
*
ec2
.
EC2
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
amis
:=
state
[
"amis"
]
.
(
map
[
string
]
string
)
ami
:=
amis
[
ec2conn
.
Region
.
Name
]
if
s
.
Description
!=
""
{
ui
.
Say
(
fmt
.
Sprintf
(
"Setting Description of AMI (%s) to '%s'..."
,
ami
,
s
.
Description
))
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
&
ec2
.
ModifyImageAttribute
{
Attribute
:
ec2
.
DescriptionAttribute
,
Description
:
s
.
Description
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error setting Description of AMI (%s): %s"
,
ami
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
if
len
(
s
.
Users
)
>
0
||
len
(
s
.
Groups
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Setting Launch Permissions for AMI (%s)..."
,
ami
))
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
&
ec2
.
ModifyImageAttribute
{
Attribute
:
ec2
.
LaunchPermissionAttribute
,
Operation
:
ec2
.
LaunchPermissionAdd
,
Users
:
s
.
Users
,
Groups
:
s
.
Groups
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error setting Launch Permissions for AMI (%s): %s"
,
ami
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
if
len
(
s
.
ProductCodes
)
>
0
{
ui
.
Say
(
fmt
.
Sprintf
(
"Setting Product Code(s) for AMI (%s)..."
,
ami
))
_
,
err
:=
ec2conn
.
ModifyImageAttribute
(
ami
,
&
ec2
.
ModifyImageAttribute
{
Attribute
:
ec2
.
ProductCodeAttribute
,
ProductCodes
:
s
.
ProductCodes
,
})
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error setting Product Code(s) for AMI (%s): %s"
,
ami
,
err
)
state
[
"error"
]
=
err
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
}
return
multistep
.
ActionContinue
}
func
(
s
*
StepModifyAttributes
)
Cleanup
(
state
map
[
string
]
interface
{})
{
// No cleanup...
}
builder/amazon/ebs/builder.go
View file @
2ba59617
...
...
@@ -27,6 +27,11 @@ type config struct {
// Configuration of the resulting AMI
AMIName
string
`mapstructure:"ami_name"`
// AMI attributes
AMIDescription
string
`mapstructure:"ami_description"`
AMIUsers
[]
string
`mapstructure:"ami_users"`
AMIGroups
[]
string
`mapstructure:"ami_groups"`
// Tags for the AMI
Tags
map
[
string
]
string
...
...
@@ -136,6 +141,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
stepStopInstance
{},
&
stepCreateAMI
{},
&
awscommon
.
StepCreateTags
{
Tags
:
b
.
config
.
Tags
},
&
awscommon
.
StepModifyAttributes
{
Description
:
b
.
config
.
AMIDescription
,
Users
:
b
.
config
.
AMIUsers
,
Groups
:
b
.
config
.
AMIGroups
,
},
}
// Run!
...
...
builder/amazon/instance/builder.go
View file @
2ba59617
...
...
@@ -37,6 +37,12 @@ type Config struct {
X509KeyPath
string
`mapstructure:"x509_key_path"`
X509UploadPath
string
`mapstructure:"x509_upload_path"`
// AMI attributes
AMIDescription
string
`mapstructure:"ami_description"`
AMIUsers
[]
string
`mapstructure:"ami_users"`
AMIGroups
[]
string
`mapstructure:"ami_groups"`
AMIProductCodes
[]
string
`mapstructure:"ami_product_codes"`
tpl
*
common
.
Template
}
...
...
@@ -210,6 +216,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
StepUploadBundle
{},
&
StepRegisterAMI
{},
&
awscommon
.
StepCreateTags
{
Tags
:
b
.
config
.
Tags
},
&
awscommon
.
StepModifyAttributes
{
Description
:
b
.
config
.
AMIDescription
,
Users
:
b
.
config
.
AMIUsers
,
Groups
:
b
.
config
.
AMIGroups
,
ProductCodes
:
b
.
config
.
AMIProductCodes
,
},
}
// Run!
...
...
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