@@ -108,6 +108,61 @@ With this setup Terraform generates a unique name for your Instance
108
108
Template and can then update the Instance Group manager without conflict before
109
109
destroying the previous Instance Template.
110
110
111
+ ## Deploying the Latest Image
112
+
113
+ A common way to use instance templates and managed instance groups is to deploy the
114
+ latest image in a family, usually the latest build of your application. There are two
115
+ ways to do this in Terraform, and they have their pros and cons. The difference ends
116
+ up being in how "latest" is interpreted. You can either deploy the latest image available
117
+ when Terraform runs, or you can have each instance check what the latest image is when
118
+ it's being created, either as part of a scaling event or being rebuilt by the instance
119
+ group manager.
120
+
121
+ If you're not sure, we recommend deploying the latest image available when Terraform runs,
122
+ because this means all the instances in your group will be based on the same image, always,
123
+ and means that no upgrades or changes to your instances happen outside of a ` terraform apply ` .
124
+ You can achieve this by using the [ ` google_compute_image ` ] ( ../d/datasource_compute_image.html )
125
+ data source, which will retrieve the latest image on every ` terraform apply ` , and will update
126
+ the template to use that specific image:
127
+
128
+ ``` tf
129
+ data "google_compute_image" "my_image" {
130
+ family = "debian-9"
131
+ project = "debian-cloud"
132
+ }
133
+
134
+ resource "google_compute_instance_template" "instance_template" {
135
+ name_prefix = "instance-template-"
136
+ machine_type = "n1-standard-1"
137
+ region = "us-central1"
138
+
139
+ // boot disk
140
+ disk {
141
+ initialize_params {
142
+ image = "${data.google_compute_image.my_image.self_link}"
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ To have instances update to the latest on every scaling event or instance re-creation,
149
+ use the family as the image for the disk, and it will use GCP's default behavior, setting
150
+ the image for the template to the family:
151
+
152
+ ``` tf
153
+ resource "google_compute_instance_template" "instance_template" {
154
+ name_prefix = "instance-template-"
155
+ machine_type = "n1-standard-1"
156
+ region = "us-central1"
157
+
158
+ // boot disk
159
+ disk {
160
+ initialize_params {
161
+ image = "debian-cloud/debian-9"
162
+ }
163
+ }
164
+ }
165
+ ```
111
166
112
167
## Argument Reference
113
168
0 commit comments