Create a DNS managed zone on Google Cloud. Module in Terraform Registry.
- Create a new directory for this terraform configuration.
- Create a main.tf, for example:
# Configure the Google Cloud provider
provider "google" {
credentials = "${file("king-of-my-google-cloud-castle.json")}"
project = "smashing-dash-1992"
}
module "google-dns-managed-zone" {
source = "github.com/Eimert/terraform-google-dns-managed-zone"
dns_name = "cloud-zone"
dns_zone = "cloud.eimertvink.nl."
}
terraform init
terraform plan
Boom! Credentials file missing.- Add your google cloud credentials in a .json file. Getting started guide
Keep the Google Cloud credentials in a safe place. Don't push them to Git.
- Adapt the Terraform variables in
main.tf
to match your Google cloud project name, and VM requirements. All optional parameters can be found in variables.tf. - Let terraform fire up the VM's:
terraform apply
- Wait a few
minutesseconds. - Optionally see the created resources in Google Cloud Console
- Break down the resources:
terraform destroy
This module can be used to register a type A (name) DNS record, linking a DNS name to a VM ip address. Terraform usage example in github.com/Eimert/terraform-google-compute-engine-instance.
Result in google cloud console, after running the example (minus the A record):
My personal domain eimertvink.nl is configured with NS of freedns. This terraform plan configures Google Cloud to act as the NS for the subdomain cloud.eimertvink.nl.
But that's not all. Freedns must forwards dns queries to *.cloud.eimertvink.nl to Google's NS.
This is the configuration of freedns:
Now the subdomain cloud.eimertvink.nl is configured to forward queries to Google' nameservers. And Google Cloud is providing DNS for queries to resources under *.cloud.eimertvink.nl.