» alicloud_slb_rule

A forwarding rule is configured in HTTP/HTTPS listener and it used to listen a list of backend servers which in one specified virtual backend server group. You can add forwarding rules to a listener to forward requests based on the domain names or the URL in the request.

» Example Usage

variable "name" {
    default = "slbrulebasicconfig"
}

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}"
    security_groups = ["${alicloud_security_group.default.*.id}"]
    internet_charge_type = "PayByTraffic"
    internet_max_bandwidth_out = "10"
    availability_zone = "${data.alicloud_zones.default.zones.0.id}"
    instance_charge_type = "PostPaid"
    system_disk_category = "cloud_efficiency"
    vswitch_id = "${alicloud_vswitch.default.id}"
    instance_name = "${var.name}"
}

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

resource "alicloud_slb_listener" "default" {
    load_balancer_id = "${alicloud_slb.default.id}"
    backend_port = 22
    frontend_port = 22
    protocol = "http"
    bandwidth = 5
    health_check_connect_port = "20"
}

resource "alicloud_slb_server_group" "default" {
    load_balancer_id = "${alicloud_slb.default.id}"
    servers = [
        {
            server_ids = ["${alicloud_instance.default.*.id}"]
            port = 80
            weight = 100
        }
    ]
}

resource "alicloud_slb_rule" "default" {
    load_balancer_id = "${alicloud_slb.default.id}"
    frontend_port = "${alicloud_slb_listener.default.frontend_port}"
    name = "${var.name}"
    domain = "*.aliyun.com"
    url = "/image"
    server_group_id = "${alicloud_slb_server_group.default.id}"
}

» Argument Reference

The following arguments are supported:

  • load_balancer_id - (Required, ForceNew) The Load Balancer ID which is used to launch the new forwarding rule.
  • name - (Optional, ForceNew) Name of the forwarding rule. Our plugin provides a default name: "tf-slb-rule".
  • frontend_port - (Required, ForceNew) The listener frontend port which is used to launch the new forwarding rule. Valid range: [1-65535].
  • domain - (Optional, ForceNew) Domain name of the forwarding rule. It can contain letters a-z, numbers 0-9, hyphens (-), and periods (.), and wildcard characters. The following two domain name formats are supported:
    • Standard domain name: www.test.com
    • Wildcard domain name: .test.com. wildcard () must be the first character in the format of (*.)
  • url - (Optional, ForceNew) Domain of the forwarding rule. It must be 2-80 characters in length. Only letters a-z, numbers 0-9, and characters '-' '/' '?' '%' '#' and '&' are allowed. URLs must be started with the character '/', but cannot be '/' alone.
  • server_group_id - (Required) ID of a virtual server group that will be forwarded.

» Attributes Reference

The following attributes are exported:

  • id - The ID of the forwarding rule.
  • load_balancer_id - The Load Balancer ID in which forwarding rule belongs.
  • name - The name of the forwarding rule.
  • forntend_port - The listener port in which forwarding rule belongs.
  • domain - The domain name of the forwarding rule.
  • url - The url of the forwarding rule.
  • server_group_id - The Id of the virtual server group.

» Import

Load balancer forwarding rule can be imported using the id, e.g.

$ terraform import alicloud_slb_rule.example rule-abc123456