terraform/website/source/docs/enterprise/packer/artifacts/creating-vagrant-boxes.html.md

142 lines
4.2 KiB
Markdown
Raw Normal View History

2017-03-21 23:01:58 +01:00
---
2017-04-03 19:53:38 +02:00
layout: "enterprise"
2017-04-07 06:00:42 +02:00
page_title: "Creating Vagrant Boxes - Packer Artifacts - Terraform Enterprise"
2017-04-03 19:53:38 +02:00
sidebar_current: "docs-enterprise-packerartifacts-vagrant"
2017-03-22 18:31:44 +01:00
description: |-
Creating Vagrant artifacts with Terraform Enterprise.
2017-03-21 23:01:58 +01:00
---
# Creating Vagrant Boxes with Packer
2017-04-07 06:00:42 +02:00
We recommend using Packer to create boxes, as is it is fully repeatable and
keeps a strong history of changes within Terraform Enterprise.
2017-03-21 23:01:58 +01:00
## Getting Started
2017-04-07 06:00:42 +02:00
Using Packer requires more up front effort, but the repeatable and automated
builds will end any manual management of boxes. Additionally, all boxes will be
stored and served from Terraform Enterprise, keeping a history along the way.
2017-03-21 23:01:58 +01:00
## Post-Processors
2017-04-07 06:00:42 +02:00
Packer uses
[post-processors](https://packer.io/docs/templates/post-processors.html) to
define how to process images and artifacts after provisioning. Both the
`vagrant` and `atlas` post-processors must be used in order to upload Vagrant
Boxes to Terraform Enterprise via Packer.
2017-03-21 23:01:58 +01:00
It's important that they are [sequenced](https://packer.io/docs/templates/post-processors.html)
in the Packer template so they run in order. This is done by nesting arrays:
2017-04-07 06:00:42 +02:00
```javascript
{
"post-processors": [
[
{
"type": "vagrant"
// ...
},
{
"type": "atlas"
// ...
}
2017-03-21 23:01:58 +01:00
]
2017-04-07 06:00:42 +02:00
]
}
```
2017-03-21 23:01:58 +01:00
Sequencing automatically passes the resulting artifact from one
post-processor to the next in this case, the `.box` file.
### Vagrant Post-Processor
The [Vagrant post-processor](https://packer.io/docs/post-processors/vagrant.html) is required to package the image
from the build (an `.ovf` file, for example) into a `.box` file before
passing it to the `atlas` post-processor.
2017-04-07 06:00:42 +02:00
```json
{
"type": "vagrant",
"keep_input_artifact": false
}
```
2017-03-21 23:01:58 +01:00
The input artifact (i.e and `.ovf` file) does not need to be kept when building Vagrant Boxes,
as the resulting `.box` will contain it.
2017-03-22 18:31:44 +01:00
### Post-Processor
2017-03-21 23:01:58 +01:00
2017-03-22 18:31:44 +01:00
The [post-processor](https://packer.io/docs/post-processors/atlas.html) takes the resulting `.box` file and uploads it adding metadata about the box version.
2017-03-21 23:01:58 +01:00
2017-04-07 06:00:42 +02:00
```json
{
"type": "atlas",
"artifact": "my-username/dev-environment",
"artifact_type": "vagrant.box",
"metadata": {
"provider": "vmware_desktop",
"version": "0.0.1"
}
}
```
2017-03-21 23:01:58 +01:00
#### Attributes Required
2017-03-22 18:31:44 +01:00
These are all of the attributes for that post-processor
2017-03-21 23:01:58 +01:00
required for uploading Vagrant Boxes. A complete example is shown below.
- `artifact`: The username and box name (`username/name`) you're creating the version
of the box under. If the box doesn't exist, it will be automatically
created
2017-03-22 18:31:44 +01:00
- `artifact_type`: This must be `vagrant.box`. Terraform Enterprise uses this to determine
2017-03-21 23:01:58 +01:00
how to treat this artifact.
For `vagrant.box` type artifacts, you can specify keys in the metadata block:
- `provider`: The Vagrant provider for the box. Common providers are
`virtualbox`, `vmware_desktop`, `aws` and so on _(required)_
2017-03-22 18:31:44 +01:00
- `version`: This is the Vagrant box version and is constrained to the
2017-03-21 23:01:58 +01:00
same formatting as in the web UI: `*.*.*` _(optional, but required for boxes
with multiple providers). The version will increment on the minor version if left blank (e.g the initial version will be set to 0.1.0, the subsequent version will be set to 0.2.0)._
- `description`: This is the description that will be shown with the
2017-03-21 23:01:58 +01:00
version of the box. You can use Markdown for links and style. _(optional)_
## Example
2017-03-22 18:31:44 +01:00
An example post-processor block for Terraform Enterprise and Vagrant is below. In this example,
2017-03-21 23:01:58 +01:00
the build runs on both VMware and Virtualbox creating two
different providers for the same box version (`0.0.1`).
2017-04-07 06:00:42 +02:00
```json
{
"post-processors": [
[
{
"type": "vagrant",
"keep_input_artifact": false
},
{
"type": "atlas",
"only": ["vmware-iso"],
"artifact": "my-username/dev-environment",
"artifact_type": "vagrant.box",
"metadata": {
"provider": "vmware_desktop",
"version": "0.0.1"
2017-03-21 23:01:58 +01:00
}
2017-04-07 06:00:42 +02:00
},
{
"type": "atlas",
"only": ["virtualbox-iso"],
"artifact": "my-username/dev-environment",
"artifact_type": "vagrant.box",
"metadata": {
"provider": "virtualbox",
"version": "0.0.1"
}
}
2017-03-21 23:01:58 +01:00
]
2017-04-07 06:00:42 +02:00
]
}
```