github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/website/source/docs/enterprise/faq/rolling-deployments.html.md (about) 1 --- 2 layout: "enterprise" 3 page_title: "Rolling Deployments - FAQ - Terraform Enterprise" 4 sidebar_current: "docs-enterprise-faq-deployments" 5 description: |- 6 How do I configure rolling deployments in Terraform Enterprise? 7 --- 8 9 # Rolling Deployments 10 11 *How do I configure rolling deployments?* 12 13 User are able to quickly change out an Artifact version that is being utilized 14 by Terraform, using variables within Terraform Enterprise. This is particularly 15 useful when testing specific versions of the given artifact without performing a 16 full rollout. This configuration also allows one to deploy any version of an 17 artifact with ease, simply by changing a version variable in Terraform and 18 re-deploying. 19 20 Here is an example: 21 22 ```hcl 23 variable "type" { default = "amazon.image" } 24 variable "region" {} 25 variable "atlas_username" {} 26 variable "pinned_name" {} 27 variable "pinned_version" { default = "latest" } 28 29 resource "atlas_artifact" "pinned" { 30 name = "${var.atlas_username}/${var.pinned_name}" 31 type = "${var.type}" 32 version = "${var.pinned_version}" 33 34 lifecycle { create_before_destroy = true } 35 36 metadata { 37 region = "${var.region}" 38 } 39 } 40 41 output "pinned" { value = "${atlas_artifact.pinned.metadata_full.ami_id}" } 42 ``` 43 44 45 In the above example we have an `atlas_artifact` resource where you pass in the 46 version number via the variable `pinned_version`. (_note: this variable defaults 47 to latest_). If you ever want to deploy any other version, you just update the 48 variable `pinned_version` and redeploy. 49 50 Below is similar to the first example, but it is in the form of a module that 51 handles the creation of artifacts: 52 53 ```hcl 54 variable "type" { default = "amazon.image" } 55 variable "region" {} 56 variable "atlas_username" {} 57 variable "artifact_name" {} 58 variable "artifact_version" { default = "latest" } 59 60 resource "atlas_artifact" "artifact" { 61 name = "${var.atlas_username}/${var.artifact_name}" 62 type = "${var.type}" 63 count = "${length(split(",", var.artifact_version))}" 64 version = "${element(split(",", var.artifact_version), count.index)}" 65 66 lifecycle { create_before_destroy = true } 67 metadata { region = "${var.region}" } 68 } 69 70 output "amis" { value = "${join(",", atlas_artifact.artifact.*.metadata_full.ami_id)}" } 71 ``` 72 73 One can then use the module as follows (_note: the source will likely be 74 different depending on the location of the module_): 75 76 ```hcl 77 module "artifact_consul" { 78 source = "../../../modules/aws/util/artifact" 79 80 type = "${var.artifact_type}" 81 region = "${var.region}" 82 atlas_username = "${var.atlas_username}" 83 artifact_name = "${var.consul_artifact_name}" 84 artifact_version = "${var.consul_artifacts}" 85 } 86 ``` 87 88 89 In the above example, we have created artifacts for Consul. In this example, we 90 can create two versions of the artifact, "latest" and "pinned". This is useful 91 when rolling a cluster (like Consul) one node at a time, keeping some nodes 92 pinned to current version and others deployed with the latest Artifact. 93 94 There are additional details for implementing rolling deployments in the [Best-Practices Repo](https://github.com/hashicorp/best-practices/blob/master/terraform/providers/aws/us_east_1_prod/us_east_1_prod.tf#L105-L123), as there are some things uncovered in this FAQ (i.e Using the Terraform Enterprise Artifact in an instance).