website/content/guides/packer-on-cicd/trigger-tfe.mdx
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
[!IMPORTANT]
Documentation Update: Product documentation previously located in/websitehas moved to thehashicorp/web-unified-docsrepository, where all product documentation is now centralized. Please make contributions directly toweb-unified-docs, since changes to/websitein this repository will not appear on developer.hashicorp.com. ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
Once an image is built and uploaded to an artifact store, the next step is to use this new image. In some cases the image will be downloaded by the dev team and used locally in development, like is often done with VirtualBox images with Vagrant. In most other cases, the new image will be used to provision new infrastructure.
You can use Terraform to provision new infrastructure with images generated by Packer. When working with teams, you can use HCP Terraform or Terraform Enterprise to automate Terraform runs.
The following is a sample Terraform configuration which provisions a new AWS
EC2 instance. The aws_ami_id is a variable which will be provided when
running terraform plan and terraform apply. This variable references the
latest AMI generated with the Packer build in CI/CD.
variable "aws_ami_id" { }
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "web" {
ami = "${var.aws_ami_id}"
instance_type = "t2.micro"
}
Terraform Enterprise should have a workspace with this terraform configuration
and a placeholder variable aws_ami_id.
Follow these steps to create a new run from CI/CD after a Packer build is complete and uploaded.
curl call to update the variables in the workspace
using the update variables
API,
so that Terraform has a reference to the latest image. For the sample
configuration above, the aws_ami_id variable should be updated to the AMI
ID of the latest image.curl call to create a new run via the
API.
A run performs a plan and apply on the last configuration version created,
using the variables set in the workspace. In the previous step we update the
variables, so the new run can be created using the previous configuration
version.