Skip to content

Commit

Permalink
resource/alicloud_ga_listener: Added the field idle_timeout, request_…
Browse files Browse the repository at this point in the history
…timeout
  • Loading branch information
MrWolong committed Jul 1, 2024
1 parent d717183 commit b10f462
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
36 changes: 36 additions & 0 deletions alicloud/resource_alicloud_ga_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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")
Expand Down
49 changes: 46 additions & 3 deletions alicloud/resource_alicloud_ga_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/ga_listener.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b10f462

Please sign in to comment.