alicloud_alb_server_group
更新时间:
Provides an ALB Server Group resource.
For information about ALB Server Group and how to use it, see What is Server Group.
-> NOTE: Available since v1.131.0.
Example Usage
Basic Usage
variable "name" {
default = "terraform-example"
}
data "alicloud_resource_manager_resource_groups" "example" {
}
data "alicloud_zones" "example" {
available_resource_creation = "Instance"
}
data "alicloud_instance_types" "example" {
availability_zone = data.alicloud_zones.example.zones.0.id
cpu_core_count = 1
memory_size = 2
}
data "alicloud_images" "example" {
name_regex = "^ubuntu_18.*64"
owners = "system"
}
resource "alicloud_vpc" "example" {
vpc_name = var.name
cidr_block = "10.4.0.0/16"
}
resource "alicloud_vswitch" "example" {
vswitch_name = var.name
cidr_block = "10.4.0.0/16"
vpc_id = alicloud_vpc.example.id
zone_id = data.alicloud_zones.example.zones.0.id
}
resource "alicloud_security_group" "example" {
name = var.name
description = var.name
vpc_id = alicloud_vpc.example.id
}
resource "alicloud_instance" "example" {
availability_zone = data.alicloud_zones.example.zones.0.id
instance_name = var.name
image_id = data.alicloud_images.example.images.0.id
instance_type = data.alicloud_instance_types.example.instance_types.0.id
security_groups = [alicloud_security_group.example.id]
vswitch_id = alicloud_vswitch.example.id
}
resource "alicloud_alb_server_group" "example" {
protocol = "HTTP"
vpc_id = alicloud_vpc.example.id
server_group_name = var.name
resource_group_id = data.alicloud_resource_manager_resource_groups.example.groups.0.id
sticky_session_config {
sticky_session_enabled = true
cookie = "tf-example"
sticky_session_type = "Server"
}
health_check_config {
health_check_connect_port = "46325"
health_check_enabled = true
health_check_host = "tf-example.com"
health_check_codes = ["http_2xx", "http_3xx", "http_4xx"]
health_check_http_version = "HTTP1.1"
health_check_interval = "2"
health_check_method = "HEAD"
health_check_path = "/tf-example"
health_check_protocol = "HTTP"
health_check_timeout = 5
healthy_threshold = 3
unhealthy_threshold = 3
}
servers {
description = var.name
port = 80
server_id = alicloud_instance.example.id
server_ip = alicloud_instance.example.private_ip
server_type = "Ecs"
weight = 10
}
tags = {
Created = "TF"
}
}
Argument Reference
The following arguments are supported:
server_group_name
- (Required) The name of the server group.server_group_type
- (Optional, ForceNew, Available since v1.193.0) The type of the server group. Default value:Instance
. Valid values:Instance
: allows you add servers by specifying Ecs, Ens, or Eci.Ip
: allows you to add servers by specifying IP addresses.Fc
: allows you to add servers by specifying functions of Function Compute.
protocol
- (Optional, ForceNew) The server protocol. Valid values:HTTP
,HTTPS
,gRPC
. Whileserver_group_type
isFc
this parameter will not take effect. From version 1.215.0,protocol
can be set togRPC
.vpc_id
- (Optional, ForceNew) The ID of the VPC that you want to access. NOTE: This parameter takes effect when theserver_group_type
parameter is set toInstance
orIp
.scheduler
- (Optional) The scheduling algorithm. Valid values:Sch
,Wlc
,Wrr
. NOTE: This parameter takes effect when theserver_group_type
parameter is set toInstance
orIp
.resource_group_id
- (Optional) The ID of the resource group.sticky_session_config
- (Optional, Set) The configuration of session persistence. Seesticky_session_config
below.health_check_config
- (Required, Set) The configuration of health checks. Seehealth_check_config
below.servers
- (Optional, Set) The backend servers. Seeservers
below.dry_run
- (Optional, Bool) The dry run.tags
- (Optional) A mapping of tags to assign to the resource.
sticky_session_config
The sticky_session_config supports the following:
sticky_session_enabled
- (Optional, Bool) Specifies whether to enable session persistence. Default value:false
. Valid values:true
,false
. NOTE: This parameter takes effect when theserver_group_type
parameter is set toInstance
orIp
.sticky_session_type
- (Optional) The method that is used to handle a cookie. Valid values:Server
,Insert
.cookie
- (Optional) The cookie to be configured on the server. NOTE: This parameter takes effect when thesticky_session_enabled
parameter is set totrue
and thesticky_session_type
parameter is set toServer
.cookie_timeout
- (Optional, Int) The timeout period of a cookie. Unit: seconds. Default value:1000
. Valid values:1
to86400
. NOTE: This parameter takes effect when thesticky_session_enabled
parameter is set totrue
and thesticky_session_type
parameter is set toInsert
.
health_check_config
The health_check_config supports the following:
health_check_enabled
- (Required, Bool) Specifies whether to enable the health check feature. Valid values:true
,false
.health_check_connect_port
- (Optional, Int) The backend port that is used for health checks. Default value:0
. Valid values:0
to65535
. A value of 0 indicates that a backend server port is used for health checks.health_check_host
- (Optional) The domain name that is used for health checks.health_check_http_version
- (Optional) The version of the HTTP protocol. Default value:HTTP1.1
. Valid values:HTTP1.0
andHTTP1.1
. NOTE: This parameter takes effect only whenhealth_check_protocol
is set toHTTP
orHTTPS
.health_check_interval
- (Optional, Int) The interval at which health checks are performed. Unit: seconds. Default value:2
. Valid values:1
to50
.health_check_method
- (Optional) The HTTP method that is used for health checks. Default value:GET
. Valid values:GET
,POST
,HEAD
. NOTE: This parameter takes effect only whenhealth_check_protocol
is set toHTTP
,HTTPS
, orgRPC
. From version 1.215.0,health_check_method
can be set toPOST
.health_check_path
- (Optional) The path that is used for health checks. NOTE: This parameter takes effect only whenhealth_check_protocol
is set toHTTP
orHTTPS
.health_check_protocol
- (Optional) The protocol that is used for health checks. Valid values:HTTP
,HTTPS
,TCP
andgRPC
.health_check_timeout
- (Optional, Int) The timeout period for a health check response. If a backend Elastic Compute Service (ECS) instance does not send an expected response within the specified period of time, the ECS instance is considered unhealthy. Unit: seconds. Default value:5
. Valid values:1
to300
. NOTE: If the value ofhealth_check_timeout
is smaller than the value ofhealth_check_interval
, the value ofhealth_check_timeout
is ignored and the value ofhealth_check_interval
is used.healthy_threshold
- (Optional, Int) The number of times that an unhealthy backend server must consecutively pass health checks before it is declared healthy. Default value:3
. Valid values:2
to10
.unhealthy_threshold
- (Optional, Int) The number of times that a healthy backend server must consecutively fail health checks before it is declared unhealthy. Default value:3
. Valid values:2
to10
.health_check_codes
- (Optional, List) The HTTP status codes that are used to indicate whether the backend server passes the health check. Valid values:- If
health_check_protocol
is set toHTTP
orHTTPS
. Valid values:http_2xx
,http_3xx
,http_4xx
, andhttp_5xx
. Default value:http_2xx
. - If
health_check_protocol
is set togRPC
. Valid values:0
to99
. Default value:0
.
- If
servers
The servers supports the following:
server_id
- (Required) The ID of the backend server.- If
server_group_type
is set toInstance
, set the parameter to the ID of an Elastic Compute Service (ECS) instance, an elastic network interface (ENI), or an elastic container instance. These backend servers are specified by Ecs, Eni, or Eci. - If
server_group_type
is set toIp
, set the parameter to an IP address specified in the server group. - If
server_group_type
is set toFc
, set the parameter to the Alibaba Cloud Resource Name (ARN) of a function specified in the server group.
- If
server_type
- (Required) The type of the server. The type of the server. Valid values:Ecs
: an ECS instance.Eni
: an ENI.Eci
: an elastic container instance.Ip
(Available since v1.194.0): an IP address.Fc
(Available since v1.194.0): a function.
server_ip
- (Optional) The IP address of an Elastic Compute Service (ECS) instance, an elastic network interface (ENI), or an elastic container instance. Note: Ifserver_group_type
is set toFc
, you do not need to configure parameters, otherwise this attribute is required. Ifserver_group_type
is set toIp
, the value of this property is the same as theserver_id
value.port
- (Optional, Int) The port used by the backend server. Valid values:1
to65535
. Note: This parameter is required if theserver_type
parameter is set toEcs
,Eni
,Eci
, orIp
. You do not need to configure this parameter if you setserver_type
toFc
.remote_ip_enabled
- (Optional, Bool, Available since v1.194.0) Specifies whether to enable the remote IP address feature. You can specify up to 40 servers in each call. Note: Ifserver_type
is set toIp
, this parameter is available.weight
- (Optional, Int) The weight of the server. Default value:100
. Valid values:0
to100
. If the value is set to0
, no requests are forwarded to the server. Note: You do not need to set this parameter if you setserver_type
toFc
.description
- (Optional) The description of the backend server.
Attributes Reference
The following attributes are exported:
id
- The resource ID in terraform of Server Group.status
- The status of the Server Group.servers
- The backend servers.status
- The status of the backend server.
Timeouts
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 6 mins) Used when create the Server Group.update
- (Defaults to 6 mins) Used when update the Server Group.delete
- (Defaults to 6 mins) Used when delete the Server Group.
Import
ALB Server Group can be imported using the id, e.g.
$ terraform import alicloud_alb_server_group.example <id>
文档内容是否对您有帮助?