Terraform Template To Create 3 Nodes Failover Cluster in Google Cloud
Terraform Template To Create 3 Nodes Failover Cluster in Google Cloud
Below is a simple example of a Terraform configuration to create three instances that can be part of a
failover cluster. Please note that this example assumes you have a basic understanding of GCP, and you
might need to customize it based on your specific requirements.
hcl
Copy code
provider "google" {
credentials = file("<path-to-your-service-account-key-file.json>")
project = "<your-gcp-project>"
region = "us-central1"
count =3
boot_disk {
initialize_params {
image = "debian-cloud/debian-10"
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
name = "failover-cluster-firewall"
network = "default"
allow {
protocol = "tcp"
ports = ["22", "135", "137-139", "445", "49152-65535"] # Adjust ports as needed for your cluster
source_ranges = ["0.0.0.0/0"]
target_tags = ["failover-cluster-node"]
count = 3
tags = ["failover-cluster-node"]
output "instance_ips" {
value =
google_compute_instance.failover_cluster_node[*].network_interface[0].access_config[0].nat_ip
}
Creates three instances with a Debian 10 image. Adjust the machine_type, image, and other parameters
as needed.
Defines firewall rules to allow necessary ports for failover cluster communication.
Before running this configuration, make sure you have the necessary credentials by setting the path to
your service account key file (<path-to-your-service-account-key-file.json>) and specifying your GCP
project (<your-gcp-project>).
Remember to adapt this template based on your specific requirements, such as adjusting firewall rules,
choosing an appropriate machine type, and configuring the failover cluster appropriately based on the
technology you plan to use (e.g., Windows Server Failover Cluster, Pacemaker for Linux, etc.).