blob: 8a25afffe3db6ef43a493dfb718bdf3ae2bbd419 [file] [log] [blame] [edit]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "AlloyDB"
description: |-
A database user in an AlloyDB cluster.
---
# google_alloydb_user
A database user in an AlloyDB cluster.
To get more information about User, see:
* [API documentation](https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.clusters.users/create)
* How-to Guides
* [AlloyDB](https://cloud.google.com/alloydb/docs/)
## Example Usage - Alloydb User Builtin
```hcl
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_config {
network = data.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
```hcl
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_config {
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:
* `cluster` -
(Required)
Identifies the alloydb cluster. Must be in the format
'projects/{project}/locations/{location}/clusters/{cluster_id}'
* `user_id` -
(Required)
The database role name of the user.
* `user_type` -
(Required)
The type of this user.
Possible values are: `ALLOYDB_BUILT_IN`, `ALLOYDB_IAM_USER`.
- - -
* `password` -
(Optional)
Password for this database user.
* `database_roles` -
(Optional)
List of database roles this database user has.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are exported:
* `id` - an identifier for the resource with format `{{cluster}}/users/{{user_id}}`
* `name` -
Name of the resource in the form of projects/{project}/locations/{location}/clusters/{cluster}/users/{user}.
## Timeouts
This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
- `create` - Default is 20 minutes.
- `update` - Default is 20 minutes.
- `delete` - Default is 20 minutes.
## Import
User can be imported using any of these accepted formats:
* `projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/users/{{user_id}}`
* `{{project}}/{{location}}/{{cluster}}/{{user_id}}`
* `{{location}}/{{cluster}}/{{user_id}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import User using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/users/{{user_id}}"
to = google_alloydb_user.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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}}
```