» alicloud_slb_attachment

Add a group of backend servers (ECS instance) to the Server Load Balancer or remove them from it.

» Example Usage

variable "name" {
  default = "slbattachmenttest"
}
data "alicloud_zones" "default" {
  available_disk_category     = "cloud_efficiency"
  available_resource_creation = "VSwitch"
}
data "alicloud_instance_types" "default" {
  availability_zone = "${data.alicloud_zones.default.zones.0.id}"
  cpu_core_count    = 1
  memory_size       = 2
}
data "alicloud_images" "default" {
  name_regex  = "^ubuntu_14.*_64"
  most_recent = true
  owners      = "system"
}

resource "alicloud_vpc" "default" {
  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/16"
  availability_zone = "${data.alicloud_zones.default.zones.0.id}"
  name              = "${var.name}"
}

resource "alicloud_security_group" "default" {
  name   = "${var.name}"
  vpc_id = "${alicloud_vpc.default.id}"
}

resource "alicloud_instance" "default" {
  image_id                   = "${data.alicloud_images.default.images.0.id}"
  instance_type              = "${data.alicloud_instance_types.default.instance_types.0.id}"
  internet_charge_type       = "PayByTraffic"
  internet_max_bandwidth_out = "5"
  system_disk_category       = "cloud_efficiency"
  security_groups            = ["${alicloud_security_group.default.id}"]
  instance_name              = "${var.name}"
  vswitch_id                 = "${alicloud_vswitch.default.id}"
}

resource "alicloud_slb" "default" {
  name       = "${var.name}"
  vswitch_id = "${alicloud_vswitch.default.id}"
}

resource "alicloud_slb_attachment" "default" {
  load_balancer_id = "${alicloud_slb.default.id}"
  instance_ids     = ["${alicloud_instance.default.id}"]
  weight           = 90
}

» Argument Reference

The following arguments are supported:

  • load_balancer_id - (Required) ID of the load balancer.
  • instance_ids - (Required) A list of instance ids to added backend server in the SLB.
  • weight - (Optional) Weight of the instances. Valid value range: [0-100]. Default to 100.
  • slb_id - (Deprecated) It has been deprecated from provider version 1.6.0. New field 'load_balancer_id' replaces it.
  • instances - (Deprecated) It has been deprecated from provider version 1.6.0. New field 'instance_ids' replaces it.

» Attributes Reference

The following attributes are exported:

» Import

Load balancer attachment can be imported using the id or load balancer id, e.g.

$ terraform import alicloud_slb_attachment.example lb-abc123456