Skip to content

Commit

Permalink
fix(AS): fix AS group resource issues of codes, documents and test ca…
Browse files Browse the repository at this point in the history
…ses. (huaweicloud#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
  • Loading branch information
deer-hang authored Jun 17, 2024
1 parent 07ea879 commit 10adefe
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 212 deletions.
125 changes: 64 additions & 61 deletions docs/resources/as_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,7 @@ resource "huaweicloud_as_group" "my_as_group" {
networks {
id = var.subnet_id
}
}
```

### Autoscaling Group with tags

```hcl
variable "configuration_id" {}
variable "vpc_id" {}
variable "subnet_id" {}
resource "huaweicloud_as_group" "my_as_group_tags" {
scaling_group_name = "my_as_group_tags"
scaling_configuration_id = var.configuration_id
desire_instance_number = 2
min_instance_number = 0
max_instance_number = 10
vpc_id = var.vpc_id
delete_publicip = true
delete_instances = "yes"
networks {
id = var.subnet_id
}
tags = {
foo = "bar"
key = "value"
Expand Down Expand Up @@ -92,23 +70,23 @@ variable "vpc_id" {}
variable "subnet_id" {}
variable "ipv4_subnet_id" {}
resource "huaweicloud_lb_loadbalancer" "loadbalancer_1" {
name = "loadbalancer_1"
resource "huaweicloud_lb_loadbalancer" "test" {
name = "test_name"
vip_subnet_id = var.ipv4_subnet_id
}
resource "huaweicloud_lb_listener" "listener_1" {
name = "listener_1"
resource "huaweicloud_lb_listener" "test" {
name = "test_name"
protocol = "HTTP"
protocol_port = 8080
loadbalancer_id = huaweicloud_lb_loadbalancer.loadbalancer_1.id
loadbalancer_id = huaweicloud_lb_loadbalancer.test.id
}
resource "huaweicloud_lb_pool" "pool_1" {
name = "pool_1"
resource "huaweicloud_lb_pool" "test" {
name = "test_name"
protocol = "HTTP"
lb_method = "ROUND_ROBIN"
listener_id = huaweicloud_lb_listener.listener_1.id
listener_id = huaweicloud_lb_listener.test.id
}
resource "huaweicloud_as_group" "my_as_group_with_enhanced_lb" {
Expand All @@ -123,8 +101,8 @@ resource "huaweicloud_as_group" "my_as_group_with_enhanced_lb" {
id = var.subnet_id
}
lbaas_listeners {
pool_id = huaweicloud_lb_pool.pool_1.id
protocol_port = huaweicloud_lb_listener.listener_1.protocol_port
pool_id = huaweicloud_lb_pool.test.id
protocol_port = huaweicloud_lb_listener.test.protocol_port
}
}
```
Expand All @@ -145,18 +123,19 @@ The following arguments are supported:
* `desire_instance_number` - (Optional, Int) Specifies the expected number of instances. The default value is the
minimum number of instances. The value ranges from the minimum number of instances to the maximum number of instances.

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

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

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

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

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

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

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

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

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

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

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

* `health_periodic_audit_time` - (Optional, Int) Specifies the health check period for instances. The unit is minute
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.
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.

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

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

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

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

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

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

* `delete_publicip` - (Optional, Bool) Specifies whether to delete the elastic IP address bound to the instances of
AS group when deleting the instances. The options are `true` and `false`.
* `delete_publicip` - (Optional, Bool) Specifies whether to release the EIPs bound to ECSs when the ECSs are removed
from the AS group. Defaults to **false**.

+ **true**: The EIPs bound to ECSs will be released when the ECSs are removed. If the EIPs are billed on a
`yearly/monthly` basis, they will not be released when the ECSs are removed.
+ **false**: The EIPs bound to ECSs will be unbound but will not be released when the ECSs are removed.

* `delete_instances` - (Optional, String) Specifies whether to delete the instances in the AS group when deleting
the AS group. The options are `yes` and `no`.
the AS group. The options are **yes** and **no**.

-> If the instances were manually added to an AS group, they are removed from the AS group but are not deleted.

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

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

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

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

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

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

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

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

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

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

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

## Attribute Reference

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

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

```bash
$ terraform import huaweicloud_as_group.test <id>
```
terraform import huaweicloud_as_group.my_as_group 9ec5bea6-a728-4082-8109-5a7dc5c7af74

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
API response, security or some other reason. The missing attributes include: `delete_instances`.
It is generally recommended running `terraform plan` after importing the resource. You can then decide if changes should
be applied to the resource, or the resource definition should be updated to align with the group. Also, you can ignore
changes as below.

```
resource "huaweicloud_as_group" "test" {
...
lifecycle {
ignore_changes = [
delete_instances,
]
}
}
```
Loading

0 comments on commit 10adefe

Please sign in to comment.