google_redis_instance

A Google Cloud Redis instance.

To get more information about Instance, see:

Open in Cloud Shell

Example Usage - Redis Instance Basic

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

  lifecycle {
    prevent_destroy = true
  }
}
Open in Cloud Shell

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 = "192.168.0.0/29"

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

  maintenance_policy {
    weekly_maintenance_window {
      day = "TUESDAY"
      start_time {
        hours = 0
        minutes = 30
        seconds = 0
        nanos = 0
      }
    }
  }

  lifecycle {
    prevent_destroy = true
  }
}

// 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"
}
Open in Cloud Shell

Example Usage - Redis Instance Full With Persistence Config

resource "google_redis_instance" "cache-persis" {
  name           = "ha-memory-cache-persis"
  tier           = "STANDARD_HA"
  memory_size_gb = 1
  location_id             = "us-central1-a"
  alternative_location_id = "us-central1-f"

  persistence_config {
    persistence_mode = "RDB"
    rdb_snapshot_period = "TWELVE_HOURS"
  }

  lifecycle {
    prevent_destroy = true
  }
}
## Example Usage - Redis Instance Private Service
// 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"
resource "google_compute_network" "redis-network" {
  name = "redis-test-network"
}

resource "google_compute_global_address" "service_range" {
  name          = "address"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  prefix_length = 16
  network       = google_compute_network.redis-network.id
}

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

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

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

  authorized_network = google_compute_network.redis-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]

  lifecycle {
    prevent_destroy = true
  }
}
Open in Cloud Shell

Example Usage - Redis Instance Mrr

resource "google_redis_instance" "cache" {
  name           = "mrr-memory-cache"
  tier           = "STANDARD_HA"
  memory_size_gb = 5

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

  authorized_network = data.google_compute_network.redis-network.id

  redis_version     = "REDIS_6_X"
  display_name      = "Terraform Test Instance"
  reserved_ip_range = "192.168.0.0/28"
  replica_count     = 5
  read_replicas_mode = "READ_REPLICAS_ENABLED"

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

  lifecycle {
    prevent_destroy = true
  }
}

// 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 Cmek

resource "google_redis_instance" "cache" {
  name           = "cmek-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_6_X"
  display_name      = "Terraform Test Instance"
  reserved_ip_range = "192.168.0.0/29"

  labels = {
    my_key    = "my_val"
    other_key = "other_val"
  }
  customer_managed_key = google_kms_crypto_key.redis_key.id

  lifecycle {
    prevent_destroy = true
  }
}

resource "google_kms_key_ring" "redis_keyring" {
  name     = "redis-keyring"
  location = "us-central1"
}

resource "google_kms_crypto_key" "redis_key" {
  name            = "redis-key"
  key_ring        = google_kms_key_ring.redis_keyring.id
}

// 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"
}

Argument Reference

The following arguments are supported:


The persistence_config block supports:

The maintenance_policy block supports:

The weekly_maintenance_window block supports:

The start_time block supports:

Attributes Reference

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

The maintenance_schedule block contains:

The server_ca_certs block contains:

The nodes block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

Instance can be imported using any of these accepted formats:

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/{{region}}/instances/{{name}}"
  to = google_redis_instance.default
}

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

$ 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.