alicloud_polardb_cluster

Provides an PolarDB cluster resource. An PolarDB cluster is an isolated database environment in the cloud. An PolarDB cluster can contain multiple user-created databases.

Example Usage

Create a PolarDB MySQL cluster

data "alicloud_polardb_node_classes" "default" {
  db_type    = "MySQL"
  db_version = "8.0"
  category   = "Normal"
  pay_type   = "PostPaid"
}

resource "alicloud_vpc" "default" {
  vpc_name   = "terraform-example"
  cidr_block = "172.16.0.0/16"
}

resource "alicloud_vswitch" "default" {
  vpc_id       = alicloud_vpc.default.id
  cidr_block   = "172.16.0.0/24"
  zone_id      = data.alicloud_polardb_node_classes.default.classes[0].zone_id
  vswitch_name = "terraform-example"
}

resource "alicloud_polardb_cluster" "default" {
  db_type       = "MySQL"
  db_version    = "8.0"
  db_node_class = data.alicloud_polardb_node_classes.default.classes.0.supported_engines.0.available_resources.0.db_node_class
  pay_type      = "PostPaid"
  vswitch_id    = alicloud_vswitch.default.id
  description   = "terraform-example"

  db_cluster_ip_array {
    db_cluster_ip_array_name = "default"
    security_ips             = ["1.2.3.4", "1.2.3.5"]
  }
  db_cluster_ip_array {
    db_cluster_ip_array_name = "default2"
    security_ips             = ["1.2.3.6"]
  }
}

When enabling TDE encryption, it is necessary to ensure that there is a AliyunRDSInstanceEncryptionDefaultRole role under the account. If not, the following code can be used to create it

data "alicloud_account" "current" {
}


// resource "alicloud_ram_role" "default" {
//  name        = "AliyunRDSInstanceEncryptionDefaultRole"
//  document    = <<DEFINITION
//    {
//        "Statement": [
//            {
//               "Action": "sts:AssumeRole",
//                "Effect": "Allow",
//                "Principal": {
//                    "Service": [
//                        "rds.aliyuncs.com"
//                    ]
//                }
//            }
//        ],
//        "Version": "1"
//    }
//  DEFINITION
//  description = "RDS使用此角色来访问您在其他云产品中的资源"
//}



// resource "alicloud_resource_manager_policy_attachment" "default" {
// policy_name       = "AliyunRDSInstanceEncryptionRolePolicy"
// policy_type       = "System"
// principal_name    = "AliyunRDSInstanceEncryptionDefaultRole@role.${data.alicloud_account.current.id}.onaliyunservice.com"
// principal_type    = "ServiceRole"
// resource_group_id = "${data.alicloud_account.current.id}"
// }

Removing alicloud_polardb_cluster from your configuration

The alicloud_polardb_cluster resource allows you to manage your polardb cluster, but Terraform cannot destroy it if your cluster type is pre paid(post paid type can destroy normally). Removing this resource from your configuration will remove it from your statefile and management, but will not destroy the cluster. You can resume managing the cluster via the polardb Console.

Argument Reference

The following arguments are supported:

db_cluster_ip_array

The db_cluster_ip_array supports the following:

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

PolarDB cluster can be imported using the id, e.g.

$ terraform import alicloud_polardb_cluster.example pc-abc12345678