Provides a Classic Load Balancer (SLB) Load Balancer Listener resource.
For information about Classic Load Balancer (SLB) and how to use it, see What is Classic Load Balancer.
For information about listener and how to use it, please see the following:
Basic Usage
variable "name" {
default = "tf-example"
}
resource "random_integer" "default" {
min = 10000
max = 99999
}
resource "alicloud_slb_load_balancer" "listener" {
load_balancer_name = "${var.name}-${random_integer.default.result}"
internet_charge_type = "PayByTraffic"
address_type = "internet"
instance_charge_type = "PayByCLCU"
}
resource "alicloud_slb_listener" "listener" {
load_balancer_id = alicloud_slb_load_balancer.listener.id
backend_port = 80
frontend_port = 80
protocol = "http"
bandwidth = 10
sticky_session = "on"
sticky_session_type = "insert"
cookie_timeout = 86400
cookie = "tfslblistenercookie"
health_check = "on"
health_check_domain = "ali.com"
health_check_uri = "/cons"
health_check_connect_port = 20
healthy_threshold = 8
unhealthy_threshold = 8
health_check_timeout = 8
health_check_interval = 5
health_check_http_code = "http_2xx,http_3xx"
x_forwarded_for {
retrive_slb_ip = true
retrive_slb_id = true
}
acl_status = "on"
acl_type = "white"
acl_id = alicloud_slb_acl.listener.id
request_timeout = 80
idle_timeout = 30
}
resource "alicloud_slb_acl" "listener" {
name = "${var.name}-${random_integer.default.result}"
ip_version = "ipv4"
}
resource "alicloud_slb_acl_entry_attachment" "first" {
acl_id = alicloud_slb_acl.listener.id
entry = "10.10.10.0/24"
comment = "first"
}
resource "alicloud_slb_acl_entry_attachment" "second" {
acl_id = alicloud_slb_acl.listener.id
entry = "168.10.10.0/24"
comment = "second"
}
The following arguments are supported:
HTTP Listener
- See HTTP Listener
below.HTTPS Listener
- See HTTPS Listener
below.TCP Listener
- See TCP Listener
below.UDP Listener
- See UDP Listener
below.The HTTP Listener supports the following:
load_balancer_id
- (Required, ForceNew) The Load Balancer ID which is used to launch a new listener.protocol
- (Required, ForceNew) The protocol to listen on. Valid values: http
.frontend_port
- (Required, Int, ForceNew) The frontend port that is used by the CLB instance. Valid values: 1
to 65535
.backend_port
- (Optional, Int, ForceNew) The backend port that is used by the CLB instance. Valid values: 1
to 65535
. NOTE: If server_group_id
is not set, backend_port
is required.bandwidth
- (Optional, Int) The maximum bandwidth of the listener. Unit: Mbit/s. Valid values:
-1
: If you set bandwidth
to -1
, the bandwidth of the listener is unlimited.1
to 1000
: The sum of the maximum bandwidth that you specify for all listeners of the CLB instance cannot exceed the maximum bandwidth of the CLB instance.
The HTTPS Listener supports the following:
load_balancer_id
- (Required, ForceNew) The Load Balancer ID which is used to launch a new listener.protocol
- (Required, ForceNew) The protocol to listen on. Valid values: https
.frontend_port
- (Required, Int, ForceNew) The frontend port that is used by the CLB instance. Valid values: 1
to 65535
.bandwidth
- (Required, Int) The maximum bandwidth of the listener. Unit: Mbit/s. Valid values:
-1
: For a pay-by-data-transfer Internet-facing CLB instance, if you set bandwidth
to -1
, the bandwidth of the listener is unlimited.1
to 1000
: The sum of the maximum bandwidth that you specify for all listeners of the CLB instance cannot exceed the maximum bandwidth of the CLB instance.
The TCP Listener supports the following:
load_balancer_id
- (Required, ForceNew) The Load Balancer ID which is used to launch a new listener.protocol
- (Required, ForceNew) The protocol to listen on. Valid values: tcp
.frontend_port
- (Required, Int, ForceNew) The frontend port that is used by the CLB instance. Valid values: 1
to 65535
.bandwidth
- (Required, Int) The maximum bandwidth of the listener. Unit: Mbit/s. Valid values:
-1
: For a pay-by-data-transfer Internet-facing CLB instance, if you set bandwidth
to -1
, the bandwidth of the listener is unlimited.1
to 1000
: The sum of the maximum bandwidth that you specify for all listeners of the CLB instance cannot exceed the maximum bandwidth of the CLB instance.
The UDP Listener supports the following:
load_balancer_id
- (Required, ForceNew) The Load Balancer ID which is used to launch a new listener.protocol
- (Required, ForceNew) The protocol to listen on. Valid values: udp
.frontend_port
- (Required, Int, ForceNew) The frontend port that is used by the CLB instance. Valid values: 1
to 65535
.bandwidth
- (Required, Int) The maximum bandwidth of the listener. Unit: Mbit/s. Valid values:
-1
: For a pay-by-data-transfer Internet-facing CLB instance, if you set bandwidth
to -1
, the bandwidth of the listener is unlimited.1
to 1000
: The sum of the maximum bandwidth that you specify for all listeners of the CLB instance cannot exceed the maximum bandwidth of the CLB instance.
x_forwarded_for
The x_forwarded_for mapping supports the following:
retrive_slb_ip
- (Optional, Bool) Indicates whether the SLB-IP header is used to retrieve the virtual IP address (VIP) requested by the client. Default value: false
. Valid values: true
, false
.retrive_slb_id
- (Optional, Bool) Indicates whether the SLB-ID header is used to retrieve the ID of the CLB instance. Default value: false
. Valid values: true
, false
.retrive_slb_proto
- (Optional, Bool) Specifies whether to use the X-Forwarded-Proto header to retrieve the listener protocol. Default value: false
. Valid values: true
, false
.The following attributes are exported:
id
- The resource ID in terraform of Listener. It formats as <load_balancer_id>:<protocol>:<frontend_port>
.
Classic Load Balancer (SLB) Load Balancer Listener can be imported using the id, e.g.
$ terraform import alicloud_slb_listener.example <load_balancer_id>:<protocol>:<frontend_port>
NOTE: Before provider version 1.57.1, Classic Load Balancer (SLB) Load Balancer Listener can be imported using the id, e.g.
$ terraform import alicloud_slb_listener.example <load_balancer_id>:<frontend_port>