tweak engine docs to contain guide docs for isotime

remove docs page
This commit is contained in:
Megan Marsh 2021-05-17 16:20:12 -07:00
parent 1d4a8e7ba2
commit d9b874f118
3 changed files with 48 additions and 126 deletions

View File

@ -235,6 +235,54 @@ documentation for more information on user variables.
# isotime Function Format Reference
The way you format isotime in golang is a bit nontraditional compared to how
you may be used to formatting datetime strings.
Full docs and examples for the golang time formatting function can be found
[here](https://golang.org/pkg/time/#example_Time_Format)
However, the formatting basics are worth describing here. From the [golang docs](https://golang.org/pkg/time/#pkg-constants):
> These are predefined layouts for use in Time.Format and time.Parse. The
> reference time used in the layouts is the specific time:
>
> Mon Jan 2 15:04:05 MST 2006
>
> which is Unix time 1136239445. Since MST is GMT-0700, the reference time
> can be thought of as
>
> 01/02 03:04:05PM '06 -0700
>
> To define your own format, write down what the reference time would look like
> formatted your way; see the values of constants like ANSIC, StampMicro or
> Kitchen for examples. The model is to demonstrate what the reference time
> looks like so that the Format and Parse methods can apply the same
> transformation to a general time value.
So what does that look like in a Packer template function? Here's an example
of how you'd declare a variable using the isotime function.
```json
"variables": {
"myvar": "packer-{{isotime `2006-01-02 03:04:05`}}"
}
```
You can try and modify the following examples in a packer template or in
`packer console` to get an idea of how to set different timestamps:
| Input | Output |
| ------------------------------------------ | ----------- |
| "packer-{{isotime `2006-01-02`}}" | "packer-2021-05-17 11:40:16" |
| "packer-{{isotime `Jan-_2-15:04:05.000`}}" | "packer-May-17-23:40:16.786" |
| "packer-{{isotime `3:04PM`}}" | "packer-11:40PM" |
| "{{ isotime }} | "June 7, 7:22:43pm 2014" |
| "{{isotime `2006-01-02`}}" | "2014-06-07" |
| "{{isotime `Mon 1504`}}" | "Sat 1922" |
| "{{isotime `02-Jan-06 03\_04\_05`}}" | "07-Jun-2014 07\_22\_43" |
| "{{isotime `Hour15Year200603`}}" | "Hour19Year201407" |
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:
@ -278,47 +326,9 @@ Formatting for the function `isotime` uses the magic reference date **Mon Jan 2
_The values in parentheses are the abbreviated, or 24-hour clock values_
For those unfamiliar with GO date/time formatting, here is a link to the
documentation: [go date/time formatting](https://programming.guide/go/format-parse-string-time-date-example.html)
Note that "-0700" is always formatted into "+0000" because `isotime` is always
UTC time.
Here are some example formatted time, using the above format options:
```liquid
isotime = June 7, 7:22:43pm 2014
{{isotime "2006-01-02"}} = 2014-06-07
{{isotime "Mon 1504"}} = Sat 1922
{{isotime "02-Jan-06 03\_04\_05"}} = 07-Jun-2014 07\_22\_43
{{isotime "Hour15Year200603"}} = Hour19Year201407
```
Please note that double quote characters need escaping inside of templates (in
this case, on the `ami_name` value):
```json
{
"builders": [
{
"type": "amazon-ebs",
"access_key": "...",
"secret_key": "...",
"region": "us-east-1",
"source_ami": "ami-fce3c696",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer {{isotime \"2006-01-02\"}}"
}
]
}
```
-> **Note:** See the [Amazon builder](/docs/builders/amazon)
documentation for more information on how to correctly configure the Amazon
builder in this example.
# split Function Format Reference
The function `split` takes an input string, a seperator string, and a numeric

View File

@ -1,84 +0,0 @@
---
page_title: Using the isotime template function - Guides
description: |-
It can be a bit confusing to figure out how to format your isotime using the
golang reference date string. Here is a small guide and some examples.
---
# Using the Isotime template function with a format string
The way you format isotime in golang is a bit nontraditional compared to how
you may be used to formatting datetime strings.
Full docs and examples for the golang time formatting function can be found
[here](https://golang.org/pkg/time/#example_Time_Format)
However, the formatting basics are worth describing here. From the [golang docs](https://golang.org/pkg/time/#pkg-constants):
> These are predefined layouts for use in Time.Format and time.Parse. The
> reference time used in the layouts is the specific time:
>
> Mon Jan 2 15:04:05 MST 2006
>
> which is Unix time 1136239445. Since MST is GMT-0700, the reference time
> can be thought of as
>
> 01/02 03:04:05PM '06 -0700
>
> To define your own format, write down what the reference time would look like
> formatted your way; see the values of constants like ANSIC, StampMicro or
> Kitchen for examples. The model is to demonstrate what the reference time
> looks like so that the Format and Parse methods can apply the same
> transformation to a general time value.
So what does that look like in a Packer template function?
```json
{
"variables": {
"myvar": "packer-{{isotime \"2006-01-02 03:04:05\"}}"
},
"builders": [
{
"type": "null",
"communicator": "none"
}
],
"provisioners": [
{
"type": "shell-local",
"inline": ["echo {{ user `myvar`}}"]
}
]
}
```
You can switch out the variables section above with the following examples to
get different timestamps:
Date only, not time:
```json
"variables":
{
"myvar": "packer-{{isotime \"2006-01-02\"}}"
}
```
A timestamp down to the millisecond:
```json
"variables":
{
"myvar": "packer-{{isotime \"Jan-_2-15:04:05.000\"}}"
}
```
Or just the time as it would appear on a digital clock:
```json
"variables":
{
"myvar": "packer-{{isotime \"3:04PM\"}}"
}
```

View File

@ -52,10 +52,6 @@
"title": "Overview",
"path": "workflow-tips-and-tricks"
},
{
"title": "Isotime Template Function",
"path": "workflow-tips-and-tricks/isotime-template-function"
},
{
"title": "Use jq to strip comments from a Packer template",
"path": "workflow-tips-and-tricks/use-packer-with-comment"