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
ef9b2291
Commit
ef9b2291
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'njones-template-timefmt'
parents
c66b5dbb
9a0f92c5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
3 deletions
+94
-3
packer/config_template.go
packer/config_template.go
+10
-2
packer/config_template_test.go
packer/config_template_test.go
+28
-0
website/source/docs/templates/configuration-templates.html.markdown
...urce/docs/templates/configuration-templates.html.markdown
+56
-1
No files found.
packer/config_template.go
View file @
ef9b2291
...
...
@@ -113,8 +113,16 @@ func templateEnv(n string) string {
return
os
.
Getenv
(
n
)
}
func
templateISOTime
()
string
{
return
InitTime
.
Format
(
time
.
RFC3339
)
func
templateISOTime
(
timeFormat
...
string
)
(
string
,
error
)
{
if
len
(
timeFormat
)
==
0
{
return
time
.
Now
()
.
UTC
()
.
Format
(
time
.
RFC3339
),
nil
}
if
len
(
timeFormat
)
>
1
{
return
""
,
fmt
.
Errorf
(
"too many values, 1 needed: %v"
,
timeFormat
)
}
return
time
.
Now
()
.
UTC
()
.
Format
(
timeFormat
[
0
]),
nil
}
func
templatePwd
()
(
string
,
error
)
{
...
...
packer/config_template_test.go
View file @
ef9b2291
package
packer
import
(
"fmt"
"math"
"os"
"strconv"
...
...
@@ -42,6 +43,33 @@ func TestConfigTemplateProcess_isotime(t *testing.T) {
}
}
// Note must format with the magic Date: Mon Jan 2 15:04:05 -0700 MST 2006
func
TestConfigTemplateProcess_isotime_withFormat
(
t
*
testing
.
T
)
{
tpl
,
err
:=
NewConfigTemplate
()
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Checking for a too-many arguments error
// Because of the variadic function, compile time checking won't work
_
,
err
=
tpl
.
Process
(
`{{isotime "20060102" "huh"}}`
,
nil
)
if
err
==
nil
{
t
.
Fatalf
(
"err: cannot have more than 1 input"
)
}
result
,
err
:=
tpl
.
Process
(
`{{isotime "20060102"}}`
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
ti
:=
time
.
Now
()
.
UTC
()
val
:=
fmt
.
Sprintf
(
"%04d%02d%02d"
,
ti
.
Year
(),
ti
.
Month
(),
ti
.
Day
())
if
result
!=
val
{
t
.
Fatalf
(
"val: %s (formated: %s)"
,
val
,
result
)
}
}
func
TestConfigTemplateProcess_pwd
(
t
*
testing
.
T
)
{
tpl
,
err
:=
NewConfigTemplate
()
if
err
!=
nil
{
...
...
website/source/docs/templates/configuration-templates.html.markdown
View file @
ef9b2291
...
...
@@ -53,13 +53,68 @@ While some configuration settings have local variables specific to only that
configuration, a set of functions are available globally for use in _any string_
in Packer templates. These are listed below for reference.
*
`isotime`
- UTC time in RFC-3339 format.
*
`lower`
- Lowercases the string.
*
`pwd`
- The working directory while executing Packer.
*
`isotime [FORMAT]`
- UTC time, which can be
[
formatted
](
http://golang.org/pkg/time/#example_Time_Format
)
.
See more examples below.
*
`timestamp`
- The current Unix timestamp in UTC.
*
`uuid`
- Returns a random UUID.
*
`upper`
- Uppercases the string.
### isotime Format
Formatting for the function
`isotime`
uses the magic reference date
**Mon Jan 2 15:04:05 -0700 MST 2006**
, which breaks down to the following:
<table
border=
"1"
cellpadding=
"5"
width=
"100%"
>
<tr
bgcolor=
"lightgray"
>
<td></td>
<td
align=
"center"
><strong>
Day of Week
</strong></td>
<td
align=
"center"
><strong>
Month
</strong></td>
<td
align=
"center"
><strong>
Date
</strong></td>
<td
align=
"center"
><strong>
Hour
</strong></td>
<td
align=
"center"
><strong>
Minute
</strong></td>
<td
align=
"center"
><strong>
Second
</strong></td>
<td
align=
"center"
><strong>
Year
</strong></td>
<td
align=
"center"
><strong>
Timezone
</strong></td>
</tr>
<tr>
<td><strong>
Numeric
</strong></td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
01
</td>
<td
align=
"center"
>
02
</td>
<td
align=
"center"
>
03 (15)
</td>
<td
align=
"center"
>
04
</td>
<td
align=
"center"
>
05
</td>
<td
align=
"center"
>
06
</td>
<td
align=
"center"
>
-0700
</td>
</tr>
<tr>
<td><strong>
Textual
</strong></td>
<td
align=
"center"
>
Monday (Mon)
</td>
<td
align=
"center"
>
January (Jan)
</td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
-
</td>
<td
align=
"center"
>
MST
</td>
</tr>
</table>
_The values in parentheses are the abbreviated, or 24-hour clock values_
Here are some example formated time, using the above format options:
<pre>
isotime = June 7, 7:22:43pm 2014
{{isotime "2006-01-02"}} = 2014-06-07
{{isotime "Mon 1506"}} = Sat 1914
{{isotime "01-Jan-06 03
\_
04
\_
05"}} = 07-Jun-2014 07
\_
22
\_
43
{{isotime "Hour15Year200603"}} = Hour19Year201407
</pre>
## Amazon Specific Functions
Specific to Amazon builders:
...
...
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