Instance class

A managed alloydb cluster instance.

To get more information about Instance, see:

> Warning: Deleting an instance with instanceType = SECONDARY does not delete the secondary instance, and abandons it instead. Use deletionPolicy = "FORCE" in the associated secondary cluster and delete the cluster forcefully to delete the secondary cluster as well its associated secondary instance. Users can undo the delete secondary instance action by importing the deleted secondary instance by calling terraform import.

Example Usage

Alloydb Instance Basic

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const defaultNetwork = new gcp.compute.Network("default", {name: "alloydb-network"});
const defaultCluster = new gcp.alloydb.Cluster("default", {
    clusterId: "alloydb-cluster",
    location: "us-central1",
    networkConfig: {
        network: defaultNetwork.id,
    },
    initialUser: {
        password: "alloydb-cluster",
    },
    deletionProtection: false,
});
const privateIpAlloc = new gcp.compute.GlobalAddress("private_ip_alloc", {
    name: "alloydb-cluster",
    addressType: "INTERNAL",
    purpose: "VPC_PEERING",
    prefixLength: 16,
    network: defaultNetwork.id,
});
const vpcConnection = new gcp.servicenetworking.Connection("vpc_connection", {
    network: defaultNetwork.id,
    service: "servicenetworking.googleapis.com",
    reservedPeeringRanges: [privateIpAlloc.name],
});
const _default = new gcp.alloydb.Instance("default", {
    cluster: defaultCluster.name,
    instanceId: "alloydb-instance",
    instanceType: "PRIMARY",
    machineConfig: {
        cpuCount: 2,
    },
}, {
    dependsOn: [vpcConnection],
});
const project = gcp.organizations.getProject({});
import pulumi
import pulumi_gcp as gcp

default_network = gcp.compute.Network("default", name="alloydb-network")
default_cluster = gcp.alloydb.Cluster("default",
    cluster_id="alloydb-cluster",
    location="us-central1",
    network_config={
        "network": default_network.id,
    },
    initial_user={
        "password": "alloydb-cluster",
    },
    deletion_protection=False)
private_ip_alloc = gcp.compute.GlobalAddress("private_ip_alloc",
    name="alloydb-cluster",
    address_type="INTERNAL",
    purpose="VPC_PEERING",
    prefix_length=16,
    network=default_network.id)
vpc_connection = gcp.servicenetworking.Connection("vpc_connection",
    network=default_network.id,
    service="servicenetworking.googleapis.com",
    reserved_peering_ranges=[private_ip_alloc.name])
default = gcp.alloydb.Instance("default",
    cluster=default_cluster.name,
    instance_id="alloydb-instance",
    instance_type="PRIMARY",
    machine_config={
        "cpu_count": 2,
    },
    opts = pulumi.ResourceOptions(depends_on=[vpc_connection]))
project = gcp.organizations.get_project()
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() =>
{
    var defaultNetwork = new Gcp.Compute.Network("default", new()
    {
        Name = "alloydb-network",
    });

    var defaultCluster = new Gcp.Alloydb.Cluster("default", new()
    {
        ClusterId = "alloydb-cluster",
        Location = "us-central1",
        NetworkConfig = new Gcp.Alloydb.Inputs.ClusterNetworkConfigArgs
        {
            Network = defaultNetwork.Id,
        },
        InitialUser = new Gcp.Alloydb.Inputs.ClusterInitialUserArgs
        {
            Password = "alloydb-cluster",
        },
        DeletionProtection = false,
    });

    var privateIpAlloc = new Gcp.Compute.GlobalAddress("private_ip_alloc", new()
    {
        Name = "alloydb-cluster",
        AddressType = "INTERNAL",
        Purpose = "VPC_PEERING",
        PrefixLength = 16,
        Network = defaultNetwork.Id,
    });

    var vpcConnection = new Gcp.ServiceNetworking.Connection("vpc_connection", new()
    {
        Network = defaultNetwork.Id,
        Service = "servicenetworking.googleapis.com",
        ReservedPeeringRanges = new[]
        {
            privateIpAlloc.Name,
        },
    });

    var @default = new Gcp.Alloydb.Instance("default", new()
    {
        Cluster = defaultCluster.Name,
        InstanceId = "alloydb-instance",
        InstanceType = "PRIMARY",
        MachineConfig = new Gcp.Alloydb.Inputs.InstanceMachineConfigArgs
        {
            CpuCount = 2,
        },
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            vpcConnection,
        },
    });

    var project = Gcp.Organizations.GetProject.Invoke();

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/alloydb"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/servicenetworking"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		defaultNetwork, err := compute.NewNetwork(ctx, "default", &compute.NetworkArgs{
			Name: pulumi.String("alloydb-network"),
		})
		if err != nil {
			return err
		}
		defaultCluster, err := alloydb.NewCluster(ctx, "default", &alloydb.ClusterArgs{
			ClusterId: pulumi.String("alloydb-cluster"),
			Location:  pulumi.String("us-central1"),
			NetworkConfig: &alloydb.ClusterNetworkConfigArgs{
				Network: defaultNetwork.ID().ToIDOutput().ToStringOutput(),
			},
			InitialUser: &alloydb.ClusterInitialUserArgs{
				Password: pulumi.String("alloydb-cluster"),
			},
			DeletionProtection: pulumi.Bool(false),
		})
		if err != nil {
			return err
		}
		privateIpAlloc, err := compute.NewGlobalAddress(ctx, "private_ip_alloc", &compute.GlobalAddressArgs{
			Name:         pulumi.String("alloydb-cluster"),
			AddressType:  pulumi.String("INTERNAL"),
			Purpose:      pulumi.String("VPC_PEERING"),
			PrefixLength: pulumi.Int(16),
			Network:      defaultNetwork.ID().ToIDOutput().ToStringOutput(),
		})
		if err != nil {
			return err
		}
		vpcConnection, err := servicenetworking.NewConnection(ctx, "vpc_connection", &servicenetworking.ConnectionArgs{
			Network: defaultNetwork.ID().ToIDOutput().ToStringOutput(),
			Service: pulumi.String("servicenetworking.googleapis.com"),
			ReservedPeeringRanges: pulumi.StringArray{
				privateIpAlloc.Name,
			},
		})
		if err != nil {
			return err
		}
		_, err = alloydb.NewInstance(ctx, "default", &alloydb.InstanceArgs{
			Cluster:      defaultCluster.Name,
			InstanceId:   pulumi.String("alloydb-instance"),
			InstanceType: pulumi.String("PRIMARY"),
			MachineConfig: &alloydb.InstanceMachineConfigArgs{
				CpuCount: pulumi.Int(2),
			},
		}, pulumi.DependsOn([]pulumi.Resource{
			vpcConnection,
		}))
		if err != nil {
			return err
		}
		_, err = organizations.LookupProject(ctx, &organizations.LookupProjectArgs{}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

data "gcp_organizations_getproject" "project" {
}

resource "gcp_alloydb_instance" "default" {
  depends_on    = [gcp_servicenetworking_connection.vpc_connection]
  cluster       = gcp_alloydb_cluster.default.name
  instance_id   = "alloydb-instance"
  instance_type = "PRIMARY"
  machine_config = {
    cpu_count = 2
  }
}
resource "gcp_alloydb_cluster" "default" {
  cluster_id = "alloydb-cluster"
  location   = "us-central1"
  network_config = {
    network = gcp_compute_network.default.id
  }
  initial_user = {
    password = "alloydb-cluster"
  }
  deletion_protection = false
}
resource "gcp_compute_network" "default" {
  name = "alloydb-network"
}
resource "gcp_compute_globaladdress" "private_ip_alloc" {
  name          = "alloydb-cluster"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  prefix_length = 16
  network       = gcp_compute_network.default.id
}
resource "gcp_servicenetworking_connection" "vpc_connection" {
  network                 = gcp_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [gcp_compute_globaladdress.private_ip_alloc.name]
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.Network;
import com.pulumi.gcp.compute.NetworkArgs;
import com.pulumi.gcp.alloydb.Cluster;
import com.pulumi.gcp.alloydb.ClusterArgs;
import com.pulumi.gcp.alloydb.inputs.ClusterNetworkConfigArgs;
import com.pulumi.gcp.alloydb.inputs.ClusterInitialUserArgs;
import com.pulumi.gcp.compute.GlobalAddress;
import com.pulumi.gcp.compute.GlobalAddressArgs;
import com.pulumi.gcp.servicenetworking.Connection;
import com.pulumi.gcp.servicenetworking.ConnectionArgs;
import com.pulumi.gcp.alloydb.Instance;
import com.pulumi.gcp.alloydb.InstanceArgs;
import com.pulumi.gcp.alloydb.inputs.InstanceMachineConfigArgs;
import com.pulumi.gcp.organizations.OrganizationsFunctions;
import com.pulumi.gcp.organizations.inputs.GetProjectArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()
            .name("alloydb-network")
            .build());

        var defaultCluster = new Cluster("defaultCluster", ClusterArgs.builder()
            .clusterId("alloydb-cluster")
            .location("us-central1")
            .networkConfig(ClusterNetworkConfigArgs.builder()
                .network(defaultNetwork.id())
                .build())
            .initialUser(ClusterInitialUserArgs.builder()
                .password("alloydb-cluster")
                .build())
            .deletionProtection(false)
            .build());

        var privateIpAlloc = new GlobalAddress("privateIpAlloc", GlobalAddressArgs.builder()
            .name("alloydb-cluster")
            .addressType("INTERNAL")
            .purpose("VPC_PEERING")
            .prefixLength(16)
            .network(defaultNetwork.id())
            .build());

        var vpcConnection = new Connection("vpcConnection", ConnectionArgs.builder()
            .network(defaultNetwork.id())
            .service("servicenetworking.googleapis.com")
            .reservedPeeringRanges(privateIpAlloc.name())
            .build());

        var default_ = new Instance("default", InstanceArgs.builder()
            .cluster(defaultCluster.name())
            .instanceId("alloydb-instance")
            .instanceType("PRIMARY")
            .machineConfig(InstanceMachineConfigArgs.builder()
                .cpuCount(2)
                .build())
            .build(), CustomResourceOptions.builder()
                .dependsOn(vpcConnection)
                .build());

        final var project = OrganizationsFunctions.getProject(GetProjectArgs.builder()
            .build());

    }
}
resources:
  default:
    type: gcp:alloydb:Instance
    properties:
      cluster: ${defaultCluster.name}
      instanceId: alloydb-instance
      instanceType: PRIMARY
      machineConfig:
        cpuCount: 2
    options:
      dependsOn:
        - ${vpcConnection}
  defaultCluster:
    type: gcp:alloydb:Cluster
    name: default
    properties:
      clusterId: alloydb-cluster
      location: us-central1
      networkConfig:
        network: ${defaultNetwork.id}
      initialUser:
        password: alloydb-cluster
      deletionProtection: false
  defaultNetwork:
    type: gcp:compute:Network
    name: default
    properties:
      name: alloydb-network
  privateIpAlloc:
    type: gcp:compute:GlobalAddress
    name: private_ip_alloc
    properties:
      name: alloydb-cluster
      addressType: INTERNAL
      purpose: VPC_PEERING
      prefixLength: 16
      network: ${defaultNetwork.id}
  vpcConnection:
    type: gcp:servicenetworking:Connection
    name: vpc_connection
    properties:
      network: ${defaultNetwork.id}
      service: servicenetworking.googleapis.com
      reservedPeeringRanges:
        - ${privateIpAlloc.name}
variables:
  project:
    fn::invoke:
      function: gcp:organizations:getProject
      arguments: {}

Alloydb Secondary Instance Basic

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";

const _default = new gcp.compute.Network("default", {name: "alloydb-secondary-network"});
const primary = new gcp.alloydb.Cluster("primary", {
    clusterId: "alloydb-primary-cluster",
    location: "us-central1",
    networkConfig: {
        network: _default.id,
    },
    deletionProtection: false,
});
const privateIpAlloc = new gcp.compute.GlobalAddress("private_ip_alloc", {
    name: "alloydb-secondary-instance",
    addressType: "INTERNAL",
    purpose: "VPC_PEERING",
    prefixLength: 16,
    network: _default.id,
});
const vpcConnection = new gcp.servicenetworking.Connection("vpc_connection", {
    network: _default.id,
    service: "servicenetworking.googleapis.com",
    reservedPeeringRanges: [privateIpAlloc.name],
});
const primaryInstance = new gcp.alloydb.Instance("primary", {
    cluster: primary.name,
    instanceId: "alloydb-primary-instance",
    instanceType: "PRIMARY",
    machineConfig: {
        cpuCount: 2,
    },
}, {
    dependsOn: [vpcConnection],
});
const secondary = new gcp.alloydb.Cluster("secondary", {
    clusterId: "alloydb-secondary-cluster",
    location: "us-east1",
    networkConfig: {
        network: defaultGoogleComputeNetwork.id,
    },
    clusterType: "SECONDARY",
    continuousBackupConfig: {
        enabled: false,
    },
    secondaryConfig: {
        primaryClusterName: primary.name,
    },
    deletionPolicy: "FORCE",
    deletionProtection: false,
}, {
    dependsOn: [primaryInstance],
});
const secondaryInstance = new gcp.alloydb.Instance("secondary", {
    cluster: secondary.name,
    instanceId: "alloydb-secondary-instance",
    instanceType: secondary.clusterType,
    machineConfig: {
        cpuCount: 2,
    },
}, {
    dependsOn: [vpcConnection],
});
const project = gcp.organizations.getProject({});
import pulumi
import pulumi_gcp as gcp

default = gcp.compute.Network("default", name="alloydb-secondary-network")
primary = gcp.alloydb.Cluster("primary",
    cluster_id="alloydb-primary-cluster",
    location="us-central1",
    network_config={
        "network": default.id,
    },
    deletion_protection=False)
private_ip_alloc = gcp.compute.GlobalAddress("private_ip_alloc",
    name="alloydb-secondary-instance",
    address_type="INTERNAL",
    purpose="VPC_PEERING",
    prefix_length=16,
    network=default.id)
vpc_connection = gcp.servicenetworking.Connection("vpc_connection",
    network=default.id,
    service="servicenetworking.googleapis.com",
    reserved_peering_ranges=[private_ip_alloc.name])
primary_instance = gcp.alloydb.Instance("primary",
    cluster=primary.name,
    instance_id="alloydb-primary-instance",
    instance_type="PRIMARY",
    machine_config={
        "cpu_count": 2,
    },
    opts = pulumi.ResourceOptions(depends_on=[vpc_connection]))
secondary = gcp.alloydb.Cluster("secondary",
    cluster_id="alloydb-secondary-cluster",
    location="us-east1",
    network_config={
        "network": default_google_compute_network["id"],
    },
    cluster_type="SECONDARY",
    continuous_backup_config={
        "enabled": False,
    },
    secondary_config={
        "primary_cluster_name": primary.name,
    },
    deletion_policy="FORCE",
    deletion_protection=False,
    opts = pulumi.ResourceOptions(depends_on=[primary_instance]))
secondary_instance = gcp.alloydb.Instance("secondary",
    cluster=secondary.name,
    instance_id="alloydb-secondary-instance",
    instance_type=secondary.cluster_type,
    machine_config={
        "cpu_count": 2,
    },
    opts = pulumi.ResourceOptions(depends_on=[vpc_connection]))
project = gcp.organizations.get_project()
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;

return await Deployment.RunAsync(() =>
{
    var @default = new Gcp.Compute.Network("default", new()
    {
        Name = "alloydb-secondary-network",
    });

    var primary = new Gcp.Alloydb.Cluster("primary", new()
    {
        ClusterId = "alloydb-primary-cluster",
        Location = "us-central1",
        NetworkConfig = new Gcp.Alloydb.Inputs.ClusterNetworkConfigArgs
        {
            Network = @default.Id,
        },
        DeletionProtection = false,
    });

    var privateIpAlloc = new Gcp.Compute.GlobalAddress("private_ip_alloc", new()
    {
        Name = "alloydb-secondary-instance",
        AddressType = "INTERNAL",
        Purpose = "VPC_PEERING",
        PrefixLength = 16,
        Network = @default.Id,
    });

    var vpcConnection = new Gcp.ServiceNetworking.Connection("vpc_connection", new()
    {
        Network = @default.Id,
        Service = "servicenetworking.googleapis.com",
        ReservedPeeringRanges = new[]
        {
            privateIpAlloc.Name,
        },
    });

    var primaryInstance = new Gcp.Alloydb.Instance("primary", new()
    {
        Cluster = primary.Name,
        InstanceId = "alloydb-primary-instance",
        InstanceType = "PRIMARY",
        MachineConfig = new Gcp.Alloydb.Inputs.InstanceMachineConfigArgs
        {
            CpuCount = 2,
        },
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            vpcConnection,
        },
    });

    var secondary = new Gcp.Alloydb.Cluster("secondary", new()
    {
        ClusterId = "alloydb-secondary-cluster",
        Location = "us-east1",
        NetworkConfig = new Gcp.Alloydb.Inputs.ClusterNetworkConfigArgs
        {
            Network = defaultGoogleComputeNetwork.Id,
        },
        ClusterType = "SECONDARY",
        ContinuousBackupConfig = new Gcp.Alloydb.Inputs.ClusterContinuousBackupConfigArgs
        {
            Enabled = false,
        },
        SecondaryConfig = new Gcp.Alloydb.Inputs.ClusterSecondaryConfigArgs
        {
            PrimaryClusterName = primary.Name,
        },
        DeletionPolicy = "FORCE",
        DeletionProtection = false,
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            primaryInstance,
        },
    });

    var secondaryInstance = new Gcp.Alloydb.Instance("secondary", new()
    {
        Cluster = secondary.Name,
        InstanceId = "alloydb-secondary-instance",
        InstanceType = secondary.ClusterType,
        MachineConfig = new Gcp.Alloydb.Inputs.InstanceMachineConfigArgs
        {
            CpuCount = 2,
        },
    }, new CustomResourceOptions
    {
        DependsOn =
        {
            vpcConnection,
        },
    });

    var project = Gcp.Organizations.GetProject.Invoke();

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/alloydb"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/compute"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/organizations"
	"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/servicenetworking"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_default, err := compute.NewNetwork(ctx, "default", &compute.NetworkArgs{
			Name: pulumi.String("alloydb-secondary-network"),
		})
		if err != nil {
			return err
		}
		primary, err := alloydb.NewCluster(ctx, "primary", &alloydb.ClusterArgs{
			ClusterId: pulumi.String("alloydb-primary-cluster"),
			Location:  pulumi.String("us-central1"),
			NetworkConfig: &alloydb.ClusterNetworkConfigArgs{
				Network: _default.ID().ToIDOutput().ToStringOutput(),
			},
			DeletionProtection: pulumi.Bool(false),
		})
		if err != nil {
			return err
		}
		privateIpAlloc, err := compute.NewGlobalAddress(ctx, "private_ip_alloc", &compute.GlobalAddressArgs{
			Name:         pulumi.String("alloydb-secondary-instance"),
			AddressType:  pulumi.String("INTERNAL"),
			Purpose:      pulumi.String("VPC_PEERING"),
			PrefixLength: pulumi.Int(16),
			Network:      _default.ID().ToIDOutput().ToStringOutput(),
		})
		if err != nil {
			return err
		}
		vpcConnection, err := servicenetworking.NewConnection(ctx, "vpc_connection", &servicenetworking.ConnectionArgs{
			Network: _default.ID().ToIDOutput().ToStringOutput(),
			Service: pulumi.String("servicenetworking.googleapis.com"),
			ReservedPeeringRanges: pulumi.StringArray{
				privateIpAlloc.Name,
			},
		})
		if err != nil {
			return err
		}
		primaryInstance, err := alloydb.NewInstance(ctx, "primary", &alloydb.InstanceArgs{
			Cluster:      primary.Name,
			InstanceId:   pulumi.String("alloydb-primary-instance"),
			InstanceType: pulumi.String("PRIMARY"),
			MachineConfig: &alloydb.InstanceMachineConfigArgs{
				CpuCount: pulumi.Int(2),
			},
		}, pulumi.DependsOn([]pulumi.Resource{
			vpcConnection,
		}))
		if err != nil {
			return err
		}
		secondary, err := alloydb.NewCluster(ctx, "secondary", &alloydb.ClusterArgs{
			ClusterId: pulumi.String("alloydb-secondary-cluster"),
			Location:  pulumi.String("us-east1"),
			NetworkConfig: &alloydb.ClusterNetworkConfigArgs{
				Network: pulumi.Any(defaultGoogleComputeNetwork.Id),
			},
			ClusterType: pulumi.String("SECONDARY"),
			ContinuousBackupConfig: &alloydb.ClusterContinuousBackupConfigArgs{
				Enabled: pulumi.Bool(false),
			},
			SecondaryConfig: &alloydb.ClusterSecondaryConfigArgs{
				PrimaryClusterName: primary.Name,
			},
			DeletionPolicy:     pulumi.String("FORCE"),
			DeletionProtection: pulumi.Bool(false),
		}, pulumi.DependsOn([]pulumi.Resource{
			primaryInstance,
		}))
		if err != nil {
			return err
		}
		_, err = alloydb.NewInstance(ctx, "secondary", &alloydb.InstanceArgs{
			Cluster:      secondary.Name,
			InstanceId:   pulumi.String("alloydb-secondary-instance"),
			InstanceType: secondary.ClusterType,
			MachineConfig: &alloydb.InstanceMachineConfigArgs{
				CpuCount: pulumi.Int(2),
			},
		}, pulumi.DependsOn([]pulumi.Resource{
			vpcConnection,
		}))
		if err != nil {
			return err
		}
		_, err = organizations.LookupProject(ctx, &organizations.LookupProjectArgs{}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    gcp = {
      source = "pulumi/gcp"
    }
  }
}

data "gcp_organizations_getproject" "project" {
}

resource "gcp_alloydb_cluster" "primary" {
  cluster_id = "alloydb-primary-cluster"
  location   = "us-central1"
  network_config = {
    network = gcp_compute_network.default.id
  }
  deletion_protection = false
}
resource "gcp_alloydb_instance" "primary" {
  depends_on    = [gcp_servicenetworking_connection.vpc_connection]
  cluster       = gcp_alloydb_cluster.primary.name
  instance_id   = "alloydb-primary-instance"
  instance_type = "PRIMARY"
  machine_config = {
    cpu_count = 2
  }
}
resource "gcp_alloydb_cluster" "secondary" {
  depends_on = [gcp_alloydb_instance.primary]
  cluster_id = "alloydb-secondary-cluster"
  location   = "us-east1"
  network_config = {
    network = defaultGoogleComputeNetwork.id
  }
  cluster_type = "SECONDARY"
  continuous_backup_config = {
    enabled = false
  }
  secondary_config = {
    primary_cluster_name = gcp_alloydb_cluster.primary.name
  }
  deletion_policy     = "FORCE"
  deletion_protection = false
}
resource "gcp_alloydb_instance" "secondary" {
  depends_on    = [gcp_servicenetworking_connection.vpc_connection]
  cluster       = gcp_alloydb_cluster.secondary.name
  instance_id   = "alloydb-secondary-instance"
  instance_type = gcp_alloydb_cluster.secondary.cluster_type
  machine_config = {
    cpu_count = 2
  }
}
resource "gcp_compute_network" "default" {
  name = "alloydb-secondary-network"
}
resource "gcp_compute_globaladdress" "private_ip_alloc" {
  name          = "alloydb-secondary-instance"
  address_type  = "INTERNAL"
  purpose       = "VPC_PEERING"
  prefix_length = 16
  network       = gcp_compute_network.default.id
}
resource "gcp_servicenetworking_connection" "vpc_connection" {
  network                 = gcp_compute_network.default.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [gcp_compute_globaladdress.private_ip_alloc.name]
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.compute.Network;
import com.pulumi.gcp.compute.NetworkArgs;
import com.pulumi.gcp.alloydb.Cluster;
import com.pulumi.gcp.alloydb.ClusterArgs;
import com.pulumi.gcp.alloydb.inputs.ClusterNetworkConfigArgs;
import com.pulumi.gcp.compute.GlobalAddress;
import com.pulumi.gcp.compute.GlobalAddressArgs;
import com.pulumi.gcp.servicenetworking.Connection;
import com.pulumi.gcp.servicenetworking.ConnectionArgs;
import com.pulumi.gcp.alloydb.Instance;
import com.pulumi.gcp.alloydb.InstanceArgs;
import com.pulumi.gcp.alloydb.inputs.InstanceMachineConfigArgs;
import com.pulumi.gcp.alloydb.inputs.ClusterContinuousBackupConfigArgs;
import com.pulumi.gcp.alloydb.inputs.ClusterSecondaryConfigArgs;
import com.pulumi.gcp.organizations.OrganizationsFunctions;
import com.pulumi.gcp.organizations.inputs.GetProjectArgs;
import com.pulumi.resources.CustomResourceOptions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var default_ = new Network("default", NetworkArgs.builder()
            .name("alloydb-secondary-network")
            .build());

        var primary = new Cluster("primary", ClusterArgs.builder()
            .clusterId("alloydb-primary-cluster")
            .location("us-central1")
            .networkConfig(ClusterNetworkConfigArgs.builder()
                .network(default_.id())
                .build())
            .deletionProtection(false)
            .build());

        var privateIpAlloc = new GlobalAddress("privateIpAlloc", GlobalAddressArgs.builder()
            .name("alloydb-secondary-instance")
            .addressType("INTERNAL")
            .purpose("VPC_PEERING")
            .prefixLength(16)
            .network(default_.id())
            .build());

        var vpcConnection = new Connection("vpcConnection", ConnectionArgs.builder()
            .network(default_.id())
            .service("servicenetworking.googleapis.com")
            .reservedPeeringRanges(privateIpAlloc.name())
            .build());

        var primaryInstance = new Instance("primaryInstance", InstanceArgs.builder()
            .cluster(primary.name())
            .instanceId("alloydb-primary-instance")
            .instanceType("PRIMARY")
            .machineConfig(InstanceMachineConfigArgs.builder()
                .cpuCount(2)
                .build())
            .build(), CustomResourceOptions.builder()
                .dependsOn(vpcConnection)
                .build());

        var secondary = new Cluster("secondary", ClusterArgs.builder()
            .clusterId("alloydb-secondary-cluster")
            .location("us-east1")
            .networkConfig(ClusterNetworkConfigArgs.builder()
                .network(defaultGoogleComputeNetwork.get("id"))
                .build())
            .clusterType("SECONDARY")
            .continuousBackupConfig(ClusterContinuousBackupConfigArgs.builder()
                .enabled(false)
                .build())
            .secondaryConfig(ClusterSecondaryConfigArgs.builder()
                .primaryClusterName(primary.name())
                .build())
            .deletionPolicy("FORCE")
            .deletionProtection(false)
            .build(), CustomResourceOptions.builder()
                .dependsOn(primaryInstance)
                .build());

        var secondaryInstance = new Instance("secondaryInstance", InstanceArgs.builder()
            .cluster(secondary.name())
            .instanceId("alloydb-secondary-instance")
            .instanceType(secondary.clusterType())
            .machineConfig(InstanceMachineConfigArgs.builder()
                .cpuCount(2)
                .build())
            .build(), CustomResourceOptions.builder()
                .dependsOn(vpcConnection)
                .build());

        final var project = OrganizationsFunctions.getProject(GetProjectArgs.builder()
            .build());

    }
}
resources:
  primary:
    type: gcp:alloydb:Cluster
    properties:
      clusterId: alloydb-primary-cluster
      location: us-central1
      networkConfig:
        network: ${default.id}
      deletionProtection: false
  primaryInstance:
    type: gcp:alloydb:Instance
    name: primary
    properties:
      cluster: ${primary.name}
      instanceId: alloydb-primary-instance
      instanceType: PRIMARY
      machineConfig:
        cpuCount: 2
    options:
      dependsOn:
        - ${vpcConnection}
  secondary:
    type: gcp:alloydb:Cluster
    properties:
      clusterId: alloydb-secondary-cluster
      location: us-east1
      networkConfig:
        network: ${defaultGoogleComputeNetwork.id}
      clusterType: SECONDARY
      continuousBackupConfig:
        enabled: false
      secondaryConfig:
        primaryClusterName: ${primary.name}
      deletionPolicy: FORCE
      deletionProtection: false
    options:
      dependsOn:
        - ${primaryInstance}
  secondaryInstance:
    type: gcp:alloydb:Instance
    name: secondary
    properties:
      cluster: ${secondary.name}
      instanceId: alloydb-secondary-instance
      instanceType: ${secondary.clusterType}
      machineConfig:
        cpuCount: 2
    options:
      dependsOn:
        - ${vpcConnection}
  default:
    type: gcp:compute:Network
    properties:
      name: alloydb-secondary-network
  privateIpAlloc:
    type: gcp:compute:GlobalAddress
    name: private_ip_alloc
    properties:
      name: alloydb-secondary-instance
      addressType: INTERNAL
      purpose: VPC_PEERING
      prefixLength: 16
      network: ${default.id}
  vpcConnection:
    type: gcp:servicenetworking:Connection
    name: vpc_connection
    properties:
      network: ${default.id}
      service: servicenetworking.googleapis.com
      reservedPeeringRanges:
        - ${privateIpAlloc.name}
variables:
  project:
    fn::invoke:
      function: gcp:organizations:getProject
      arguments: {}

Import

Instance can be imported using any of these accepted formats:

  • projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/instances/{{instance_id}}
  • {{project}}/{{location}}/{{cluster}}/{{instance_id}}
  • {{location}}/{{cluster}}/{{instance_id}}

When using the pulumi import command, Instance can be imported using one of the formats above. For example:

$ pulumi import gcp:alloydb/instance:Instance default projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/instances/{{instance_id}}
$ pulumi import gcp:alloydb/instance:Instance default {{project}}/{{location}}/{{cluster}}/{{instance_id}}
$ pulumi import gcp:alloydb/instance:Instance default {{location}}/{{cluster}}/{{instance_id}}

Constructors

Instance(String name, {InstanceArgs? args, CustomResourceOptions? options})
Creates a new Instance. name The Pulumi resource name. args Arguments used to configure this Instance. The set of arguments for Instance. options Resource options controlling this resource's behavior.
Instance.reference(String urn)
Creates a typed reference to an existing Instance resource.

Properties

activationPolicy ↔ Output<String>
'Specifies whether an instance needs to spin up. Once the instance is active, the activation policy can be updated to the NEVER to stop the instance. Likewise, the activation policy can be updated to ALWAYS to start the instance. There are restrictions around when an instance can/cannot be activated (for example, a read pool instance should be stopped before stopping primary etc.). Please refer to the API documentation for more details. Possible values are: ACTIVATION_POLICY_UNSPECIFIED, ALWAYS, NEVER.' Possible values are: ACTIVATION_POLICY_UNSPECIFIED, ALWAYS, NEVER.
latefinal
annotations ↔ Output<Map<String, String>?>
Annotations to allow client tools to store small amount of arbitrary data. This is distinct from labels. Note: This field is non-authoritative, and will only manage the annotations present in your configuration. Please refer to the field effectiveAnnotations for all of the annotations present on the resource.
latefinal
availabilityType ↔ Output<String>
'Availability type of an Instance. Defaults to REGIONAL for both primary and read instances. Note that primary and read instances can have different availability types. Primary instances can be either ZONAL or REGIONAL. Read Pool instances can also be either ZONAL or REGIONAL. Read pools of size 1 can only have zonal availability. Read pools with a node count of 2 or more can have regional availability (nodes are present in 2 or more zones in a region). Possible values are: AVAILABILITY_TYPE_UNSPECIFIED, ZONAL, REGIONAL.' Possible values are: AVAILABILITY_TYPE_UNSPECIFIED, ZONAL, REGIONAL.
latefinal
childResources → Set<Resource>
finalinherited
clientConnectionConfig ↔ Output<InstanceClientConnectionConfig>
Client connection specific configurations. Structure is documented below.
latefinal
cluster ↔ Output<String>
Identifies the alloydb cluster. Must be in the format 'projects/{project}/locations/{location}/clusters/{cluster_id}'
latefinal
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
connectionPoolConfig ↔ Output<InstanceConnectionPoolConfig?>
Configuration for Managed Connection Pool. Structure is documented below.
latefinal
createTime ↔ Output<String>
Time the Instance was created in UTC.
latefinal
databaseFlags ↔ Output<Map<String, String>>
Database flags. Set at instance level. * They are copied from primary instance on read instance creation. * Read instances can set new or override existing flags that are relevant for reads, e.g. for enabling columnar cache on a read instance. Flags set on read instance may or may not be present on primary.
latefinal
deletionPolicy ↔ Output<String>
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE. When a 'terraform destroy' or 'pulumi up' would delete the resource, the command will fail if this field is set to "PREVENT" in Terraform state. When set to "ABANDON", the command will remove the resource from Terraform management without updating or deleting the resource in the API. When set to "DELETE", deleting the resource is allowed.
latefinal
displayName ↔ Output<String?>
User-settable and human-readable display name for the Instance.
latefinal
effectiveAnnotations ↔ Output<Map<String, String>>
All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.
latefinal
effectiveLabels ↔ Output<Map<String, String>>
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Pulumi, other clients and services.
latefinal
gceZone ↔ Output<String?>
The Compute Engine zone that the instance should serve from, per https://cloud.google.com/compute/docs/regions-zones This can ONLY be specified for ZONAL instances. If present for a REGIONAL instance, an error will be thrown. If this is absent for a ZONAL instance, instance is created in a random zone with available capacity.
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
instanceId ↔ Output<String>
The ID of the alloydb instance.
latefinal
instanceType ↔ Output<String>
The type of the instance. If the instance type is READ_POOL, provide the associated PRIMARY/SECONDARY instance in the dependsOn meta-data attribute. If the instance type is SECONDARY, point to the clusterType of the associated secondary cluster instead of mentioning SECONDARY. Example: {instance_type = google_alloydb_cluster.<secondary_cluster_name>.cluster_type} instead of {instance_type = SECONDARY} If the instance type is SECONDARY, the terraform delete instance operation does not delete the secondary instance but abandons it instead. Use deletionPolicy = "FORCE" in the associated secondary cluster and delete the cluster forcefully to delete the secondary cluster as well its associated secondary instance. Users can undo the delete secondary instance action by importing the deleted secondary instance by calling terraform import. Possible values are: PRIMARY, READ_POOL, SECONDARY.
latefinal
ipAddress ↔ Output<String>
The IP address for the Instance. This is the connection endpoint for an end-user application.
latefinal
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
labels ↔ Output<Map<String, String>?>
User-defined labels for the alloydb instance. Note: This field is non-authoritative, and will only manage the labels present in your configuration. Please refer to the field effectiveLabels for all of the labels present on the resource.
latefinal
machineConfig ↔ Output<InstanceMachineConfig>
Configurations for the machines that host the underlying database engine. Structure is documented below.
latefinal
name ↔ Output<String>
The name of the instance resource.
latefinal
networkConfig ↔ Output<InstanceNetworkConfig>
Instance level network configuration. Structure is documented below.
latefinal
observabilityConfig ↔ Output<InstanceObservabilityConfig>
(Optional, Beta) Configuration for enhanced query insights. Structure is documented below.
latefinal
outboundPublicIpAddresses ↔ Output<List<String>>
The outbound public IP addresses for the instance. This is available ONLY when networkConfig.enableOutboundPublicIp is set to true. These IP addresses are used for outbound connections.
latefinal
pscInstanceConfig ↔ Output<InstancePscInstanceConfig>
Configuration for Private Service Connect (PSC) for the instance. Structure is documented below.
latefinal
publicIpAddress ↔ Output<String>
The public IP addresses for the Instance. This is available ONLY when networkConfig.enablePublicIp is set to true. This is the connection endpoint for an end-user application.
latefinal
pulumiLabels ↔ Output<Map<String, String>>
The combination of labels configured directly on the resource and default labels configured on the provider.
latefinal
queryInsightsConfig ↔ Output<InstanceQueryInsightsConfig>
Configuration for query insights. Structure is documented below.
latefinal
readPoolConfig ↔ Output<InstanceReadPoolConfig?>
Read pool specific config. If the instance type is READ_POOL, this configuration must be provided. Structure is documented below.
latefinal
reconciling ↔ Output<bool>
Set to true if the current state of Instance does not match the user's intended state, and the service is actively updating the resource to reconcile them. This can happen due to user-triggered updates or system actions like failover or maintenance.
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
state ↔ Output<String>
The current state of the alloydb instance.
latefinal
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
uid ↔ Output<String>
The system-generated UID of the resource.
latefinal
updateTime ↔ Output<String>
Time the Instance was updated in UTC.
latefinal
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {InstanceState? state, CustomResourceOptions? options}) → Instance
Gets an existing Instance resource's state with the given name and id.