Provides an RDS connection resource to allocate an Internet connection string for RDS instance, see What is DB Connection.
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"
}
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 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.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.RDS connection can be imported using the id, e.g.
$ terraform import alicloud_db_connection.example abc12345678