You are on page 1of 3

Creating a 3-node failover cluster in Google Cloud Platform (GCP) using Terraform involves several steps.

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

# Define the provider and authentication

provider "google" {

credentials = file("<path-to-your-service-account-key-file.json>")

project = "<your-gcp-project>"

region = "us-central1"

# Define the instances

resource "google_compute_instance" "failover_cluster_node" {

count =3

name = "failover-cluster-node-${count.index + 1}"

machine_type = "n1-standard-2" # Choose an appropriate machine type

boot_disk {

initialize_params {

image = "debian-cloud/debian-10"

network_interface {

network = "default"

access_config {

// Ephemeral IP
}

# Define firewall rules to allow cluster communication

resource "google_compute_firewall" "failover_cluster_firewall" {

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"]

# Add tags to the instances

resource "google_compute_instance" "failover_cluster_node" {

count = 3

tags = ["failover-cluster-node"]

# Output the instance IPs

output "instance_ips" {

value =
google_compute_instance.failover_cluster_node[*].network_interface[0].access_config[0].nat_ip
}

This Terraform configuration does the following:

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.

Adds tags to the instances to apply the firewall rules.

Outputs the public IPs of the instances.

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.).

You might also like