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
96cc8a4a
Commit
96cc8a4a
authored
Aug 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/common: access config uses template processing
parent
4c2ada1e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
5 deletions
+34
-5
builder/amazon/common/access_config.go
builder/amazon/common/access_config.go
+31
-2
builder/amazon/common/access_config_test.go
builder/amazon/common/access_config_test.go
+3
-3
No files found.
builder/amazon/common/access_config.go
View file @
96cc8a4a
...
...
@@ -3,6 +3,7 @@ package common
import
(
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/packer/common"
"strings"
"unicode"
)
...
...
@@ -36,12 +37,40 @@ func (c *AccessConfig) Region() (aws.Region, error) {
return
aws
.
Regions
[
region
],
nil
}
func
(
c
*
AccessConfig
)
Prepare
()
[]
error
{
func
(
c
*
AccessConfig
)
Prepare
(
t
*
common
.
Template
)
[]
error
{
if
t
==
nil
{
var
err
error
t
,
err
=
common
.
NewTemplate
()
if
err
!=
nil
{
return
[]
error
{
err
}
}
}
templates
:=
map
[
string
]
*
string
{
"access_key"
:
&
c
.
AccessKey
,
"secret_key"
:
&
c
.
SecretKey
,
"region"
:
&
c
.
RawRegion
,
}
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
c
.
RawRegion
!=
""
{
if
_
,
ok
:=
aws
.
Regions
[
c
.
RawRegion
];
!
ok
{
return
[]
error
{
fmt
.
Errorf
(
"Unknown region: %s"
,
c
.
RawRegion
)}
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unknown region: %s"
,
c
.
RawRegion
))
}
}
if
len
(
errs
)
>
0
{
return
errs
}
return
nil
}
builder/amazon/common/access_config_test.go
View file @
96cc8a4a
...
...
@@ -11,17 +11,17 @@ func testAccessConfig() *AccessConfig {
func
TestAccessConfigPrepare_Region
(
t
*
testing
.
T
)
{
c
:=
testAccessConfig
()
c
.
RawRegion
=
""
if
err
:=
c
.
Prepare
();
err
!=
nil
{
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
}
c
.
RawRegion
=
"us-east-12"
if
err
:=
c
.
Prepare
();
err
==
nil
{
if
err
:=
c
.
Prepare
(
nil
);
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
c
.
RawRegion
=
"us-east-1"
if
err
:=
c
.
Prepare
();
err
!=
nil
{
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
}
}
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