Skip to content

Commit 10adefe

Browse files
authored
fix(AS): fix AS group resource issues of codes, documents and test cases. (#5010)
* fix(AS): Remove AS group validation functions * fix(AS): fix AS group resource lint error. * docs(AS): fix AS group resource document * fix(AS): fix AS group resource test cases
1 parent 07ea879 commit 10adefe

File tree

3 files changed

+168
-212
lines changed

3 files changed

+168
-212
lines changed

docs/resources/as_group.md

+64-61
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,7 @@ resource "huaweicloud_as_group" "my_as_group" {
3131
networks {
3232
id = var.subnet_id
3333
}
34-
}
35-
```
36-
37-
### Autoscaling Group with tags
38-
39-
```hcl
40-
variable "configuration_id" {}
41-
variable "vpc_id" {}
42-
variable "subnet_id" {}
4334
44-
resource "huaweicloud_as_group" "my_as_group_tags" {
45-
scaling_group_name = "my_as_group_tags"
46-
scaling_configuration_id = var.configuration_id
47-
desire_instance_number = 2
48-
min_instance_number = 0
49-
max_instance_number = 10
50-
vpc_id = var.vpc_id
51-
delete_publicip = true
52-
delete_instances = "yes"
53-
54-
networks {
55-
id = var.subnet_id
56-
}
5735
tags = {
5836
foo = "bar"
5937
key = "value"
@@ -92,23 +70,23 @@ variable "vpc_id" {}
9270
variable "subnet_id" {}
9371
variable "ipv4_subnet_id" {}
9472
95-
resource "huaweicloud_lb_loadbalancer" "loadbalancer_1" {
96-
name = "loadbalancer_1"
73+
resource "huaweicloud_lb_loadbalancer" "test" {
74+
name = "test_name"
9775
vip_subnet_id = var.ipv4_subnet_id
9876
}
9977
100-
resource "huaweicloud_lb_listener" "listener_1" {
101-
name = "listener_1"
78+
resource "huaweicloud_lb_listener" "test" {
79+
name = "test_name"
10280
protocol = "HTTP"
10381
protocol_port = 8080
104-
loadbalancer_id = huaweicloud_lb_loadbalancer.loadbalancer_1.id
82+
loadbalancer_id = huaweicloud_lb_loadbalancer.test.id
10583
}
10684
107-
resource "huaweicloud_lb_pool" "pool_1" {
108-
name = "pool_1"
85+
resource "huaweicloud_lb_pool" "test" {
86+
name = "test_name"
10987
protocol = "HTTP"
11088
lb_method = "ROUND_ROBIN"
111-
listener_id = huaweicloud_lb_listener.listener_1.id
89+
listener_id = huaweicloud_lb_listener.test.id
11290
}
11391
11492
resource "huaweicloud_as_group" "my_as_group_with_enhanced_lb" {
@@ -123,8 +101,8 @@ resource "huaweicloud_as_group" "my_as_group_with_enhanced_lb" {
123101
id = var.subnet_id
124102
}
125103
lbaas_listeners {
126-
pool_id = huaweicloud_lb_pool.pool_1.id
127-
protocol_port = huaweicloud_lb_listener.listener_1.protocol_port
104+
pool_id = huaweicloud_lb_pool.test.id
105+
protocol_port = huaweicloud_lb_listener.test.protocol_port
128106
}
129107
}
130108
```
@@ -145,18 +123,19 @@ The following arguments are supported:
145123
* `desire_instance_number` - (Optional, Int) Specifies the expected number of instances. The default value is the
146124
minimum number of instances. The value ranges from the minimum number of instances to the maximum number of instances.
147125

148-
* `min_instance_number` - (Optional, Int) Specifies the minimum number of instances. The default value is 0.
126+
* `min_instance_number` - (Optional, Int) Specifies the minimum number of instances. Defaults to **0**.
149127

150-
* `max_instance_number` - (Optional, Int) Specifies the maximum number of instances. The default value is 0.
128+
* `max_instance_number` - (Optional, Int) Specifies the maximum number of instances. The value ranges from **0** to **300**.
129+
Defaults to **0**.
151130

152-
* `cool_down_time` - (Optional, Int) Specifies the cooling duration (in seconds). The value ranges from 0 to 86400,
153-
and is 300 by default.
131+
* `cool_down_time` - (Optional, Int) Specifies the cooling duration (in seconds). The value ranges from **0** to **86,400**.
132+
Defaults to **300**.
154133

155134
* `availability_zones` - (Optional, List) Specifies the availability zones in which to create the instances in the
156-
autoscaling group.
135+
autoscaling group. If this field is not specified, the system will automatically specify one.
157136

158137
* `multi_az_scaling_policy` - (Optional, String) Specifies the priority policy used to select target AZs when adjusting
159-
the number of instances in an AS group. The value can be `EQUILIBRIUM_DISTRIBUTE` and `PICK_FIRST`.
138+
the number of instances in an AS group. The value can be **EQUILIBRIUM_DISTRIBUTE** or **PICK_FIRST**.
160139

161140
+ **EQUILIBRIUM_DISTRIBUTE** (default): When adjusting the number of instances, ensure that instances in each AZ in the
162141
availability_zones list is evenly distributed. If instances cannot be added in the target AZ, select another AZ based
@@ -167,33 +146,34 @@ The following arguments are supported:
167146
* `vpc_id` - (Required, String, ForceNew) Specifies the VPC ID. Changing this creates a new group.
168147

169148
* `networks` - (Required, List) Specifies an array of one or more network IDs. The system supports up to five networks.
170-
The [object](#group_network_object) structure is documented below.
149+
The [networks](#group_network_object) structure is documented below.
171150

172151
* `security_groups` - (Optional, List) Specifies an array of one or more security group IDs to associate with the group.
173-
The [object](#group_security_group_object) structure is documented below.
152+
The [security_groups](#group_security_group_object) structure is documented below.
174153

175154
-> If the security group is specified both in the AS configuration and AS group, scaled ECS instances will be added to
176155
the security group specified in the AS configuration. If the security group is not specified in either of them, scaled
177156
ECS instances will be added to the default security group. For your convenience, you are advised to specify the security
178157
group in the AS configuration.
179158

180159
* `lbaas_listeners` - (Optional, List) Specifies an array of one or more enhanced load balancer. The system supports
181-
the binding of up to six load balancers. The [object](#group_lbaas_listener_object) structure is documented below.
160+
the binding of up to six load balancers. The [lbaas_listeners](#group_lbaas_listener_object) structure is documented below.
182161

183162
* `health_periodic_audit_method` - (Optional, String) Specifies the health check method for instances in the AS group.
184-
The health check methods include `ELB_AUDIT` and `NOVA_AUDIT`. If load balancing is configured, the default value of
185-
this parameter is `ELB_AUDIT`. Otherwise, the default value is `NOVA_AUDIT`.
163+
The health check methods include **ELB_AUDIT** and **NOVA_AUDIT**. If load balancing is configured, the default value of
164+
this parameter is **ELB_AUDIT**. Otherwise, the default value is **NOVA_AUDIT**.
186165

187166
* `health_periodic_audit_time` - (Optional, Int) Specifies the health check period for instances. The unit is minute
188-
and value includes 0, 1, 5 (default), 15, 60, and 180. If the value is set to 0, health check is performed every 10 seconds.
167+
and value includes **0**, **1**, **5** (default), **15**, **60**, and **180**.
168+
If the value is set to **0**, health check is performed every 10 seconds.
189169

190170
* `health_periodic_audit_grace_period` - (Optional, Int) Specifies the health check grace period for instances.
191-
The unit is second and the value ranges from 0 to 86400. The default value is 600.
171+
The unit is second and the value ranges from **0** to **86,400**. Defaults to **600**.
192172

193-
-> This parameter is valid only when the instance health check method of the AS group is `ELB_AUDIT`.
173+
-> This parameter is valid only when the instance health check method of the AS group is **ELB_AUDIT**.
194174

195175
* `instance_terminate_policy` - (Optional, String) Specifies the instance removal policy. The policy has four
196-
options: `OLD_CONFIG_OLD_INSTANCE` (default), `OLD_CONFIG_NEW_INSTANCE`, `OLD_INSTANCE`, and `NEW_INSTANCE`.
176+
options: **OLD_CONFIG_OLD_INSTANCE** (default), **OLD_CONFIG_NEW_INSTANCE**, **OLD_INSTANCE**, and **NEW_INSTANCE**.
197177

198178
+ **OLD_CONFIG_OLD_INSTANCE** (default): The earlier-created instances based on the earlier-created AS configurations
199179
are removed first.
@@ -204,36 +184,41 @@ The following arguments are supported:
204184
* `tags` - (Optional, Map) Specifies the key/value pairs to associate with the AS group.
205185

206186
* `description` - (Optional, String) Specifies the description of the AS group.
207-
The value can contain 0 to 256 characters.
187+
The value can contain `0` to `256` characters.
208188

209189
* `agency_name` - (Optional, String) Specifies the IAM agency name. If you change the agency,
210190
the new agency will be available for ECSs scaled out after the change.
211191

212-
* `delete_publicip` - (Optional, Bool) Specifies whether to delete the elastic IP address bound to the instances of
213-
AS group when deleting the instances. The options are `true` and `false`.
192+
* `delete_publicip` - (Optional, Bool) Specifies whether to release the EIPs bound to ECSs when the ECSs are removed
193+
from the AS group. Defaults to **false**.
194+
195+
+ **true**: The EIPs bound to ECSs will be released when the ECSs are removed. If the EIPs are billed on a
196+
`yearly/monthly` basis, they will not be released when the ECSs are removed.
197+
+ **false**: The EIPs bound to ECSs will be unbound but will not be released when the ECSs are removed.
214198

215199
* `delete_instances` - (Optional, String) Specifies whether to delete the instances in the AS group when deleting
216-
the AS group. The options are `yes` and `no`.
200+
the AS group. The options are **yes** and **no**.
201+
202+
-> If the instances were manually added to an AS group, they are removed from the AS group but are not deleted.
217203

218204
* `force_delete` - (Optional, Bool) Specifies whether to forcibly delete the AS group, remove the ECS instances and
219-
release them. The default value is `false`.
205+
release them. Defaults to **false**.
220206

221-
* `enable` - (Optional, Bool) Specifies whether to enable the AS Group. The options are `true` and `false`.
222-
The default value is `true`.
207+
* `enable` - (Optional, Bool) Specifies whether to enable the AS Group. Defaults to **true**.
223208

224-
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project id of the AS group.
209+
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID of the AS group.
225210

226211
<a name="group_network_object"></a>
227212
The `networks` block supports:
228213

229214
* `id` - (Required, String) Specifies the subnet ID.
230215

231-
* `ipv6_enable` - (Optional, Bool) Specifies whether to support IPv6 addresses. The default value is `false`.
216+
* `ipv6_enable` - (Optional, Bool) Specifies whether to support IPv6 addresses. Defaults to **false**.
232217

233218
* `ipv6_bandwidth_id` - (Optional, String) Specifies the ID of the shared bandwidth of an IPv6 address.
234219

235220
* `source_dest_check` - (Optional, Bool) Specifies whether process only traffic that is destined specifically
236-
for it. Defaults to true.
221+
for it. Defaults to **true**.
237222

238223
<a name="group_security_group_object"></a>
239224
The `security_groups` block supports:
@@ -246,11 +231,11 @@ The `lbaas_listeners` block supports:
246231
* `pool_id` - (Required, String) Specifies the backend ECS group ID.
247232

248233
* `protocol_port` - (Required, Int) Specifies the backend protocol, which is the port on which a backend ECS listens for
249-
traffic. The number of the port ranges from 1 to 65535.
234+
traffic. The number of the port ranges from **1** to **65,535**.
250235

251236
* `weight` - (Optional, Int) Specifies the weight, which determines the portion of requests a backend ECS processes
252-
compared to other backend ECSs added to the same listener. The value of this parameter ranges from 0 to 100. The
253-
default value is 1.
237+
compared to other backend ECSs added to the same listener. The value of this parameter ranges from **0** to **100**.
238+
Defaults to **1**.
254239

255240
## Attribute Reference
256241

@@ -275,6 +260,24 @@ This resource provides the following timeouts configuration options:
275260

276261
AS groups can be imported by their `id`. For example,
277262

263+
```bash
264+
$ terraform import huaweicloud_as_group.test <id>
278265
```
279-
terraform import huaweicloud_as_group.my_as_group 9ec5bea6-a728-4082-8109-5a7dc5c7af74
266+
267+
Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
268+
API response, security or some other reason. The missing attributes include: `delete_instances`.
269+
It is generally recommended running `terraform plan` after importing the resource. You can then decide if changes should
270+
be applied to the resource, or the resource definition should be updated to align with the group. Also, you can ignore
271+
changes as below.
272+
273+
```
274+
resource "huaweicloud_as_group" "test" {
275+
...
276+
277+
lifecycle {
278+
ignore_changes = [
279+
delete_instances,
280+
]
281+
}
282+
}
280283
```

0 commit comments

Comments
 (0)