A managed alloydb cluster instance.
To get more information about Instance, see:
resource "google_alloydb_instance" "default" {
cluster = google_alloydb_cluster.default.name
instance_id = "alloydb-instance"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "default" {
cluster_id = "alloydb-cluster"
location = "us-central1"
network = google_compute_network.default.id
initial_user {
password = "alloydb-cluster"
}
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "alloydb-network"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "alloydb-cluster"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
resource "google_alloydb_cluster" "primary" {
cluster_id = "alloydb-primary-cluster"
location = "us-central1"
network = google_compute_network.default.id
}
resource "google_alloydb_instance" "primary" {
cluster = google_alloydb_cluster.primary.name
instance_id = "alloydb-primary-instance"
instance_type = "PRIMARY"
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
resource "google_alloydb_cluster" "secondary" {
cluster_id = "alloydb-secondary-cluster"
location = "us-east1"
network = google_compute_network.default.id
cluster_type = "SECONDARY"
continuous_backup_config {
enabled = false
}
secondary_config {
primary_cluster_name = google_alloydb_cluster.primary.name
}
deletion_policy = "FORCE"
# Need lifecycle.ignore_changes because instance_type is an immutable field.
# And when promoting cluster from SECONDARY to PRIMARY, the instance_type of the associated secondary instance also changes and becomes PRIMARY.
# And we do not want terraform to destroy and create the instance because the field is immutable
lifecycle {
ignore_changes = [instance_type]
}
depends_on = [google_alloydb_instance.primary]
}
resource "google_alloydb_instance" "secondary" {
cluster = google_alloydb_cluster.secondary.name
instance_id = "alloydb-secondary-instance"
instance_type = google_alloydb_cluster.secondary.cluster_type
machine_config {
cpu_count = 2
}
depends_on = [google_service_networking_connection.vpc_connection]
}
data "google_project" "project" {}
resource "google_compute_network" "default" {
name = "alloydb-secondary-network"
}
resource "google_compute_global_address" "private_ip_alloc" {
name = "alloydb-secondary-instance"
address_type = "INTERNAL"
purpose = "VPC_PEERING"
prefix_length = 16
network = google_compute_network.default.id
}
resource "google_service_networking_connection" "vpc_connection" {
network = google_compute_network.default.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
The following arguments are supported:
instance_type
-
(Required)
The type of the instance.
If the instance type is READ_POOL, provide the associated PRIMARY/SECONDARY instance in the depends_on
meta-data attribute.
If the instance type is SECONDARY, point to the cluster_type of the associated secondary cluster instead of mentioning SECONDARY.
Example: {instance_type = google_alloydb_cluster.PRIMARY
, READ_POOL
, SECONDARY
.
cluster
-
(Required)
Identifies the alloydb cluster. Must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'
instance_id
-
(Required)
The ID of the alloydb instance.
labels
-
(Optional)
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 effective_labels
for all of the labels present on the resource.
annotations
-
(Optional)
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 effective_annotations
for all of the annotations present on the resource.
display_name
-
(Optional)
User-settable and human-readable display name for the Instance.
gce_zone
-
(Optional)
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.
database_flags
-
(Optional)
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.
availability_type
-
(Optional)
'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.
Only READ_POOL instance supports ZONAL type. Users can't specify the zone for READ_POOL instance.
Zone is automatically chosen from the list of zones in the region specified.
Read pool of size 1 can only have zonal availability. Read pools with 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
.
query_insights_config
-
(Optional)
Configuration for query insights.
Structure is documented below.
read_pool_config
-
(Optional)
Read pool specific config. If the instance type is READ_POOL, this configuration must be provided.
Structure is documented below.
machine_config
-
(Optional)
Configurations for the machines that host the underlying database engine.
Structure is documented below.
client_connection_config
-
(Optional)
Client connection specific configurations.
Structure is documented below.
network_config
-
(Optional)
Instance level network configuration.
Structure is documented below.
The query_insights_config
block supports:
query_string_length
-
(Optional)
Query string length. The default value is 1024. Any integer between 256 and 4500 is considered valid.
record_application_tags
-
(Optional)
Record application tags for an instance. This flag is turned "on" by default.
record_client_address
-
(Optional)
Record client address for an instance. Client address is PII information. This flag is turned "on" by default.
query_plans_per_minute
-
(Optional)
Number of query execution plans captured by Insights per minute for all queries combined. The default value is 5. Any integer between 0 and 20 is considered valid.
The read_pool_config
block supports:
node_count
-
(Optional)
Read capacity, i.e. number of nodes in a read pool instance.The machine_config
block supports:
cpu_count
-
(Optional)
The number of CPU's in the VM instance.The client_connection_config
block supports:
require_connectors
-
(Optional)
Configuration to enforce connectors only (ex: AuthProxy) connections to the database.
ssl_config
-
(Optional)
SSL config option for this instance.
Structure is documented below.
The ssl_config
block supports:
ssl_mode
-
(Optional)
SSL mode. Specifies client-server SSL/TLS connection behavior.
Possible values are: ENCRYPTED_ONLY
, ALLOW_UNENCRYPTED_AND_ENCRYPTED
.The network_config
block supports:
authorized_external_networks
-
(Optional)
A list of external networks authorized to access this instance. This
field is only allowed to be set when enable_public_ip
is set to
true.
Structure is documented below.
enable_public_ip
-
(Optional)
Enabling public ip for the instance. If a user wishes to disable this,
please also clear the list of the authorized external networks set on
the same instance.
The authorized_external_networks
block supports:
cidr_range
-
(Optional)
CIDR range for one authorized network of the instance.In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format {{cluster}}/instances/{{instance_id}}
name
-
The name of the instance resource.
create_time
-
Time the Instance was created in UTC.
update_time
-
Time the Instance was updated in UTC.
uid
-
The system-generated UID of the resource.
state
-
The current state of the alloydb instance.
reconciling
-
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.
ip_address
-
The IP address for the Instance. This is the connection endpoint for an end-user application.
public_ip_address
-
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.
terraform_labels
-
The combination of labels configured directly on the resource
and default labels configured on the provider.
effective_labels
-
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
effective_annotations
-
All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.
This resource provides the following Timeouts configuration options:
create
- Default is 120 minutes.update
- Default is 120 minutes.delete
- Default is 120 minutes.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}}
In Terraform v1.5.0 and later, use an import
block to import Instance using one of the formats above. For example:
import {
id = "projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/instances/{{instance_id}}"
to = google_alloydb_instance.default
}
When using the terraform import
command, Instance can be imported using one of the formats above. For example:
$ terraform import google_alloydb_instance.default projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/instances/{{instance_id}}
$ terraform import google_alloydb_instance.default {{project}}/{{location}}/{{cluster}}/{{instance_id}}
$ terraform import google_alloydb_instance.default {{location}}/{{cluster}}/{{instance_id}}