google_alloydb_user

A database user in an AlloyDB cluster.

To get more information about User, see:

Example Usage - Alloydb User Builtin

resource "google_alloydb_instance" "default" {
  cluster       = google_alloydb_cluster.default.name
  instance_id   = "alloydb-instance"
  instance_type = "PRIMARY"

  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 = "cluster_secret"
  }
}

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_user" "user1" {
  cluster = google_alloydb_cluster.default.name
  user_id = "user1"
  user_type = "ALLOYDB_BUILT_IN"

  password = "user_secret"
  database_roles = ["alloydbsuperuser"]
  depends_on = [google_alloydb_instance.default]
}

Example Usage - Alloydb User Iam

resource "google_alloydb_instance" "default" {
  cluster       = google_alloydb_cluster.default.name
  instance_id   = "alloydb-instance"
  instance_type = "PRIMARY"

  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 = "cluster_secret"
  }
}

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_user" "user2" {
  cluster = google_alloydb_cluster.default.name
  user_id = "user2@foo.com"
  user_type = "ALLOYDB_IAM_USER"

  database_roles = ["alloydbiamuser"]
  depends_on = [google_alloydb_instance.default]
}

Argument Reference

The following arguments are supported:


Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

Timeouts

This resource provides the following Timeouts configuration options:

Import

User can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import User using one of the formats above. For example:

import {
  id = "projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/users/{{user_id}}"
  to = google_alloydb_user.default
}

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

$ terraform import google_alloydb_user.default projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/users/{{user_id}}
$ terraform import google_alloydb_user.default {{project}}/{{location}}/{{cluster}}/{{user_id}}
$ terraform import google_alloydb_user.default {{location}}/{{cluster}}/{{user_id}}