Using Terraform’s Documentation#
Terraform is a system for building cloud resources to a specification. Resources are specific to a cloud vendor and are different for each vendor. To get the most out of Terraform you should learn how to use the Google provider reference to find the resources you need and learn how to configure them. In this lab we’ll take a closer look at how resources and how to use the reference manual.
Make a lab09
Directory#
In your git repository, create copy the base
directory to create a new directory for this lab.
$ cp -R base lab09
$ cd lab09
An Example Resource#
Here’s the example instance resource from the base
configuration:
resource "google_compute_instance" "vm_instance" {
name = "cis91"
machine_type = "e2-micro"
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2004-lts"
}
}
network_interface {
network = google_compute_network.vpc_network.name
access_config {
}
}
}
The resource definitions begins with a type (google_compute_instance
) and then specifies a name (vm_instance
). Complex resources like an instance have multiple block definitions that are specific to that resource type. For example, the boot_disk
block:
boot_disk {
initialize_params {
image = "ubuntu-os-cloud/ubuntu-2004-lts"
}
}
Find the Documentation for an Instance#
Use the GCP reference manual to search for “instance”. Notice how the results are organized by the particular Google product. When you find google_compute_instance
click it and look at the reference page.
Note
Notice the attached_disk
section. It can be used to attach extra disk resources.
Find the Documentation for a Disk#
What if you want to create and attach a disk? In the instance resource you can only automatically create one disk. For additional disks you need to create the resources separately and attach them. Search for disk
in the documentation. What resources do you find? How helpful is the example?
Update your Configuration#
Using examples from the documentation see if you can add a disk. Test your code with terraform apply
. With your new VM running SSH into it and see if you can find the disk in the /dev
directory.
Turn In#
There’s nothing to turn in. This is just for practice.