github.com/ratanraj/packer@v1.3.2/website/source/guides/packer-on-cicd/trigger-tfe.html.md (about)

     1  ---
     2  layout: guides
     3  sidebar_current: guides-packer-on-cicd-trigger-tfe-run
     4  page_title: Trigger Terraform Enterprise runs
     5  ---
     6  
     7  # Create Terraform Enterprise Runs
     8  
     9  Once an image is built and uploaded to an artifact store, the next step is to
    10  use this new image. In some cases the image will be downloaded by the dev team
    11  and used locally in development, like is often done with VirtualBox images with
    12  Vagrant. In most other cases, the new image will be used to provision new
    13  infrastructure.
    14  
    15  [Terraform](https://www.terraform.io/) is an open source tool that is ideal for
    16  provisioning new infrastructure with images generated by Packer, and [Terraform
    17  Enterprise](https://www.hashicorp.com/products/terraform/) is the best way to
    18  perform automated Terraform runs.
    19  
    20  ## Create a Terraform Configuration and Workspace
    21  
    22  The following is a sample Terraform configuration which provisions a new AWS
    23  EC2 instance.  The `aws_ami_id` is a variable which will be provided when
    24  running `terraform plan` and `terraform apply`. This variable references the
    25  latest AMI generated with the Packer build in CI/CD.
    26  
    27  ```hcl
    28  variable "aws_ami_id" { }
    29  
    30  provider "aws" {
    31    region = "us-west-2"
    32  }
    33  
    34  resource "aws_instance" "web" {
    35    ami           = "${var.aws_ami_id}"
    36    instance_type = "t2.micro"
    37  }
    38  ```
    39  
    40  Terraform Enterprise should have a workspace with this terraform configuration
    41  and a placeholder variable `aws_ami_id`.
    42  
    43  ## Include Terraform Enterprise in Your CI Builds
    44  
    45  Follow these steps to create a new run from CI/CD after a Packer build is
    46  complete and uploaded.
    47  
    48  1. Add a new step to the CI/CD pipeline.
    49  2. In the new step add a `curl` call to update the variables in the workspace
    50     using the [update variables
    51     API](https://www.terraform.io/docs/enterprise/api/variables.html#update-variables),
    52     so that Terraform has a reference to the latest image. For the sample
    53     configuration above, the `aws_ami_id` variable should be updated to the AMI
    54     ID of the latest image.
    55  3. In that same step, add another `curl` call to [create a new run via the
    56     API](https://www.terraform.io/docs/enterprise/api/run.html#create-a-run).
    57     A run performs a plan and apply on the last configuration version created,
    58     using the variables set in the workspace. In the previous step we update the
    59     variables, so the new run can be created using the previous configuration
    60     version.