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
3ff37469
Commit
3ff37469
authored
Aug 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/common: support user_data_file
parent
0f6c6511
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
1 deletion
+63
-1
builder/amazon/common/run_config.go
builder/amazon/common/run_config.go
+10
-0
builder/amazon/common/run_config_test.go
builder/amazon/common/run_config_test.go
+39
-0
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+14
-1
No files found.
builder/amazon/common/run_config.go
View file @
3ff37469
...
...
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/mitchellh/packer/common"
"os"
"time"
)
...
...
@@ -14,6 +15,7 @@ type RunConfig struct {
IamInstanceProfile
string
`mapstructure:"iam_instance_profile"`
InstanceType
string
`mapstructure:"instance_type"`
UserData
string
`mapstructure:"user_data"`
UserDataFile
string
`mapstructure:"user_data_file"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPort
int
`mapstructure:"ssh_port"`
...
...
@@ -58,6 +60,14 @@ func (c *RunConfig) Prepare(t *common.Template) []error {
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
if
c
.
UserData
!=
""
&&
c
.
UserDataFile
!=
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Only one of user_data or user_data_file can be specified."
))
}
else
if
c
.
UserDataFile
!=
""
{
if
_
,
err
:=
os
.
Stat
(
c
.
UserDataFile
);
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"user_data_file not found: %s"
,
c
.
UserDataFile
))
}
}
templates
:=
map
[
string
]
*
string
{
"iam_instance_profile"
:
&
c
.
IamInstanceProfile
,
"instance_type"
:
&
c
.
InstanceType
,
...
...
builder/amazon/common/run_config_test.go
View file @
3ff37469
package
common
import
(
"io/ioutil"
"os"
"testing"
)
...
...
@@ -87,3 +88,41 @@ func TestRunConfigPrepare_SSHUsername(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestRunConfigPrepare_UserData
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
tf
.
Close
()
c
.
UserData
=
"foo"
c
.
UserDataFile
=
tf
.
Name
()
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
1
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestRunConfigPrepare_UserDataFile
(
t
*
testing
.
T
)
{
c
:=
testConfig
()
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
c
.
UserDataFile
=
"idontexistidontthink"
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
1
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
tf
,
err
:=
ioutil
.
TempFile
(
""
,
"packer"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
defer
tf
.
Close
()
c
.
UserDataFile
=
tf
.
Name
()
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
builder/amazon/common/step_run_source_instance.go
View file @
3ff37469
...
...
@@ -5,6 +5,7 @@ import (
"github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"log"
)
...
...
@@ -12,6 +13,7 @@ type StepRunSourceInstance struct {
ExpectedRootDevice
string
InstanceType
string
UserData
string
UserDataFile
string
SourceAMI
string
IamInstanceProfile
string
SubnetId
string
...
...
@@ -25,11 +27,22 @@ func (s *StepRunSourceInstance) Run(state map[string]interface{}) multistep.Step
securityGroupId
:=
state
[
"securityGroupId"
]
.
(
string
)
ui
:=
state
[
"ui"
]
.
(
packer
.
Ui
)
userData
:=
s
.
UserData
if
s
.
UserDataFile
!=
""
{
contents
,
err
:=
ioutil
.
ReadFile
(
s
.
UserDataFile
)
if
err
!=
nil
{
state
[
"error"
]
=
fmt
.
Errorf
(
"Problem reading user data file: %s"
,
err
)
return
multistep
.
ActionHalt
}
userData
=
string
(
contents
)
}
runOpts
:=
&
ec2
.
RunInstances
{
KeyName
:
keyName
,
ImageId
:
s
.
SourceAMI
,
InstanceType
:
s
.
InstanceType
,
UserData
:
[]
byte
(
s
.
U
serData
),
UserData
:
[]
byte
(
u
serData
),
MinCount
:
0
,
MaxCount
:
0
,
SecurityGroups
:
[]
ec2
.
SecurityGroup
{
ec2
.
SecurityGroup
{
Id
:
securityGroupId
}},
...
...
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