This repo contains various bits of Terraform code to provision resources on Google Cloud Platform (GCP), mainly a Google Compute Instance, together with its associated resources, such as disk, network interface and provisioning metadata.
We're making use of the Always Free GCP usage tier and the 12 month, 300USD free trial to minimise the monetary impact of learning how to work with both Terraform and GCP.
The included Terraform states currently are able to provision the following resources:
- static external IP address
- virtual machine instance.
- cloud storage bucket, used for storing the instance startup script
The following attributes can be customised in the variable file,
vars.tf
:
- instance name
- instance machine type (default: f1-micro)
- instance region & zone (default: us-west1-a)
- instance maintenance behaviour (default: migrate)
- instance restart behavior (default: automatic restart)
- disk type (default: standard (HDD) persistent disk)
- disk image (default: latest CoreOS Container Linux)
- disk size (default: 30GB)
- disk auto-delete property (default: true)
- cloud storage bucket storage class (default: regional)
- Cloud SDK - we'll use the
gcloud
tool for some initial setup since Terraform GCP provider doesn't yet have complete feature support. - Terraform
Terraform GCP provider only supports creating projects that are part of an Organisation which can only be created by speaking to the Google sales team and we won't be doing that. Just navigate to the GCP Console and create a new project.
Follow the docs here to configure and download the account file.
Then update the credentials
like in the included settings.tf
file
with the name of your credentials file, e.g.
gce-project-111111111111.json
and enter the correct project ID, e.g.
111111111111
:
provider "google" {
credentials = "${file("gce-project-111111111111.json")}"
project = "111111111111"
region = "us-west1"
}
You can run terraform plan
to get the output of what Terraform is
about to do, if anything. In other words, terraform plan
will check
the existing state of the environment and prepare any required steps to
make the environment match the configuration.
Once you're happy, let Terraform apply the state:
terraform apply
And observe the results.