Provisioning a MIG and global load balancer
Note
The code for this section is under the chap06/main
directory in the GitHub repository of this book.
To create a MIG, we first create an instance template, and then the MIG, which uses the instance template. The instance group is analogous to creating a virtual machine. Please note that we specify the service account we created and set the scopes to cloud-platform
. That follows Google Cloud best practices: https://cloud.google.com/compute/docs/access/service-accounts#scopes_best_practice.
Now, here, we can put the create_before_destroy
life cycle rule to good use. Let’s say we want to change the instance template by, for example, changing the startup script. Usually, Terraform destroys the google_compute_instance_template
resource before applying the change and creating a new resource. However, Google Cloud won’t let us destroy google_compute_instance_template
because the MIG still uses it. Hence, we use the create_before_destroy...