How to implement image family with Terraform in GCP.

Declare the machine image in terraform.tfvars.

<pre lang="yaml">
image-family = "centos-7"

Declare data type for the machine image in maint.tf.

<pre lang="yaml">
data "google_compute_image" "my_image" {
  family  = var.image-family
  project = "your-project-id"
}

In main.tf use “google_compute_instance” under boot disk section in main.tf.

<pre lang="yaml">
boot_disk {
  initialize_params {
    image = data.google_compute_image.my_image.self_link
  }
}