Skip to content

Commit 71108f3

Browse files
authored
feat(as): new datasource to query scaling activity logs (#6578)
1 parent 79a1952 commit 71108f3

File tree

4 files changed

+868
-0
lines changed

4 files changed

+868
-0
lines changed
+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
subcategory: "Auto Scaling"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_asv2_activity_logs"
5+
description: |-
6+
Use this data source to get a list of AS (V2 version) scaling activity logs within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_asv2_activity_logs
10+
11+
Use this data source to get a list of AS (V2 version) scaling activity logs within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
variable "group_id" {}
17+
18+
data "huaweicloud_asv2_activity_logs" "test" {
19+
scaling_group_id = var.group_id
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `region` - (Optional, String) Specifies the region in which to query the resource.
28+
If omitted, the provider-level region will be used.
29+
30+
* `scaling_group_id` - (Required, String) Specifies the AS group ID.
31+
32+
* `log_id` - (Optional, String) Specifies the scaling action log ID.
33+
34+
* `start_time` - (Optional, String) Specifies the start time that complies with UTC for querying scaling action logs.
35+
The format of the start time is yyyy-MM-ddThh:mm:ssZ.
36+
37+
* `end_time` - (Optional, String) Specifies the end time that complies with UTC for querying scaling action logs.
38+
The format of the end time is yyyy-MM-ddThh:mm:ssZ.
39+
40+
* `type` - (Optional, String) Specifies the types of the scaling actions to be queried. Different types are separated by
41+
commas (,). Valid values are:
42+
+ **NORMAL**: Indicates a common scaling action.
43+
+ **MANUAL_REMOVE**: Indicates manually removing instances from an AS group.
44+
+ **MANUAL_DELETE**: Indicates manually removing and deleting instances from an AS group.
45+
+ **MANUAL_ADD**: Indicates manually adding instances to an AS group.
46+
+ **ELB_CHECK_DELETE**: Indicates that instances are removed from an AS group and deleted based on the ELB health check
47+
result.
48+
+ **AUDIT_CHECK_DELETE**: Indicates that instances are removed from an AS group and deleted based on the audit.
49+
+ **DIFF**: Indicates that the number of expected instances is different from the actual number of instances.
50+
+ **MODIFY_ELB**: Indicates the load balancer migration.
51+
+ **ENTER_STANDBY**: Indicates setting instances to standby mode.
52+
+ **EXIT_STANDBY**: Indicates canceling standby mode for instances.
53+
54+
* `status` - (Optional, String) Specifies the status of the scaling action. Valid values are:
55+
+ **SUCCESS**: The scaling action has been performed.
56+
+ **FAIL**: Performing the scaling action failed.
57+
+ **DOING**: The scaling action is being performed.
58+
59+
## Attribute Reference
60+
61+
In addition to all arguments above, the following attributes are exported:
62+
63+
* `id` - The data source ID.
64+
65+
* `scaling_activity_log` - The scaling action logs.
66+
67+
The [scaling_activity_log](#scaling_activity_log_struct) structure is documented below.
68+
69+
<a name="scaling_activity_log_struct"></a>
70+
The `scaling_activity_log` block supports:
71+
72+
* `id` - The scaling action log ID.
73+
74+
* `scaling_value` - The number of added or deleted instances during the scaling.
75+
76+
* `desire_value` - The expected number of instances for the scaling action.
77+
78+
* `type` - The type of the scaling action.
79+
80+
* `status` - The status of the scaling action. Valid values are:
81+
+ **SUCCESS**: The scaling action has been performed.
82+
+ **FAIL**: Performing the scaling action failed.
83+
+ **DOING**: The scaling action is being performed.
84+
85+
* `description` - The description of the scaling action.
86+
87+
* `start_time` - The start time of the scaling action. The time format must comply with UTC.
88+
89+
* `end_time` - The end time of the scaling action. The time format must comply with UTC.
90+
91+
* `instance_value` - The number of instances in the AS group.
92+
93+
* `instance_removed_list` - The names of the ECSs that are removed from the AS group in a scaling action.
94+
95+
The [instance_removed_list](#scaling_activity_log_scaling_instance_struct) structure is documented below.
96+
97+
* `instance_standby_list` - The ECSs that are set to standby mode or for which standby mode is canceled in a scaling action.
98+
99+
The [instance_standby_list](#scaling_activity_log_scaling_instance_struct) structure is documented below.
100+
101+
* `instance_failed_list` - The ECSs for which a scaling action fails.
102+
103+
The [instance_failed_list](#scaling_activity_log_scaling_instance_struct) structure is documented below.
104+
105+
* `instance_deleted_list` - The names of the ECSs that are removed from the AS group and deleted in a scaling action.
106+
107+
The [instance_deleted_list](#scaling_activity_log_scaling_instance_struct) structure is documented below.
108+
109+
* `instance_added_list` - The names of the ECSs that are added to the AS group in a scaling action.
110+
111+
The [instance_added_list](#scaling_activity_log_scaling_instance_struct) structure is documented below.
112+
113+
* `lb_bind_failed_list` - The load balancers that failed to be bound to the AS group.
114+
115+
The [lb_bind_failed_list](#scaling_activity_log_modify_lb_struct) structure is documented below.
116+
117+
* `lb_unbind_failed_list` - The load balancers that failed to be unbound from the AS group.
118+
119+
The [lb_unbind_failed_list](#scaling_activity_log_modify_lb_struct) structure is documented below.
120+
121+
* `lb_bind_success_list` - The load balancers that are bound to the AS group.
122+
123+
The [lb_bind_success_list](#scaling_activity_log_modify_lb_struct) structure is documented below.
124+
125+
* `lb_unbind_success_list` - The load balancers that are unbound from the AS group.
126+
127+
The [lb_unbind_success_list](#scaling_activity_log_modify_lb_struct) structure is documented below.
128+
129+
<a name="scaling_activity_log_scaling_instance_struct"></a>
130+
The `instance_removed_list`, `instance_standby_list`, `instance_failed_list`, `instance_deleted_list`, and
131+
`instance_added_list` block supports:
132+
133+
* `instance_name` - The ECS name.
134+
135+
* `instance_id` - The ECS ID.
136+
137+
* `failed_reason` - The cause of the instance scaling failure.
138+
139+
* `failed_details` - The details of the instance scaling failure.
140+
141+
* `instance_config` - The information about instance configurations.
142+
143+
<a name="scaling_activity_log_modify_lb_struct"></a>
144+
The `lb_bind_failed_list`, `lb_unbind_failed_list`, `lb_bind_success_list`, and `lb_unbind_success_list` block supports:
145+
146+
* `lbaas_listener` - The information about an enhanced load balancer.
147+
148+
The [lbaas_listener](#lbaas_listener_struct) structure is documented below.
149+
150+
* `listener` - The information about a classic load balancer.
151+
152+
* `failed_reason` - The cause of a load balancer migration failure.
153+
154+
* `failed_details` - The details of a load balancer migration failure.
155+
156+
<a name="lbaas_listener_struct"></a>
157+
The `lbaas_listener` block supports:
158+
159+
* `listener_id` - The listener ID.
160+
161+
* `pool_id` - The backend ECS group ID.
162+
163+
* `protocol_port` - The backend protocol port, which is the port on which a backend ECS listens for traffic.
164+
165+
* `weight` - The weight, which determines the portion of requests a backend ECS processes when being compared to other
166+
backend ECSs added to the same listener.

huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ func Provider() *schema.Provider {
489489
"huaweicloud_apig_throttling_policies": apig.DataSourceThrottlingPolicies(),
490490

491491
"huaweicloud_as_activity_logs": as.DataSourceActivityLogs(),
492+
"huaweicloud_asv2_activity_logs": as.DataSourceAsv2ActivityLogs(),
492493
"huaweicloud_as_configurations": as.DataSourceASConfigurations(),
493494
"huaweicloud_as_group_quotas": as.DataSourceAsGroupQuotas(),
494495
"huaweicloud_as_group_tags": as.DataSourceAsGroupTags(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package as
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
9+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
10+
)
11+
12+
func TestAccDataSourceAsv2ActivityLogs_basic(t *testing.T) {
13+
var (
14+
dataSource = "data.huaweicloud_asv2_activity_logs.test"
15+
dc = acceptance.InitDataSourceCheck(dataSource)
16+
17+
byLogID = "data.huaweicloud_asv2_activity_logs.log_id_filter"
18+
dcByLogID = acceptance.InitDataSourceCheck(byLogID)
19+
20+
byStartTime = "data.huaweicloud_asv2_activity_logs.start_time_filter"
21+
dcByStartTime = acceptance.InitDataSourceCheck(byStartTime)
22+
23+
byEndTime = "data.huaweicloud_asv2_activity_logs.end_time_filter"
24+
dcByEndTime = acceptance.InitDataSourceCheck(byEndTime)
25+
26+
byStartEndTime = "data.huaweicloud_asv2_activity_logs.start_end_time_filter"
27+
dcByStartEndTime = acceptance.InitDataSourceCheck(byStartEndTime)
28+
29+
byType = "data.huaweicloud_asv2_activity_logs.type_filter"
30+
dcByType = acceptance.InitDataSourceCheck(byType)
31+
32+
byStatus = "data.huaweicloud_asv2_activity_logs.status_filter"
33+
dcByStatus = acceptance.InitDataSourceCheck(byStatus)
34+
)
35+
36+
resource.ParallelTest(t, resource.TestCase{
37+
PreCheck: func() {
38+
acceptance.TestAccPreCheck(t)
39+
// Please prepare the scaling group ID with scaling activity logs in advance.
40+
acceptance.TestAccPreCheckASScalingGroupID(t)
41+
},
42+
ProviderFactories: acceptance.TestAccProviderFactories,
43+
Steps: []resource.TestStep{
44+
{
45+
Config: testDataSourceAsv2ActivityLogs_basic(),
46+
Check: resource.ComposeTestCheckFunc(
47+
dc.CheckResourceExists(),
48+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.#"),
49+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.description"),
50+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.desire_value"),
51+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.start_time"),
52+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.end_time"),
53+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.id"),
54+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.instance_value"),
55+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.scaling_value"),
56+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.status"),
57+
resource.TestCheckResourceAttrSet(dataSource, "scaling_activity_log.0.type"),
58+
59+
dcByLogID.CheckResourceExists(),
60+
resource.TestCheckOutput("is_log_id_filter_useful", "true"),
61+
62+
dcByStartTime.CheckResourceExists(),
63+
resource.TestCheckOutput("is_start_time_filter_useful", "true"),
64+
65+
dcByEndTime.CheckResourceExists(),
66+
resource.TestCheckOutput("is_end_time_filter_useful", "true"),
67+
68+
dcByStartEndTime.CheckResourceExists(),
69+
resource.TestCheckOutput("start_time_filter_result1_useful", "true"),
70+
resource.TestCheckOutput("end_time_filter_result1_useful", "true"),
71+
72+
dcByType.CheckResourceExists(),
73+
resource.TestCheckOutput("is_type_filter_useful", "true"),
74+
75+
dcByStatus.CheckResourceExists(),
76+
resource.TestCheckOutput("is_status_filter_useful", "true"),
77+
),
78+
},
79+
},
80+
})
81+
}
82+
83+
func testDataSourceAsv2ActivityLogs_basic() string {
84+
return fmt.Sprintf(`
85+
data "huaweicloud_asv2_activity_logs" "test" {
86+
scaling_group_id = "%[1]s"
87+
}
88+
89+
# Filter by log_id
90+
locals {
91+
log_id = data.huaweicloud_asv2_activity_logs.test.scaling_activity_log[0].id
92+
}
93+
94+
data "huaweicloud_asv2_activity_logs" "log_id_filter" {
95+
scaling_group_id = "%[1]s"
96+
log_id = local.log_id
97+
}
98+
99+
locals {
100+
log_id_filter_result = [
101+
for v in data.huaweicloud_asv2_activity_logs.log_id_filter.scaling_activity_log[*].id : v == local.log_id
102+
]
103+
}
104+
105+
output "is_log_id_filter_useful" {
106+
value = alltrue(local.log_id_filter_result) && length(local.log_id_filter_result) > 0
107+
}
108+
109+
# Filter by time
110+
locals {
111+
start_time_utc = data.huaweicloud_asv2_activity_logs.test.scaling_activity_log[0].start_time
112+
end_time_utc = data.huaweicloud_asv2_activity_logs.test.scaling_activity_log[0].end_time
113+
114+
start_time_utc_before24h = timeadd(local.start_time_utc, "-24h")
115+
end_time_utc_after24h = timeadd(local.end_time_utc, "24h")
116+
}
117+
118+
# Filter by start_time
119+
data "huaweicloud_asv2_activity_logs" "start_time_filter" {
120+
scaling_group_id = "%[1]s"
121+
start_time = local.start_time_utc_before24h
122+
}
123+
124+
locals {
125+
start_time_filter_result = [
126+
for v in data.huaweicloud_asv2_activity_logs.start_time_filter.scaling_activity_log[*].start_time :
127+
timecmp(local.start_time_utc_before24h, v) == -1
128+
]
129+
}
130+
131+
output "is_start_time_filter_useful" {
132+
value = alltrue(local.start_time_filter_result) && length(local.start_time_filter_result) > 0
133+
}
134+
135+
# Filter by end_time
136+
data "huaweicloud_asv2_activity_logs" "end_time_filter" {
137+
scaling_group_id = "%[1]s"
138+
end_time = local.end_time_utc_after24h
139+
}
140+
141+
locals {
142+
end_time_filter_result = [
143+
for v in data.huaweicloud_asv2_activity_logs.end_time_filter.scaling_activity_log[*].end_time :
144+
timecmp(local.end_time_utc_after24h, v) == 1
145+
]
146+
}
147+
148+
output "is_end_time_filter_useful" {
149+
value = alltrue(local.end_time_filter_result) && length(local.end_time_filter_result) > 0
150+
}
151+
152+
# Filter by start_time and end_time
153+
data "huaweicloud_asv2_activity_logs" "start_end_time_filter" {
154+
scaling_group_id = "%[1]s"
155+
start_time = local.start_time_utc_before24h
156+
end_time = local.end_time_utc_after24h
157+
}
158+
159+
locals {
160+
start_time_filter_result1 = [
161+
for v in data.huaweicloud_asv2_activity_logs.start_end_time_filter.scaling_activity_log[*].start_time :
162+
timecmp(local.start_time_utc_before24h, v) == -1
163+
]
164+
165+
end_time_filter_result1 = [
166+
for v in data.huaweicloud_asv2_activity_logs.start_end_time_filter.scaling_activity_log[*].end_time :
167+
timecmp(local.end_time_utc_after24h, v) == 1
168+
]
169+
}
170+
171+
output "start_time_filter_result1_useful" {
172+
value = alltrue(local.start_time_filter_result1) && length(local.start_time_filter_result1) > 0
173+
}
174+
175+
output "end_time_filter_result1_useful" {
176+
value = alltrue(local.end_time_filter_result1) && length(local.end_time_filter_result1) > 0
177+
}
178+
179+
# Filter by type
180+
locals {
181+
type = data.huaweicloud_asv2_activity_logs.test.scaling_activity_log[0].type
182+
}
183+
184+
data "huaweicloud_asv2_activity_logs" "type_filter" {
185+
scaling_group_id = "%[1]s"
186+
type = local.type
187+
}
188+
189+
locals {
190+
type_filter_result = [
191+
for v in data.huaweicloud_asv2_activity_logs.type_filter.scaling_activity_log[*].type : v == local.type
192+
]
193+
}
194+
195+
output "is_type_filter_useful" {
196+
value = alltrue(local.type_filter_result) && length(local.type_filter_result) > 0
197+
}
198+
199+
# Filter by status
200+
locals {
201+
status = data.huaweicloud_asv2_activity_logs.test.scaling_activity_log[0].status
202+
}
203+
204+
data "huaweicloud_asv2_activity_logs" "status_filter" {
205+
scaling_group_id = "%[1]s"
206+
status = local.status
207+
}
208+
209+
locals {
210+
status_filter_result = [
211+
for v in data.huaweicloud_asv2_activity_logs.status_filter.scaling_activity_log[*].status : v == local.status
212+
]
213+
}
214+
215+
output "is_status_filter_useful" {
216+
value = alltrue(local.status_filter_result) && length(local.status_filter_result) > 0
217+
}
218+
`, acceptance.HW_AS_SCALING_GROUP_ID)
219+
}

0 commit comments

Comments
 (0)