mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
Merge pull request #1919 from terraform-providers/paddy_image_docs
Add docs about image families and instance templates.
This commit is contained in:
commit
53a8ac330a
|
@ -108,6 +108,61 @@ With this setup Terraform generates a unique name for your Instance
|
||||||
Template and can then update the Instance Group manager without conflict before
|
Template and can then update the Instance Group manager without conflict before
|
||||||
destroying the previous Instance Template.
|
destroying the previous Instance Template.
|
||||||
|
|
||||||
|
## Deploying the Latest Image
|
||||||
|
|
||||||
|
A common way to use instance templates and managed instance groups is to deploy the
|
||||||
|
latest image in a family, usually the latest build of your application. There are two
|
||||||
|
ways to do this in Terraform, and they have their pros and cons. The difference ends
|
||||||
|
up being in how "latest" is interpreted. You can either deploy the latest image available
|
||||||
|
when Terraform runs, or you can have each instance check what the latest image is when
|
||||||
|
it's being created, either as part of a scaling event or being rebuilt by the instance
|
||||||
|
group manager.
|
||||||
|
|
||||||
|
If you're not sure, we recommend deploying the latest image available when Terraform runs,
|
||||||
|
because this means all the instances in your group will be based on the same image, always,
|
||||||
|
and means that no upgrades or changes to your instances happen outside of a `terraform apply`.
|
||||||
|
You can achieve this by using the [`google_compute_image`](../d/datasource_compute_image.html)
|
||||||
|
data source, which will retrieve the latest image on every `terraform apply`, and will update
|
||||||
|
the template to use that specific image:
|
||||||
|
|
||||||
|
```tf
|
||||||
|
data "google_compute_image" "my_image" {
|
||||||
|
family = "debian-9"
|
||||||
|
project = "debian-cloud"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance_template" "instance_template" {
|
||||||
|
name_prefix = "instance-template-"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
region = "us-central1"
|
||||||
|
|
||||||
|
// boot disk
|
||||||
|
disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "${data.google_compute_image.my_image.self_link}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To have instances update to the latest on every scaling event or instance re-creation,
|
||||||
|
use the family as the image for the disk, and it will use GCP's default behavior, setting
|
||||||
|
the image for the template to the family:
|
||||||
|
|
||||||
|
```tf
|
||||||
|
resource "google_compute_instance_template" "instance_template" {
|
||||||
|
name_prefix = "instance-template-"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
region = "us-central1"
|
||||||
|
|
||||||
|
// boot disk
|
||||||
|
disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-9"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Argument Reference
|
## Argument Reference
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user