alicloud_kvstore_instance

Provides an ApsaraDB Redis / Memcache instance resource. A DB instance is an isolated database environment in the cloud. It support be associated with IP whitelists and backup configuration which are separate resource providers. For information about Alicloud KVStore DBInstance more and how to use it, see What is Resource Alicloud KVStore DBInstance.

Example Usage

Basic Usage

variable "name" {
  default = "tf-example"
}

data "alicloud_kvstore_zones" "default" {
}

data "alicloud_resource_manager_resource_groups" "default" {
  status = "OK"
}

resource "alicloud_vpc" "default" {
  vpc_name   = var.name
  cidr_block = "10.4.0.0/16"
}

resource "alicloud_vswitch" "default" {
  vswitch_name = var.name
  cidr_block   = "10.4.0.0/24"
  vpc_id       = alicloud_vpc.default.id
  zone_id      = data.alicloud_kvstore_zones.default.zones.0.id
}

resource "alicloud_kvstore_instance" "default" {
  db_instance_name  = var.name
  vswitch_id        = alicloud_vswitch.default.id
  resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.0
  zone_id           = data.alicloud_kvstore_zones.default.zones.0.id
  instance_class    = "redis.master.large.default"
  instance_type     = "Redis"
  engine_version    = "5.0"
  security_ips      = ["10.23.12.24"]
  config = {
    appendonly             = "yes"
    lazyfree-lazy-eviction = "yes"
  }
  tags = {
    Created = "TF",
    For     = "example",
  }
}

Launching a PrePaid instance

variable "name" {
  default = "tf-example-prepaid"
}
data "alicloud_kvstore_zones" "default" {
  instance_charge_type = "PrePaid"
}
data "alicloud_resource_manager_resource_groups" "default" {
  status = "OK"
}

// PrePaid instance can not deleted and there suggests using an existing vpc and vswitch, like default vpc.
data "alicloud_vpcs" "default" {
  is_default = true
}
data "alicloud_vswitches" "default" {
  zone_id = data.alicloud_kvstore_zones.default.zones.0.id
  vpc_id  = data.alicloud_vpcs.default.ids.0
}

resource "alicloud_kvstore_instance" "default" {
  db_instance_name  = var.name
  vswitch_id        = data.alicloud_vswitches.default.ids.0
  resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.0
  zone_id           = data.alicloud_kvstore_zones.default.zones.0.id
  secondary_zone_id = data.alicloud_kvstore_zones.default.zones.1.id
  instance_class    = "redis.master.large.default"
  instance_type     = "Redis"
  engine_version    = "5.0"
  payment_type      = "PrePaid"
  period            = "12"
  security_ips      = ["10.23.12.24"]
  config = {
    appendonly             = "no"
    lazyfree-lazy-eviction = "no"
    EvictionPolicy         = "volatile-lru"
  }
  tags = {
    Created = "TF",
    For     = "example",
  }
}

Setting Private Connection String

variable "name" {
  default = "tf-example-with-connection"
}

data "alicloud_kvstore_zones" "default" {
  product_type = "OnECS"
}

data "alicloud_resource_manager_resource_groups" "default" {
  status = "OK"
}

resource "alicloud_vpc" "default" {
  vpc_name   = var.name
  cidr_block = "10.4.0.0/16"
}

resource "alicloud_vswitch" "default" {
  vswitch_name = var.name
  cidr_block   = "10.4.0.0/24"
  vpc_id       = alicloud_vpc.default.id
  zone_id      = data.alicloud_kvstore_zones.default.zones.0.id
}

resource "alicloud_kvstore_instance" "default" {
  db_instance_name          = var.name
  vswitch_id                = alicloud_vswitch.default.id
  resource_group_id         = data.alicloud_resource_manager_resource_groups.default.ids.0
  zone_id                   = data.alicloud_kvstore_zones.default.zones.0.id
  secondary_zone_id         = data.alicloud_kvstore_zones.default.zones.1.id
  instance_class            = "redis.shard.small.ce"
  instance_type             = "Redis"
  engine_version            = "7.0"
  maintain_start_time       = "04:00Z"
  maintain_end_time         = "06:00Z"
  backup_period             = ["Wednesday"]
  backup_time               = "11:00Z-12:00Z"
  private_connection_prefix = "exampleconnectionprefix"
  private_connection_port   = 4011
  security_ips              = ["10.23.12.24"]
  config = {
    appendonly             = "yes"
    lazyfree-lazy-eviction = "yes"
    EvictionPolicy         = "volatile-lru"
  }
  tags = {
    Created = "TF",
    For     = "example",
  }
}

Deleting alicloud_kvstore_instance or removing it from your configuration

The alicloud_kvstore_instance resource allows you to manage payment_type = "Prepaid" db instance, but Terraform cannot destroy it. From version 1.201.0, deleting the subscription resource or removing it from your configuration will remove it from your state file and management, but will not destroy the DB Instance. You can resume managing the subscription db instance via the AlibabaCloud Console.

Argument Reference

The following arguments are supported:

parameters

The parameters supports the following:

Attributes Reference

The following attributes are exported:

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

Import

KVStore instance can be imported using the id, e.g.

$ terraform import alicloud_kvstore_instance.example r-abc12345678