diff --git a/alicloud/resource_alicloud_ga_listener.go b/alicloud/resource_alicloud_ga_listener.go index e422cfa70a06..24fcfe3b8364 100644 --- a/alicloud/resource_alicloud_ga_listener.go +++ b/alicloud/resource_alicloud_ga_listener.go @@ -59,6 +59,16 @@ func resourceAliCloudGaListener() *schema.Resource { Computed: true, ValidateFunc: StringInSlice([]string{"http1.1", "http2", "http3"}, false), }, + "idle_timeout": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, + "request_timeout": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + }, "client_affinity": { Type: schema.TypeString, Optional: true, @@ -179,6 +189,14 @@ func resourceAliCloudGaListenerCreate(d *schema.ResourceData, meta interface{}) request["HttpVersion"] = v } + if v, ok := d.GetOkExists("idle_timeout"); ok { + request["IdleTimeout"] = v + } + + if v, ok := d.GetOkExists("request_timeout"); ok { + request["RequestTimeout"] = v + } + if v, ok := d.GetOk("client_affinity"); ok { request["ClientAffinity"] = v } @@ -276,6 +294,8 @@ func resourceAliCloudGaListenerRead(d *schema.ResourceData, meta interface{}) er d.Set("security_policy_id", object["SecurityPolicyId"]) d.Set("listener_type", object["Type"]) d.Set("http_version", object["HttpVersion"]) + d.Set("idle_timeout", object["IdleTimeout"]) + d.Set("request_timeout", object["RequestTimeout"]) d.Set("client_affinity", object["ClientAffinity"]) d.Set("name", object["Name"]) d.Set("description", object["Description"]) @@ -376,6 +396,22 @@ func resourceAliCloudGaListenerUpdate(d *schema.ResourceData, meta interface{}) } + if d.HasChange("idle_timeout") { + update = true + + if v, ok := d.GetOkExists("idle_timeout"); ok { + request["IdleTimeout"] = v + } + } + + if d.HasChange("request_timeout") { + update = true + + if v, ok := d.GetOkExists("request_timeout"); ok { + request["RequestTimeout"] = v + } + } + if d.HasChange("client_affinity") { update = true request["ClientAffinity"] = d.Get("client_affinity") diff --git a/alicloud/resource_alicloud_ga_listener_test.go b/alicloud/resource_alicloud_ga_listener_test.go index d48894eb8477..faaa346ebec5 100644 --- a/alicloud/resource_alicloud_ga_listener_test.go +++ b/alicloud/resource_alicloud_ga_listener_test.go @@ -67,6 +67,16 @@ func TestAccAliCloudGaListener_basic0(t *testing.T) { }), ), }, + { + Config: testAccConfig(map[string]interface{}{ + "idle_timeout": "10", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "idle_timeout": "10", + }), + ), + }, { Config: testAccConfig(map[string]interface{}{ "client_affinity": "SOURCE_IP", @@ -148,6 +158,7 @@ func TestAccAliCloudGaListener_basic0_twin(t *testing.T) { "protocol": "TCP", "proxy_protocol": "true", "listener_type": "Standard", + "idle_timeout": "10", "client_affinity": "SOURCE_IP", "name": name, "description": name, @@ -164,6 +175,7 @@ func TestAccAliCloudGaListener_basic0_twin(t *testing.T) { "protocol": "TCP", "proxy_protocol": "true", "listener_type": "Standard", + "idle_timeout": "10", "client_affinity": "SOURCE_IP", "name": name, "description": name, @@ -184,7 +196,7 @@ func TestAccAliCloudGaListener_basic1(t *testing.T) { var v map[string]interface{} checkoutSupportedRegions(t, true, connectivity.GaSupportRegions) resourceId := "alicloud_ga_listener.default" - ra := resourceAttrInit(resourceId, AliCloudGaListenerMap0) + ra := resourceAttrInit(resourceId, AliCloudGaListenerMap1) rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { return &GaService{testAccProvider.Meta().(*connectivity.AliyunClient)} }, "DescribeGaListener") @@ -256,6 +268,26 @@ func TestAccAliCloudGaListener_basic1(t *testing.T) { }), ), }, + { + Config: testAccConfig(map[string]interface{}{ + "idle_timeout": "60", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "idle_timeout": "60", + }), + ), + }, + { + Config: testAccConfig(map[string]interface{}{ + "request_timeout": "80", + }), + Check: resource.ComposeTestCheckFunc( + testAccCheck(map[string]string{ + "request_timeout": "80", + }), + ), + }, { Config: testAccConfig(map[string]interface{}{ "client_affinity": "SOURCE_IP", @@ -346,7 +378,7 @@ func TestAccAliCloudGaListener_basic1_twin(t *testing.T) { var v map[string]interface{} checkoutSupportedRegions(t, true, connectivity.GaSupportRegions) resourceId := "alicloud_ga_listener.default" - ra := resourceAttrInit(resourceId, AliCloudGaListenerMap0) + ra := resourceAttrInit(resourceId, AliCloudGaListenerMap1) rc := resourceCheckInitWithDescribeMethod(resourceId, &v, func() interface{} { return &GaService{testAccProvider.Meta().(*connectivity.AliyunClient)} }, "DescribeGaListener") @@ -370,6 +402,8 @@ func TestAccAliCloudGaListener_basic1_twin(t *testing.T) { "security_policy_id": "tls_cipher_policy_1_1", "listener_type": "Standard", "http_version": "http3", + "idle_timeout": "60", + "request_timeout": "80", "client_affinity": "SOURCE_IP", "name": name, "description": name, @@ -401,6 +435,8 @@ func TestAccAliCloudGaListener_basic1_twin(t *testing.T) { "security_policy_id": "tls_cipher_policy_1_1", "listener_type": "Standard", "http_version": "http3", + "idle_timeout": "60", + "request_timeout": "80", "client_affinity": "SOURCE_IP", "name": name, "description": name, @@ -420,7 +456,14 @@ func TestAccAliCloudGaListener_basic1_twin(t *testing.T) { } var AliCloudGaListenerMap0 = map[string]string{ - "status": CHECKSET, + "idle_timeout": CHECKSET, + "status": CHECKSET, +} + +var AliCloudGaListenerMap1 = map[string]string{ + "idle_timeout": CHECKSET, + "request_timeout": CHECKSET, + "status": CHECKSET, } func AliCloudGaListenerBasicDependence0(name string) string { diff --git a/website/docs/r/ga_listener.html.markdown b/website/docs/r/ga_listener.html.markdown index 63e71a96d0dd..b3f54b3cf6e1 100644 --- a/website/docs/r/ga_listener.html.markdown +++ b/website/docs/r/ga_listener.html.markdown @@ -79,6 +79,12 @@ The following arguments are supported: - `CustomRouting`: custom routing. * `http_version` - (Optional, Available since v1.220.0) The maximum version of the HTTP protocol. Default Value: `http2`. Valid values: `http1.1`, `http2`, `http3`. -> **NOTE:** `http_version` is only valid when `protocol` is `HTTPS`. +* `idle_timeout` - (Optional, Int, Available since v1.226.1) The timeout period of idle connections. Unit: seconds. Valid values: + - If you set `protocol` to `TCP`. Default Value: `900`. Valid values: `10` to `900`. + - If you set `protocol` to `UDP`. Default Value: `20`. Valid values: `10` to `20`. + - If you set `protocol` to `HTTP` or `HTTPS`. Default Value: `15`. Valid values: `1` to `60`. +* `request_timeout` - (Optional, Int, Available since v1.226.1) The timeout period for HTTP or HTTPS requests. Unit: seconds. Default Value: `60`. Valid values: `1` to `180`. +-> **NOTE:** `request_timeout` is only valid when `protocol` is `HTTP` or `HTTPS`. * `client_affinity` - (Optional) The clientAffinity of the listener. Default value: `NONE`. Valid values: - `NONE`: client affinity is not maintained, that is, connection requests from the same client cannot always be directed to the same terminal node. - `SOURCE_IP`: maintain client affinity. When a client accesses a stateful application, all requests from the same client can be directed to the same terminal node, regardless of the source port and protocol.