alicloud_db_connection

更新时间:

Provides an RDS connection resource to allocate an Internet connection string for RDS instance, see What is DB Connection.

-> NOTE: Each RDS instance will allocate a intranet connnection string automatically and its prifix is RDS instance ID. To avoid unnecessary conflict, please specified a internet connection prefix before applying the resource.

-> NOTE: Available since v1.5.0.

Example Usage


variable "name" {
  default = "tf_example"
}

data "alicloud_db_zones" "default" {
  engine         = "MySQL"
  engine_version = "5.6"
}

resource "alicloud_vpc" "default" {
  vpc_name   = var.name
  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_db_zones.default.zones.0.id
  vswitch_name = var.name
}

resource "alicloud_db_instance" "default" {
  engine           = "MySQL"
  engine_version   = "5.6"
  instance_type    = "rds.mysql.t1.small"
  instance_storage = "10"
  vswitch_id       = alicloud_vswitch.default.id
  instance_name    = var.name
}

resource "alicloud_db_connection" "default" {
  instance_id       = alicloud_db_instance.default.id
  connection_prefix = "testabc"
}

Argument Reference

The following arguments are supported:

  • instance_id - (Required, ForceNew) The Id of instance that can run database.
  • connection_prefix - (Optional, ForceNew) Prefix of an Internet connection string. It must be checked for uniqueness. It may consist of lowercase letters, numbers, and underlines, and must start with a letter and have no more than 40 characters. Default to <instance_id> + 'tf'.
  • port - (Optional) Internet connection port. Valid value: [1000-5999]. Default to 3306.
  • babelfish_port - (Optional, Available since v1.176.0) The Tabular Data Stream (TDS) port of the instance for which Babelfish is enabled.

-> NOTE: This parameter applies only to ApsaraDB RDS for PostgreSQL instances. For more information about Babelfish for ApsaraDB RDS for PostgreSQL, see Introduction to Babelfish.

Attributes Reference

The following attributes are exported in addition to the arguments listed above:

  • id - The current instance connection resource ID. Composed of instance ID and connection string with format <instance_id>:<connection_prefix>.
  • connection_string - Connection instance string.
  • ip_address - The ip address of connection string.

Import

RDS connection can be imported using the id, e.g.

$ terraform import alicloud_db_connection.example abc12345678