» google_redis_instance

A Google Cloud Redis instance.

To get more information about Instance, see:

» Example Usage - Redis Instance Basic

resource "google_redis_instance" "cache" {
  name           = "memory-cache"
  memory_size_gb = 1

» Example Usage - Redis Instance Full

resource "google_redis_instance" "cache" {
  name           = "ha-memory-cache"
  tier           = "STANDARD_HA"
  memory_size_gb = 1

  location_id             = "us-central1-a"
  alternative_location_id = "us-central1-f"

  authorized_network = data.google_compute_network.redis-network.id

  redis_version     = "REDIS_4_0"
  display_name      = "Terraform Test Instance"
  reserved_ip_range = ""

  labels = {
    my_key    = "my_val"
    other_key = "other_val"

// This example assumes this network already exists.
// The API creates a tenant network per network authorized for a
// Redis instance and that network is not deleted when the user-created
// network (authorized_network) is deleted, so this prevents issues
// with tenant network quota.
// If this network hasn't been created and you are using this example in your
// config, add an additional network resource or change
// this from "data"to "resource"
data "google_compute_network" "redis-network" {
  name = "redis-test-network"

» Example Usage - Redis Instance Private Service

resource "google_compute_network" "network" {
  name = "tf-test%{random_suffix}"

resource "google_compute_global_address" "service_range" {
  name          = "tf-test%{random_suffix}"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  prefix_length = 16
  network       = google_compute_network.network.id

resource "google_service_networking_connection" "private_service_connection" {
  network                 = google_compute_network.network.id
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.service_range.name]

resource "google_redis_instance" "cache" {
  name           = "tf-test%{random_suffix}"
  tier           = "STANDARD_HA"
  memory_size_gb = 1

  location_id             = "us-central1-a"
  alternative_location_id = "us-central1-f"

  authorized_network = google_compute_network.network.id
  connect_mode       = "PRIVATE_SERVICE_ACCESS"

  redis_version     = "REDIS_4_0"
  display_name      = "Terraform Test Instance"

  depends_on = [google_service_networking_connection.private_service_connection]


» Argument Reference

The following arguments are supported:

  • name - (Required) The ID of the instance or a fully qualified identifier for the instance.

  • memory_size_gb - (Required) Redis memory size in GiB.

  • alternative_location_id - (Optional) Only applicable to STANDARD_HA tier which protects the instance against zonal failures by provisioning it across two zones. If provided, it must be a different zone from the one provided in [locationId].

  • authorized_network - (Optional) The full name of the Google Compute Engine network to which the instance is connected. If left unspecified, the default network will be used.

  • connect_mode - (Optional) The connection mode of the Redis instance. Default value is DIRECT_PEERING. Possible values are DIRECT_PEERING and PRIVATE_SERVICE_ACCESS.

  • display_name - (Optional) An arbitrary and optional user-provided name for the instance.

  • labels - (Optional) Resource labels to represent user provided metadata.

  • redis_configs - (Optional) Redis configuration parameters, according to http://redis.io/topics/config. Please check Memorystore documentation for the list of supported parameters: https://cloud.google.com/memorystore/docs/redis/reference/rest/v1/projects.locations.instances#Instance.FIELDS.redis_configs

  • location_id - (Optional) The zone where the instance will be provisioned. If not provided, the service will choose a zone for the instance. For STANDARD_HA tier, instances will be created across two zones for protection against zonal failures. If [alternativeLocationId] is also provided, it must be different from [locationId].

  • redis_version - (Optional) The version of Redis software. If not provided, latest supported version will be used. Currently, the supported values are:

    • REDIS_5_0 for Redis 5.0 compatibility
    • REDIS_4_0 for Redis 4.0 compatibility
    • REDIS_3_2 for Redis 3.2 compatibility
  • reserved_ip_range - (Optional) The CIDR range of internal addresses that are reserved for this instance. If not provided, the service will choose an unused /29 block, for example, or Ranges must be unique and non-overlapping with existing subnets in an authorized network.

  • tier - (Optional) The service tier of the instance. Must be one of these values:

    • BASIC: standalone instance
    • STANDARD_HA: highly available primary/replica instances Default value is BASIC. Possible values are BASIC and STANDARD_HA.
  • region - (Optional) The name of the Redis region of the instance.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

» Attributes Reference

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

  • id - an identifier for the resource with format projects/{{project}}/locations/{{region}}/instances/{{name}}

  • create_time - The time the instance was created in RFC3339 UTC "Zulu" format, accurate to nanoseconds.

  • current_location_id - The current zone where the Redis endpoint is placed. For Basic Tier instances, this will always be the same as the [locationId] provided by the user at creation time. For Standard Tier instances, this can be either [locationId] or [alternativeLocationId] and can change after a failover event.

  • host - Hostname or IP address of the exposed Redis endpoint used by clients to connect to the service.

  • port - The port number of the exposed Redis endpoint.

  • persistence_iam_identity - Output only. Cloud IAM identity used by import / export operations to transfer data to/from Cloud Storage. Format is "serviceAccount:". The value may change over time for a given instance so should be checked before each import/export operation.

» Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 10 minutes.
  • update - Default is 10 minutes.
  • delete - Default is 10 minutes.

» Import

Instance can be imported using any of these accepted formats:

$ terraform import google_redis_instance.default projects/{{project}}/locations/{{region}}/instances/{{name}}
$ terraform import google_redis_instance.default {{project}}/{{region}}/{{name}}
$ terraform import google_redis_instance.default {{region}}/{{name}}
$ terraform import google_redis_instance.default {{name}}

» User Project Overrides

This resource supports User Project Overrides.