learn-terraform

Course outlines for learning terraform.

View the Project on GitHub robertdebock/learn-terraform

Build a compute autoscaler

expected time requirements
60 minutes a computer

Goal: Experiment with a Google Compute Autoscaler.

Explanation

A compute autoscaler allow you to treat a set of machines as one resource. Typically a load balancer sends traffic to healthy members of a compute autoscaler.

A compute autoscaler is easier to maintain than individual VM’s, for example; a single number (instances) can scale up (or down) the amount of machines in a compute autoscaler.

A computer autoscaler can also manage it’s own capacity (that’s the number if instances) using a autoscale_policy.

Howto

Have a look at the terraform documentation on compute autoscalers.

There are quite some parameters to set; you may need to search for a few examples.

Demo

See this gcp computer autoscaler example.

A nice feature of the code above is that it uses cloud-init to customize the instance. An alternative would be to make an image using a tool as packer.

Assignment

Bonus:

Questions

  1. With Terraform, there is a count parameter for resources. Instead of a google_compute_autoscaler, you could also just add count to a google_compute_instance resource. What are the benefits of a scale-set?
  2. Does terraform know of the instances that the google_compute_autoscaler has generated?