diff --git a/website/source/docs/builders/amazon-ebs.html.markdown b/website/source/docs/builders/amazon-ebs.html.markdown index 1f66bb631..313b3ce4d 100644 --- a/website/source/docs/builders/amazon-ebs.html.markdown +++ b/website/source/docs/builders/amazon-ebs.html.markdown @@ -82,7 +82,8 @@ Here is a basic example. It is completely valid except for the access keys: ## AMI Name Variables The AMI name specified by the `ami_name` configuration variable is actually -treated as a template. Packer provides a set of variables that it will replace +treated as a [configuration template](/docs/templates/configuration-templates.html). +Packer provides a set of variables that it will replace within the AMI name. This helps ensure the AMI name is unique, as AWS requires. The available variables are shown below: diff --git a/website/source/docs/templates/configuration-templates.html.markdown b/website/source/docs/templates/configuration-templates.html.markdown new file mode 100644 index 000000000..d22e850df --- /dev/null +++ b/website/source/docs/templates/configuration-templates.html.markdown @@ -0,0 +1,49 @@ +--- +layout: "docs" +--- + +# Configuration Templates + +Certain configuration parameters within templates are themselves a +type of "template." These are not Packer templates, but text templates, +where variables can be used to modify the value of a configuration parameter +during runtime. + +For example, the `ami_name` configuration for the [AMI builder](/docs/builders/amazon-ebs.html) +is a template. An example value may be `My Packer AMI {{.CreateTime}}`. At +runtime, this will be turned into `My Packer AMI 1370900368`, where the +"CreateTime" variable was replaced with the Unix timestamp of when the +AMI was actually created. + +This sort of templating is pervasive throughout Packer. Instead of documenting +the templating syntax in each location, it is documented once here so +you know how to use it. + +
+For advanced users: The templates are actually parsed and executed +using Go's text/template +package. It therefore supports the complete template syntax. +
+ +## Syntax + +99% of the time all you'll need within configuration templates are variables. +Variables are accessed by using `{{.VARIABLENAME}}`. The "." prefixing the +variable name signals that you're accessing a variable on the root +template object. All template directives go between braces. Here is a piece +of a VMware VMX template that uses variables: + +
+.encoding = "UTF-8"
+displayName = "{{ .Name }}"
+guestOS = "{{ .GuestOS }}"
+
+ +In this case, the "Name" and "GuestOS" variables will be replaced, potentially +resulting in a VMX that looks like this: + +
+.encoding = "UTF-8"
+displayName = "packer"
+guestOS = "otherlinux"
+
diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index 37d42b16b..ee4ec2763 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -38,6 +38,7 @@
  • Introduction
  • Builders
  • Provisioners
  • +
  • Configuration Templates
  • EC2 (AMI)