diff --git a/docs/data-sources/lb_certificate.md b/docs/data-sources/lb_certificate.md new file mode 100644 index 000000000..fe4939303 --- /dev/null +++ b/docs/data-sources/lb_certificate.md @@ -0,0 +1,44 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +--- + +# flexibleengine_lb_certificate_v2 + +Use this data source to get the certificate details in FlexibleEngine Elastic Load Balance (ELB). + +## Example Usage + +The following example shows how one might accept a certificate name as a variable to fetch this data source. + +```hcl +variable "cert_name" {} + +data "flexibleengine_lb_certificate_v2" "by_name" { + name = var.cert_name +} +``` + +## Argument Reference + +The arguments of this data source act as filters for querying the available Certificates in the current region. +The given filters must match exactly one Certificate whose data will be exported as attributes. + +* `id` - (Optional, String) The id of the specific Certificate to retrieve. + +* `name` - (Optional, String) Human-readable name for the Certificate. Does not have to be unique. + +* `description` - (Optional, String) Human-readable description for the LB Certificate. + +* `domain` - (Optional, String) The domain of the Certificate. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `private_key` - The private encrypted key of the Certificate, PEM format. + +* `certificate` - The public encrypted key of the Certificate, PEM format. + +* `update_time` - Indicates the update time. + +* `create_time` - Indicates the creation time. diff --git a/docs/data-sources/lb_certificate_v2.md b/docs/data-sources/lb_certificate_v2.md index 405c99759..b898bc631 100644 --- a/docs/data-sources/lb_certificate_v2.md +++ b/docs/data-sources/lb_certificate_v2.md @@ -1,5 +1,7 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" +description: "" +page_title: "flexibleengine_lb_certificate_v2" --- # flexibleengine_lb_certificate_v2 diff --git a/docs/data-sources/lb_listeners.md b/docs/data-sources/lb_listeners.md new file mode 100644 index 000000000..9dfb8715e --- /dev/null +++ b/docs/data-sources/lb_listeners.md @@ -0,0 +1,72 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +--- + +# flexibleengine_lb_listeners_v2 + +Use this data source to query the list of ELB listeners. + +## Example Usage + +```hcl +variable "protocol" {} + +data "flexibleengine_lb_listeners_v2" "test" { + protocol = var.protocol +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String) Specifies the region in which to query the data source. + If omitted, the provider-level region will be used. + +* `name` - (Optional, String) The listener name. + +* `protocol` - (Optional, String) The listener protocol. + The valid values are **TCP**, **UDP**, **HTTP** and **TERMINATED_HTTPS**. + +* `protocol_port` - (Optional, String) The front-end listening port of the listener. + The valid value is range from `1` to `65535`. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The resource ID. + +* `listeners` - Listener list. +The [listeners](#listeners_listeners) structure is documented below. + + +The `listeners` block supports: + +* `id` - The ELB listener ID. + +* `name` - The listener name. + +* `protocol` - The listener protocol. + +* `protocol_port` - The front-end listening port of the listener. + +* `default_pool_id` - The ID of the default pool with which the ELB listener is associated. + +* `description` - The description of the ELB listener. + +* `connection_limit` - The maximum number of connections allowed for the listener. + +* `http2_enable` - Whether the ELB listener uses HTTP/2. + +* `default_tls_container_ref` - The ID of the server certificate used by the listener. + +* `sni_container_refs` - List of the SNI certificate (server certificates with a domain name) IDs used by the listener. + +* `loadbalancers` - Listener list. +The [loadbalancers](#listeners_loadbalancers) structure is documented below. + + +The `loadbalancers` block supports: + +* `id` - The ELB loadbalancer ID. diff --git a/docs/data-sources/lb_listeners_v2.md b/docs/data-sources/lb_listeners_v2.md index 9dfb8715e..093e22920 100644 --- a/docs/data-sources/lb_listeners_v2.md +++ b/docs/data-sources/lb_listeners_v2.md @@ -1,5 +1,7 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" +description: "" +page_title: "flexibleengine_lb_listeners_v2" --- # flexibleengine_lb_listeners_v2 diff --git a/docs/data-sources/lb_loadbalancer.md b/docs/data-sources/lb_loadbalancer.md new file mode 100644 index 000000000..a048805e5 --- /dev/null +++ b/docs/data-sources/lb_loadbalancer.md @@ -0,0 +1,47 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +--- + +# flexibleengine_lb_loadbalancer + +Use this data source to get a specific elb loadbalancer within FlexibleEngine. + +## Example Usage + +```hcl +variable "lb_name" {} + +data "flexibleengine_lb_loadbalancer" "test" { + name = var.lb_name +} +``` + +## Argument Reference + +* `region` - (Optional, String) Specifies the region in which to obtain the load balancer. If omitted, the + provider-level region will be used. + +* `name` - (Optional, String) Specifies the name of the load balancer. + +* `id` - (Optional, String) Specifies the data source ID of the load balancer in UUID format. + +* `status` - (Optional, String) Specifies the operating status of the load balancer. Valid values are *ONLINE* and + *FROZEN*. + +* `description` - (Optional, String) Specifies the supplementary information about the load balancer. + +* `vip_address` - (Optional, String) Specifies the private IP address of the load balancer. + +* `vip_subnet_id` - (Optional, String) Specifies the **IPv4 subnet ID** of the subnet where the load balancer works. + +* `enterprise_project_id` - (Optional, String) Specifies the enterprise project id of the load balancer. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `tags` - The tags associated with the load balancer. + +* `vip_port_id` - The ID of the port bound to the private IP address of the load balancer. + +* `public_ip` - The EIP address that is associated to the Load Balancer instance. diff --git a/docs/data-sources/lb_loadbalancer_v2.md b/docs/data-sources/lb_loadbalancer_v2.md index e08382caa..409f57484 100644 --- a/docs/data-sources/lb_loadbalancer_v2.md +++ b/docs/data-sources/lb_loadbalancer_v2.md @@ -1,5 +1,7 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" +description: "" +page_title: "flexibleengine_lb_loadbalancer_v2" --- # flexibleengine_lb_loadbalancer_v2 diff --git a/docs/resources/as_group.md b/docs/resources/as_group.md index 4a981d651..0c3e1ce4b 100644 --- a/docs/resources/as_group.md +++ b/docs/resources/as_group.md @@ -93,14 +93,14 @@ resource "flexibleengine_vpc_subnet_v1" "example_subnet" { vpc_id = flexibleengine_vpc_v1.example_vpc.id } -resource "flexibleengine_lb_loadbalancer_v2" "lb_1" { +resource "flexibleengine_lb_loadbalancer" "lb_1" { vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.lb_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.lb_1.id } resource "flexibleengine_as_group" "my_as_group_with_elb" { @@ -108,7 +108,7 @@ resource "flexibleengine_as_group" "my_as_group_with_elb" { desire_instance_number = 2 min_instance_number = 0 max_instance_number = 10 - lb_listener_id = flexibleengine_lb_listener_v2.listener_1.id + lb_listener_id = flexibleengine_lb_listener.listener_1.id scaling_configuration_id = "37e310f5-db9d-446e-9135-c625f9c2bbfc" vpc_id = flexibleengine_vpc_v1.example_vpc.id delete_publicip = true diff --git a/docs/resources/lb_l7policy.md b/docs/resources/lb_l7policy.md new file mode 100644 index 000000000..a6ee2d472 --- /dev/null +++ b/docs/resources/lb_l7policy.md @@ -0,0 +1,90 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_l7policy" +--- + +# flexibleengine_lb_l7policy + +Manages an **enhanced** load balancer L7 Policy resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "loadbalancer_1" + vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_l7policy" "l7policy_1" { + name = "test" + action = "REDIRECT_TO_POOL" + description = "test l7 policy" + position = 1 + listener_id = flexibleengine_lb_listener.listener_1.id + redirect_pool_id = flexibleengine_lb_pool.pool_1.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to obtain the V2 Networking client. + A Networking client is needed to create an . If omitted, the + `region` argument of the provider is used. Changing this creates a new L7 Policy. + +* `name` - (Optional, String) Human-readable name for the L7 Policy. Does not have to be unique. + +* `description` - (Optional, String) Human-readable description for the L7 Policy. + +* `action` - (Required, String, ForceNew) The L7 Policy action - can either be REDIRECT_TO_POOL, + or REDIRECT_TO_LISTENER. Changing this creates a new L7 Policy. + +* `listener_id` - (Required, String, ForceNew) The Listener on which the L7 Policy will be associated with. + Changing this creates a new L7 Policy. + +* `position` - (Optional, Int, ForceNew) The position of this policy on the listener. Positions start at 1. + Changing this creates a new L7 Policy. + +* `redirect_pool_id` - (Optional, String) Requests matching this policy will be redirected to + the pool with this ID. Only valid if action is REDIRECT_TO_POOL. + +* `redirect_listener_id` - (Optional, String) Requests matching this policy will be redirected to + the listener with this ID. Only valid if action is REDIRECT_TO_LISTENER. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the L7 policy. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +Load Balancer L7 Policy can be imported using the L7 Policy ID, e.g.: + +```shell +terraform import flexibleengine_lb_l7policy.l7policy_1 8a7a79c2-cf17-4e65-b2ae-ddc8bfcf6c74 +``` diff --git a/docs/resources/lb_l7policy_v2.md b/docs/resources/lb_l7policy_v2.md index f266aa196..07967b45a 100644 --- a/docs/resources/lb_l7policy_v2.md +++ b/docs/resources/lb_l7policy_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_l7policy_v2" --- diff --git a/docs/resources/lb_l7rule.md b/docs/resources/lb_l7rule.md new file mode 100644 index 000000000..513bd4096 --- /dev/null +++ b/docs/resources/lb_l7rule.md @@ -0,0 +1,94 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_l7rule" +--- + +# flexibleengine_lb_l7rule + +Manages an **enhanced** load balancer L7 Rule resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "loadbalancer_1" + vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "pool_1" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_l7policy" "l7policy_1" { + name = "test" + action = "REDIRECT_TO_POOL" + description = "test l7 policy" + position = 1 + listener_id = flexibleengine_lb_listener.listener_1.id + redirect_pool_id = flexibleengine_lb_pool.pool_1.id +} + +resource "flexibleengine_lb_l7rule" "l7rule_1" { + l7policy_id = flexibleengine_lb_l7policy.l7policy_1.id + type = "PATH" + compare_type = "EQUAL_TO" + value = "/api" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to obtain the V2 Networking client. + A Networking client is needed to create an . If omitted, the + `region` argument of the provider is used. Changing this creates a new L7 Rule. + +* `type` - (Required, String, ForceNew) The L7 Rule type - can either be HOST_NAME or PATH. + Changing this creates a new L7 Rule. + +* `compare_type` - (Required, String) The comparison type for the L7 rule - can either be + STARTS_WITH, EQUAL_TO or REGEX + +* `l7policy_id` - (Required, String, ForceNew) The ID of the L7 Policy to query. Changing this creates a new L7 Rule. + +* `value` - (Required, String) The value to use for the comparison. For example, the file type to compare. + +* `key` - (Optional, String, ForceNew) The key to use for the comparison. For example, the name of the cookie to + evaluate. Valid when `type` is set to COOKIE or HEADER. Changing this creates a new L7 Rule. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the L7 Rule. + +* `listener_id` - The ID of the Listener owning this resource. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +Load Balancer L7 Rule can be imported using the L7 Policy ID and L7 Rule ID +separated by a slash, e.g.: + +```shell +terraform import flexibleengine_lb_l7rule.l7rule_1 e0bd694a-abbe-450e-b329-0931fd1cc5eb/4086b0c9-b18c-4d1c-b6b8-4c56c3ad2a9e +``` diff --git a/docs/resources/lb_l7rule_v2.md b/docs/resources/lb_l7rule_v2.md index 94ae56258..e34e74114 100644 --- a/docs/resources/lb_l7rule_v2.md +++ b/docs/resources/lb_l7rule_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_l7rule_v2" --- diff --git a/docs/resources/lb_listener.md b/docs/resources/lb_listener.md new file mode 100644 index 000000000..982786fb5 --- /dev/null +++ b/docs/resources/lb_listener.md @@ -0,0 +1,209 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_listener" +--- + +# flexibleengine_lb_listener + +Manages an **enhanced** lb listener resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_loadbalancer" "lb_1" { + vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id + + tags = { + key = "value" + } +} + +resource "flexibleengine_lb_listener" "listener_1" { + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.lb_1.id + + tags = { + key = "value" + } +} +``` + +## Example Usage of TERMINATED_HTTPS protocol + +```hcl +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "loadbalancer_cert" + vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id +} + +resource "flexibleengine_elb_certificate" "certificate_1" { + name = "cert" + domain = "www.elb.com" + private_key = < +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the listener resource. + If omitted, the `region` argument of the provider is used. Changing this creates a new listener. + +* `loadbalancer_id` - (Required, String, ForceNew) The load balancer on which to provision this + listener. Changing this creates a new listener. + +* `protocol` - (Required, String, ForceNew) The protocol - can either be TCP, UDP, HTTP or TERMINATED_HTTPS. + Changing this creates a new listener. + +* `protocol_port` - (Required, Int, ForceNew) The port on which to listen for client traffic. + Changing this creates a new listener. + +* `default_pool_id` - (Optional, String, ForceNew) The ID of the default pool with which the + listener is associated. Changing this creates a new listener. + +* `name` - (Optional, String) Human-readable name for the listener. Does not have to be unique. + +* `description` - (Optional, String) Human-readable description for the listener. + +* `tags` - (Optional, Map) The key/value pairs to associate with the listener. + +* `http2_enable` - (Optional, Bool) Specifies whether to use HTTP/2. The default value is false. + This parameter is valid only when the protocol is set to *TERMINATED_HTTPS*. + +* `transparent_client_ip_enable` - (Optional, Bool) Specifies whether to pass source IP addresses of the clients to + backend servers. + + For TCP and UDP listeners, the value can be true or false, and the default value is false. + + For HTTP and HTTPS listeners, the value can only be true. + +* `idle_timeout` - (Optional, Int) Specifies the idle timeout duration, in seconds. + + For TCP listeners, the value ranges from 10 to 4000, and the default value is 300. + + For HTTP and HTTPS listeners, the value ranges from 1 to 300, and the default value is 60. + + For UDP listeners, this parameter does not take effect. + +* `request_timeout` - (Optional, Int) Specifies the timeout duration for waiting for a request from a client, + in seconds. This parameter is available only for HTTP and HTTPS listeners. The value ranges from 1 to 300, + and the default value is 60. + +* `response_timeout` - (Optional, Int) Specifies the timeout duration for waiting for a request from a backend + server, in seconds. This parameter is available only for HTTP and HTTPS listeners. The value ranges from 1 to 300, + and the default value is 60. + +* `default_tls_container_ref` - (Optional, String) A reference to a Barbican Secrets + container which stores TLS information. This is required if the protocol is `TERMINATED_HTTPS`. See + [here](https://wiki.openstack.org/wiki/Network/LBaaS/docs/how-to-create-tls-loadbalancer) + for more information. + +* `sni_container_refs` - (Optional, List) A list of references to Barbican Secrets + containers which store SNI information. See + [here](https://wiki.openstack.org/wiki/Network/LBaaS/docs/how-to-create-tls-loadbalancer) + for more information. + +* `tls_ciphers_policy` - (Optional, String) Specifies the security policy used by the listener. + This parameter is valid only when the load balancer protocol is set to TERMINATED_HTTPS. + The value can be tls-1-0, tls-1-1, tls-1-2, or tls-1-2-strict, and the default value is tls-1-0. + For details of cipher suites for each security policy, see the table below. + + + + + + + + + + + + + + + + + + + + + + + + + +
Security PolicyTLS VersionCipher Suite
tls-1-0TLSv1.2 TLSv1.1 TLSv1ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:AES128-SHA256:AES256-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-SHA:AES256-SHA
tls-1-1TLSv1.2 TLSv1.1
tls-1-2TLSv1.2
tls-1-2-strictTLSv1.2ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:AES128-SHA256:AES256-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384
+ +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the listener. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. diff --git a/docs/resources/lb_listener_v2.md b/docs/resources/lb_listener_v2.md index 05d71054e..cd4d1798c 100644 --- a/docs/resources/lb_listener_v2.md +++ b/docs/resources/lb_listener_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_listener_v2" --- diff --git a/docs/resources/lb_loadbalancer.md b/docs/resources/lb_loadbalancer.md new file mode 100644 index 000000000..26790e3dd --- /dev/null +++ b/docs/resources/lb_loadbalancer.md @@ -0,0 +1,72 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_loadbalancer" +--- + +# flexibleengine_lb_loadbalancer + +Manages an **enhanced** load balancer resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_loadbalancer" "lb_1" { + vip_subnet_id = flexibleengine_vpc_subnet_v1.example_subnet.ipv4_subnet_id + + tags = { + key = "value" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the loadbalancer resource. + If omitted, the `region` argument of the provider is used. Changing this creates a new loadbalancer. + +* `vip_subnet_id` - (Required, String, ForceNew) The `ipv4_subnet_id` or `ipv6_subnet_id` of the + VPC Subnet on which to allocate the loadbalancer's address. + A tenant can only create Loadbalancers on networks authorized + by policy (e.g. networks that belong to them or networks that + are shared). Changing this creates a new loadbalancer. + +* `name` - (Optional, String) Human-readable name for the loadbalancer. Does not have to be unique. + +* `description` - (Optional, String) Human-readable description for the loadbalancer. + +* `vip_address` - (Optional, String, ForceNew) The ip address of the load balancer. + Changing this creates a new loadbalancer. + +* `tags` - (Optional, Map) The key/value pairs to associate with the loadbalancer. + +* `loadbalancer_provider` - (Optional, String, ForceNew) The name of the provider. Currently, only + vlb is supported. Changing this creates a new loadbalancer. + +* `security_group_ids` - (Optional, List) A list of security group IDs to apply to the + loadbalancer. The security groups must be specified by ID and not name (as + opposed to how they are configured with the Compute Instance). + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `vip_port_id` - The Port ID of the Load Balancer IP. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 5 minutes. + +## Import + +Loadbalancers can be imported using the `id`, e.g. + +```shell +terraform import flexibleengine_lb_loadbalancer.loadbalancer_1 3e3632db-36c6-4b28-a92e-e72e6562daa6 +``` diff --git a/docs/resources/lb_loadbalancer_v2.md b/docs/resources/lb_loadbalancer_v2.md index f3e82c367..370b0a712 100644 --- a/docs/resources/lb_loadbalancer_v2.md +++ b/docs/resources/lb_loadbalancer_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_loadbalancer_v2" --- diff --git a/docs/resources/lb_member.md b/docs/resources/lb_member.md new file mode 100644 index 000000000..dcd1a4a91 --- /dev/null +++ b/docs/resources/lb_member.md @@ -0,0 +1,70 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_member" +--- + +# flexibleengine_lb_member + +Manages an **enhanced** load balancer member resource within FlexibleEngine. + +## Example Usage + +```hcl +variable "lb_pool_id" {} +variable "ipv4_subnet_id" {} + +resource "flexibleengine_lb_member" "member_1" { + address = "192.168.199.23" + protocol_port = 8080 + pool_id = var.lb_pool_id + subnet_id = var.ipv4_subnet_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the ELB member resource. If omitted, the + provider-level region will be used. Changing this creates a new member. + +* `pool_id` - (Required, String, ForceNew) The id of the pool that this member will be assigned to. + Changing this creates a new member. + +* `subnet_id` - (Required, String, ForceNew) The **IPv4 subnet ID** of the subnet in which to access the member. + Changing this creates a new member. + +* `name` - (Optional, String) Human-readable name for the member. + +* `address` - (Required, String, ForceNew) The IP address of the member to receive traffic from the load balancer. + Changing this creates a new member. + +* `protocol_port` - (Required, Int, ForceNew) The port on which to listen for client traffic. Changing this creates a + new member. + +* `weight` - (Optional, Int) A positive integer value that indicates the relative portion of traffic that this member + should receive from the pool. For example, a member with a weight of 10 receives five times as much traffic as a + member with a weight of 2. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the member. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +ELB member can be imported using the pool ID and member ID separated by a slash, e.g. + +```shell +terraform import flexibleengine_lb_member.member_1 e0bd694a-abbe-450e-b329-0931fd1cc5eb/4086b0c9-b18c-4d1c-b6b8-4c56c3ad2a9e +``` diff --git a/docs/resources/lb_member_v2.md b/docs/resources/lb_member_v2.md index 1cc77f807..f4e5dd811 100644 --- a/docs/resources/lb_member_v2.md +++ b/docs/resources/lb_member_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_member_v2" --- diff --git a/docs/resources/lb_monitor.md b/docs/resources/lb_monitor.md new file mode 100644 index 000000000..965790351 --- /dev/null +++ b/docs/resources/lb_monitor.md @@ -0,0 +1,111 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_monitor" +--- + +# flexibleengine_lb_monitor + +Manages an **enhanced** load balancer monitor resource within FlexibleEngine. + +## Example Usage + +### TCP Health Check + +```hcl +resource "flexibleengine_lb_monitor" "monitor_tcp" { + pool_id = var.pool_id + type = "TCP" + delay = 5 + timeout = 3 + max_retries = 3 +} +``` + +### UDP Health Check + +```hcl +resource "flexibleengine_lb_monitor" "monitor_udp" { + pool_id = var.pool_id + type = "UDP_CONNECT" + delay = 5 + timeout = 3 + max_retries = 3 +} +``` + +### HTTP Health Check + +```hcl +resource "flexibleengine_lb_monitor" "monitor_http" { + pool_id = var.pool_id + type = "HTTP" + delay = 5 + timeout = 3 + max_retries = 3 + url_path = "/test" + expected_codes = "200-202" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the ELB monitor resource. If omitted, the + provider-level region will be used. Changing this creates a new monitor. + +* `pool_id` - (Required, String, ForceNew) Specifies the id of the pool that this monitor will be assigned to. Changing + this creates a new monitor. + +* `type` - (Required, String, ForceNew) Specifies the monitor protocol. + The value can be *TCP*, *UDP_CONNECT*, or *HTTP*. + If the listener protocol is UDP, the monitor protocol must be *UDP_CONNECT*. Changing this creates a new monitor. + +* `delay` - (Required, Int) Specifies the maximum time between health checks in the unit of second. The value ranges + from 1 to 50. + +* `timeout` - (Required, Int) Specifies the health check timeout duration in the unit of second. + The value ranges from 1 to 50 and must be less than the `delay` value. + +* `max_retries` - (Required, Int) Specifies the maximum number of consecutive health checks after which the backend + servers are declared *healthy*. The value ranges from 1 to 10. + + -> Backend servers can be declared *unhealthy* after **three** consecutive health checks that detect these backend + servers are unhealthy, regardless of the value set for `max_retries`. + +* `name` - (Optional, String) Specifies the health check name. The value contains a maximum of 255 characters. + +* `port` - (Optional, Int) Specifies the health check port. The port number ranges from 1 to 65535. If not specified, + the port of the backend server will be used as the health check port. + +* `url_path` - (Optional, String) Specifies the HTTP request path for the health check. Required for HTTP type. + The value starts with a slash (/) and contains a maximum of 255 characters. + +* `http_method` - (Optional, String) Specifies the HTTP request method. Required for HTTP type. + The default value is *GET*. + +* `expected_codes` - (Optional, String) Specifies the expected HTTP status code. Required for HTTP type. + You can either specify a single status like "200", or a range like "200-202". + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the monitor. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +ELB monitor can be imported using the monitor ID, e.g. + +```shell +terraform import flexibleengine_lb_monitor.monitor_1 5c20fdad-7288-11eb-b817-0255ac10158b +``` diff --git a/docs/resources/lb_monitor_v2.md b/docs/resources/lb_monitor_v2.md index fbf122496..fb3e94f96 100644 --- a/docs/resources/lb_monitor_v2.md +++ b/docs/resources/lb_monitor_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_monitor_v2" --- diff --git a/docs/resources/lb_pool.md b/docs/resources/lb_pool.md new file mode 100644 index 000000000..aaa6c184e --- /dev/null +++ b/docs/resources/lb_pool.md @@ -0,0 +1,98 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_pool" +--- + +# flexibleengine_lb_pool + +Manages an **enhanced** load balancer pool resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_pool" "pool_1" { + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = "d9415786-5f1a-428b-b35f-2f1523e146d2" + + persistence { + type = "HTTP_COOKIE" + cookie_name = "testCookie" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource. + If omitted, the `region` argument of the provider is used. Changing this creates a new pool. + +* `protocol` - (Required, String, ForceNew) The protocol - can either be TCP, UDP or HTTP. + + + When the protocol used by the listener is UDP, the protocol of the backend pool must be UDP. + + When the protocol used by the listener is TCP, the protocol of the backend pool must be TCP. + + When the protocol used by the listener is HTTP or TERMINATED_HTTPS, the protocol of the backend pool must be HTTP. + + Changing this creates a new pool. + +* `lb_method` - (Required, String) The load balancing algorithm to + distribute traffic to the pool's members. Must be one of + ROUND_ROBIN, LEAST_CONNECTIONS, or SOURCE_IP. + +* `name` - (Optional, String) Human-readable name for the pool. + +* `description` - (Optional, String) Human-readable description for the pool. + +* `loadbalancer_id` - (Optional, String, ForceNew) The load balancer on which to provision this + pool. Changing this creates a new pool. + Note: One of LoadbalancerID or ListenerID must be provided. + +* `listener_id` - (Optional, String, ForceNew) The Listener on which the members of the pool + will be associated with. Changing this creates a new pool. + Note: One of LoadbalancerID or ListenerID must be provided. + +* `persistence` - (Optional, List, ForceNew) Omit this field to prevent session persistence. Indicates + whether connections in the same session will be processed by the same Pool member or not. + The [persistence](#lb_persistence) object structure is documented below. + Changing this creates a new pool. + + +The `persistence` block supports: + +* `type` - (Required, String, ForceNew) The type of persistence mode. The current specification + supports SOURCE_IP, HTTP_COOKIE, and APP_COOKIE. Changing this will create a new resource. + +* `cookie_name` - (Optional, String, ForceNew) The name of the cookie if persistence mode is set + appropriately. It is Required if `type = APP_COOKIE`. Changing this will create a new resource. + +* `timeout` - (Optional, Int, ForceNew) Specifies the sticky session timeout duration in minutes. This parameter is + invalid when type is set to APP_COOKIE. Changing this will create a new resource. + The value range varies depending on the protocol of the backend server group: + + + When the protocol of the backend server group is TCP or UDP, the value ranges from 1 to 60. + + When the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the pool. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +ELB pool can be imported using the ELB pool ID, e.g. + +```shell +terraform import flexibleengine_lb_pool.pool_1 3e3632db-36c6-4b28-a92e-e72e6562daa6 +``` diff --git a/docs/resources/lb_pool_v2.md b/docs/resources/lb_pool_v2.md index 2fa0b736b..cc4222814 100644 --- a/docs/resources/lb_pool_v2.md +++ b/docs/resources/lb_pool_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_pool_v2" --- diff --git a/docs/resources/lb_whitelist.md b/docs/resources/lb_whitelist.md new file mode 100644 index 000000000..0ce4622db --- /dev/null +++ b/docs/resources/lb_whitelist.md @@ -0,0 +1,63 @@ +--- +subcategory: "Elastic Load Balance (ELB)" +description: "" +page_title: "flexibleengine_lb_whitelist" +--- + +# flexibleengine_lb_whitelist + +Manages an **enhanced** load balancer whitelist resource within FlexibleEngine. + +## Example Usage + +```hcl +resource "flexibleengine_lb_listener" "listener_1" { + name = "listener_1" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = var.loadbalancer_id +} + +resource "flexibleengine_lb_whitelist" "whitelist_1" { + enable_whitelist = true + whitelist = "192.168.11.1,192.168.0.1/24,192.168.201.18/8" + listener_id = flexibleengine_lb_listener.listener_1.id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the ELB whitelist resource. If omitted, the + provider-level region will be used. Changing this creates a new whitelist. + +* `listener_id` - (Required, String, ForceNew) The Listener ID that the whitelist will be associated with. Changing this + creates a new whitelist. + +* `enable_whitelist` - (Optional, Bool) Specify whether to enable access control. + +* `whitelist` - (Optional, String) Specifies the IP addresses in the whitelist. Use commas(,) to separate the multiple + IP addresses. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The unique ID for the whitelist. + +## Timeouts + +This resource provides the following timeouts configuration options: + +* `create` - Default is 10 minutes. +* `update` - Default is 10 minutes. +* `delete` - Default is 10 minutes. + +## Import + +ELB whitelist can be imported using the whitelist ID, e.g. + +```shell +terraform import flexibleengine_lb_whitelist.whitelist_1 5c20fdad-7288-11eb-b817-0255ac10158b +``` diff --git a/docs/resources/lb_whitelist_v2.md b/docs/resources/lb_whitelist_v2.md index b54749573..bcd7646dd 100644 --- a/docs/resources/lb_whitelist_v2.md +++ b/docs/resources/lb_whitelist_v2.md @@ -1,5 +1,5 @@ --- -subcategory: "Elastic Load Balance (ELB)" +subcategory: "Deprecated" description: "" page_title: "flexibleengine_lb_whitelist_v2" --- diff --git a/examples/antiddos.tf b/examples/antiddos.tf index 506a886f0..ae19ae87e 100644 --- a/examples/antiddos.tf +++ b/examples/antiddos.tf @@ -12,7 +12,7 @@ resource "flexibleengine_vpc_eip" "eip_1" { resource "flexibleengine_vpc_eip_associate" "associated" { public_ip = flexibleengine_vpc_eip.eip_1.address - fixed_ip = flexibleengine_lb_loadbalancer_v2.loadbalancer.vip_address + fixed_ip = flexibleengine_lb_loadbalancer.loadbalancer.vip_address network_id = flexibleengine_vpc_subnet_v1.subnet.id } diff --git a/examples/loadbalancer.tf b/examples/loadbalancer.tf index 55e55f579..ecf35e3e3 100755 --- a/examples/loadbalancer.tf +++ b/examples/loadbalancer.tf @@ -1,33 +1,33 @@ -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer" { name = "${var.project}-loadbalancer" vip_subnet_id = flexibleengine_vpc_subnet_v1.subnet.ipv4_subnet_id admin_state_up = "true" depends_on = [flexibleengine_vpc_subnet_v1.subnet] } -resource "flexibleengine_lb_listener_v2" "listener" { +resource "flexibleengine_lb_listener" "listener" { name = "${var.project}-listener" protocol = "HTTP" protocol_port = 80 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer.id } -resource "flexibleengine_lb_pool_v2" "pool" { +resource "flexibleengine_lb_pool" "pool" { protocol = "HTTP" lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener.id + listener_id = flexibleengine_lb_listener.listener.id } -resource "flexibleengine_lb_member_v2" "member" { +resource "flexibleengine_lb_member" "member" { count = var.instance_count address = element(flexibleengine_compute_instance_v2.webserver.*.access_ip_v4, count.index) - pool_id = flexibleengine_lb_pool_v2.pool.id + pool_id = flexibleengine_lb_pool.pool.id subnet_id = flexibleengine_vpc_subnet_v1.subnet.ipv4_subnet_id protocol_port = 80 } -resource "flexibleengine_lb_monitor_v2" "monitor" { - pool_id = flexibleengine_lb_pool_v2.pool.id +resource "flexibleengine_lb_monitor" "monitor" { + pool_id = flexibleengine_lb_pool.pool.id type = "HTTP" url_path = "/" expected_codes = "200" diff --git a/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go b/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go index d3fe909e3..f3c5bff3e 100644 --- a/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go +++ b/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go @@ -12,9 +12,9 @@ import ( func TestAccDatasourceListeners_basic(t *testing.T) { var ( rName = acceptance.RandomAccResourceNameWithDash() - dcByName = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners_v2.by_name") - dcByProtocol = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners_v2.by_protocol") - dcByProtocolPort = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners_v2.by_protocol_port") + dcByName = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners.by_name") + dcByProtocol = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners.by_protocol") + dcByProtocolPort = acceptance.InitDataSourceCheck("data.flexibleengine_lb_listeners.by_protocol_port") ) resource.ParallelTest(t, resource.TestCase{ @@ -26,17 +26,17 @@ func TestAccDatasourceListeners_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( dcByName.CheckResourceExists(), resource.TestCheckOutput("name_query_result_validation", "true"), - resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners.by_name", "listeners.0.name"), - resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners.by_name", "listeners.0.protocol"), - resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners.by_name", "listeners.0.protocol_port"), - resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners.by_name", "listeners.0.connection_limit"), - resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners.by_name", "listeners.0.http2_enable"), - resource.TestCheckResourceAttr("data.flexibleengine_lb_listeners_v2.by_name", + resource.TestCheckResourceAttr("data.flexibleengine_lb_listeners.by_name", "listeners.0.loadbalancers.#", "1"), dcByProtocol.CheckResourceExists(), resource.TestCheckOutput("protocol_query_result_validation", "true"), @@ -76,15 +76,15 @@ resource "flexibleengine_vpc_subnet_v1" "test" { gateway_ip = cidrhost(cidrsubnet(flexibleengine_vpc_v1.test.cidr, 4, 1), 1) } -resource "flexibleengine_lb_loadbalancer_v2" "test" { +resource "flexibleengine_lb_loadbalancer" "test" { name = "%[1]s" vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id } -resource "flexibleengine_lb_listener_v2" "test" { +resource "flexibleengine_lb_listener" "test" { count = length(var.listener_configuration) - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.test.id + loadbalancer_id = flexibleengine_lb_loadbalancer.test.id name = "%[1]s-${count.index}" protocol = var.listener_configuration[count.index]["protocol"] @@ -97,43 +97,43 @@ func testAccDatasourceListeners_basic(rName string) string { return fmt.Sprintf(` %s -data "flexibleengine_lb_listeners_v2" "by_name" { - depends_on = [flexibleengine_lb_listener_v2.test] +data "flexibleengine_lb_listeners" "by_name" { + depends_on = [flexibleengine_lb_listener.test] - name = flexibleengine_lb_listener_v2.test[0].name + name = flexibleengine_lb_listener.test[0].name } -data "flexibleengine_lb_listeners_v2" "by_protocol" { - depends_on = [flexibleengine_lb_listener_v2.test] +data "flexibleengine_lb_listeners" "by_protocol" { + depends_on = [flexibleengine_lb_listener.test] - protocol = flexibleengine_lb_listener_v2.test[1].protocol + protocol = flexibleengine_lb_listener.test[1].protocol } -data "flexibleengine_lb_listeners_v2" "by_protocol_port" { - depends_on = [flexibleengine_lb_listener_v2.test] +data "flexibleengine_lb_listeners" "by_protocol_port" { + depends_on = [flexibleengine_lb_listener.test] - protocol_port = flexibleengine_lb_listener_v2.test[2].protocol_port + protocol_port = flexibleengine_lb_listener.test[2].protocol_port } output "name_query_result_validation" { - value = contains(data.flexibleengine_lb_listeners_v2.by_name.listeners[*].id, - flexibleengine_lb_listener_v2.test[0].id) && !contains(data.flexibleengine_lb_listeners_v2.by_name.listeners[*].id, - flexibleengine_lb_listener_v2.test[1].id) && !contains(data.flexibleengine_lb_listeners_v2.by_name.listeners[*].id, - flexibleengine_lb_listener_v2.test[2].id) + value = contains(data.flexibleengine_lb_listeners.by_name.listeners[*].id, + flexibleengine_lb_listener.test[0].id) && !contains(data.flexibleengine_lb_listeners.by_name.listeners[*].id, + flexibleengine_lb_listener.test[1].id) && !contains(data.flexibleengine_lb_listeners.by_name.listeners[*].id, + flexibleengine_lb_listener.test[2].id) } output "protocol_query_result_validation" { - value = contains(data.flexibleengine_lb_listeners_v2.by_protocol.listeners[*].id, - flexibleengine_lb_listener_v2.test[1].id) && !contains(data.flexibleengine_lb_listeners_v2.by_protocol.listeners[*].id, - flexibleengine_lb_listener_v2.test[0].id) && !contains(data.flexibleengine_lb_listeners_v2.by_protocol.listeners[*].id, - flexibleengine_lb_listener_v2.test[2].id) + value = contains(data.flexibleengine_lb_listeners.by_protocol.listeners[*].id, + flexibleengine_lb_listener.test[1].id) && !contains(data.flexibleengine_lb_listeners.by_protocol.listeners[*].id, + flexibleengine_lb_listener.test[0].id) && !contains(data.flexibleengine_lb_listeners.by_protocol.listeners[*].id, + flexibleengine_lb_listener.test[2].id) } output "protocol_port_query_result_validation" { - value = contains(data.flexibleengine_lb_listeners_v2.by_protocol_port.listeners[*].id, - flexibleengine_lb_listener_v2.test[2].id) && !contains(data.flexibleengine_lb_listeners_v2.by_protocol_port.listeners[*].id, - flexibleengine_lb_listener_v2.test[0].id) && !contains(data.flexibleengine_lb_listeners_v2.by_protocol_port.listeners[*].id, - flexibleengine_lb_listener_v2.test[1].id) + value = contains(data.flexibleengine_lb_listeners.by_protocol_port.listeners[*].id, + flexibleengine_lb_listener.test[2].id) && !contains(data.flexibleengine_lb_listeners.by_protocol_port.listeners[*].id, + flexibleengine_lb_listener.test[0].id) && !contains(data.flexibleengine_lb_listeners.by_protocol_port.listeners[*].id, + flexibleengine_lb_listener.test[1].id) } `, testAccDatasourceListeners_base(rName)) } diff --git a/flexibleengine/acceptance/data_source_flexibleengine_lb_loadbalancer_test.go b/flexibleengine/acceptance/data_source_flexibleengine_lb_loadbalancer_test.go new file mode 100644 index 000000000..b96e29e38 --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_lb_loadbalancer_test.go @@ -0,0 +1,95 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + + "github.com/chnsz/golangsdk/openstack/elb/v2/loadbalancers" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getLoadBalancerResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { + c, err := conf.LoadBalancerClient(OS_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating ELB v2 Client: %s", err) + } + resp, err := loadbalancers.Get(c, state.Primary.ID).Extract() + if resp == nil && err == nil { + return resp, fmt.Errorf("unable to find the LoadBalancer (%s)", state.Primary.ID) + } + return resp, err +} + +func TestAccELBV2LoadbalancerDataSource_basic(t *testing.T) { + rName := acceptance.RandomAccResourceNameWithDash() + dataSourceName1 := "data.flexibleengine_lb_loadbalancer.test_by_name" + dc1 := acceptance.InitDataSourceCheck(dataSourceName1) + dataSourceName2 := "data.flexibleengine_lb_loadbalancer.test_by_description" + dc2 := acceptance.InitDataSourceCheck(dataSourceName2) + + var lb loadbalancers.LoadBalancer + resourceName := "flexibleengine_lb_loadbalancer.test" + + rc := acceptance.InitResourceCheck( + resourceName, + &lb, + getLoadBalancerResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccELBV2LoadbalancerDataSource_basic(rName), + Check: resource.ComposeTestCheckFunc( + dc1.CheckResourceExists(), + dc2.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName1, "name", rName), + resource.TestCheckResourceAttr(dataSourceName2, "name", rName), + ), + }, + }, + }) +} + +func testAccELBV2LoadbalancerDataSource_basic(rName string) string { + return fmt.Sprintf(` + +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "test" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + description = "test for load balancer data source" +} + +data "flexibleengine_lb_loadbalancer" "test_by_name" { + name = flexibleengine_lb_loadbalancer.test.name + + depends_on = [flexibleengine_lb_loadbalancer.test] +} + +data "flexibleengine_lb_loadbalancer" "test_by_description" { + description = flexibleengine_lb_loadbalancer.test.description + + depends_on = [flexibleengine_lb_loadbalancer.test] +} +`, rName) +} diff --git a/flexibleengine/acceptance/resource_flexibleengine_lb_member_test.go b/flexibleengine/acceptance/resource_flexibleengine_lb_member_test.go new file mode 100644 index 000000000..858c9d8d8 --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_lb_member_test.go @@ -0,0 +1,230 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk/openstack/elb/v2/pools" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils/fmtp" +) + +func TestAccLBV2Member_basic(t *testing.T) { + var member_1 pools.Member + var member_2 pools.Member + resourceName1 := "flexibleengine_lb_member.member_1" + resourceName2 := "flexibleengine_lb_member.member_2" + rName := acceptance.RandomAccResourceNameWithDash() + + rc1 := acceptance.InitResourceCheck( + resourceName1, + &member_1, + getMemberResourceFunc, + ) + rc2 := acceptance.InitResourceCheck( + resourceName2, + &member_2, + getMemberResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: testAccCheckLBV2MemberDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLBV2MemberConfig_basic(rName), + ExpectNonEmptyPlan: true, // Because admin_state_up remains false. + Check: resource.ComposeTestCheckFunc( + rc1.CheckResourceExists(), + rc2.CheckResourceExists(), + ), + }, + { + Config: testAccLBV2MemberConfig_update(rName), + ExpectNonEmptyPlan: true, // Because admin_state_up remains false. + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("flexibleengine_lb_member.member_1", "weight", "10"), + resource.TestCheckResourceAttr("flexibleengine_lb_member.member_2", "weight", "15"), + ), + }, + { + ResourceName: "flexibleengine_lb_member.member_1", + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccLBMemberImportStateIdFunc(), + }, + }, + }) +} + +func testAccCheckLBV2MemberDestroy(s *terraform.State) error { + config := acceptance.TestAccProvider.Meta().(*config.Config) + elbClient, err := config.LoadBalancerClient(OS_REGION_NAME) + if err != nil { + return fmtp.Errorf("Error creating HuaweiCloud elb client: %s", err) + } + + for _, rs := range s.RootModule().Resources { + if rs.Type != "flexibleengine_lb_member" { + continue + } + + poolId := rs.Primary.Attributes["pool_id"] + _, err := pools.GetMember(elbClient, poolId, rs.Primary.ID).Extract() + if err == nil { + return fmtp.Errorf("Member still exists: %s", rs.Primary.ID) + } + } + + return nil +} + +func testAccLBMemberImportStateIdFunc() resource.ImportStateIdFunc { + return func(s *terraform.State) (string, error) { + pool, ok := s.RootModule().Resources["flexibleengine_lb_pool.pool_1"] + if !ok { + return "", fmt.Errorf("pool not found: %s", pool) + } + member, ok := s.RootModule().Resources["flexibleengine_lb_member.member_1"] + if !ok { + return "", fmt.Errorf("member not found: %s", member) + } + if pool.Primary.ID == "" || member.Primary.ID == "" { + return "", fmt.Errorf("resource not found: %s/%s", pool.Primary.ID, member.Primary.ID) + } + return fmt.Sprintf("%s/%s", pool.Primary.ID, member.Primary.ID), nil + } +} + +func testAccLBV2MemberConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "%[1]s" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = flexibleengine_lb_listener.listener_1.id +} + +resource "flexibleengine_lb_member" "member_1" { + address = "192.168.0.10" + protocol_port = 8080 + pool_id = flexibleengine_lb_pool.pool_1.id + subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + + timeouts { + create = "5m" + update = "5m" + delete = "5m" + } +} + +resource "flexibleengine_lb_member" "member_2" { + address = "192.168.0.11" + protocol_port = 8080 + pool_id = flexibleengine_lb_pool.pool_1.id + subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + + timeouts { + create = "5m" + update = "5m" + delete = "5m" + } +} +`, rName) +} + +func testAccLBV2MemberConfig_update(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "%[1]s" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = flexibleengine_lb_listener.listener_1.id +} + +resource "flexibleengine_lb_member" "member_1" { + address = "192.168.0.10" + protocol_port = 8080 + weight = 10 + admin_state_up = "true" + pool_id = flexibleengine_lb_pool.pool_1.id + subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + + timeouts { + create = "5m" + update = "5m" + delete = "5m" + } +} + +resource "flexibleengine_lb_member" "member_2" { + address = "192.168.0.11" + protocol_port = 8080 + weight = 15 + admin_state_up = "true" + pool_id = flexibleengine_lb_pool.pool_1.id + subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + + timeouts { + create = "5m" + update = "5m" + delete = "5m" + } +} +`, rName) +} diff --git a/flexibleengine/acceptance/resource_flexibleengine_lb_monitor_test.go b/flexibleengine/acceptance/resource_flexibleengine_lb_monitor_test.go new file mode 100644 index 000000000..4fcd860e2 --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_lb_monitor_test.go @@ -0,0 +1,250 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/chnsz/golangsdk/openstack/elb/v2/monitors" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func TestAccLBV2Monitor_basic(t *testing.T) { + var monitor monitors.Monitor + rName := acceptance.RandomAccResourceNameWithDash() + rNameUpdate := rName + "-update" + resourceName := "flexibleengine_lb_monitor.monitor_1" + + rc := acceptance.InitResourceCheck( + resourceName, + &monitor, + getMonitorResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccLBV2MonitorConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "type", "TCP"), + resource.TestCheckResourceAttr(resourceName, "delay", "20"), + resource.TestCheckResourceAttr(resourceName, "timeout", "10"), + resource.TestCheckResourceAttr(resourceName, "max_retries", "5"), + ), + }, + { + Config: testAccLBV2MonitorConfig_update(rName, rNameUpdate), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", rNameUpdate), + resource.TestCheckResourceAttr(resourceName, "delay", "30"), + resource.TestCheckResourceAttr(resourceName, "timeout", "15"), + resource.TestCheckResourceAttr(resourceName, "max_retries", "3"), + resource.TestCheckResourceAttr(resourceName, "port", "8888"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccLBV2Monitor_udp(t *testing.T) { + var monitor monitors.Monitor + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_lb_monitor.monitor_udp" + + rc := acceptance.InitResourceCheck( + resourceName, + &monitor, + getMonitorResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccLBV2MonitorConfig_udp(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "type", "UDP_CONNECT"), + resource.TestCheckResourceAttr(resourceName, "delay", "20"), + resource.TestCheckResourceAttr(resourceName, "timeout", "10"), + resource.TestCheckResourceAttr(resourceName, "max_retries", "5"), + ), + }, + }, + }) +} + +func TestAccLBV2Monitor_http(t *testing.T) { + var monitor monitors.Monitor + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_lb_monitor.monitor_http" + + rc := acceptance.InitResourceCheck( + resourceName, + &monitor, + getMonitorResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccLBV2MonitorConfig_http(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "type", "HTTP"), + resource.TestCheckResourceAttr(resourceName, "delay", "20"), + resource.TestCheckResourceAttr(resourceName, "timeout", "10"), + resource.TestCheckResourceAttr(resourceName, "max_retries", "5"), + resource.TestCheckResourceAttr(resourceName, "url_path", "/api"), + resource.TestCheckResourceAttr(resourceName, "http_method", "GET"), + resource.TestCheckResourceAttr(resourceName, "expected_codes", "200-202"), + ), + }, + }, + }) +} + +func testAccLBV2MonitorConfig_base(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "%[1]s" + protocol = "HTTP" + lb_method = "ROUND_ROBIN" + listener_id = flexibleengine_lb_listener.listener_1.id +} +`, rName) +} + +func testAccLBV2MonitorConfig_basic(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_lb_monitor" "monitor_1" { + pool_id = flexibleengine_lb_pool.pool_1.id + name = "%s" + type = "TCP" + delay = 20 + timeout = 10 + max_retries = 5 +} +`, testAccLBV2MonitorConfig_base(rName), rName) +} + +func testAccLBV2MonitorConfig_update(rName, rNameUpdate string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_lb_monitor" "monitor_1" { + pool_id = flexibleengine_lb_pool.pool_1.id + name = "%s" + type = "TCP" + delay = 30 + timeout = 15 + max_retries = 3 + port = 8888 +} +`, testAccLBV2MonitorConfig_base(rName), rNameUpdate) +} + +func testAccLBV2MonitorConfig_http(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_lb_monitor" "monitor_http" { + pool_id = flexibleengine_lb_pool.pool_1.id + name = "%s" + type = "HTTP" + delay = 20 + timeout = 10 + max_retries = 5 + url_path = "/api" + expected_codes = "200-202" +} +`, testAccLBV2MonitorConfig_base(rName), rName) +} + +func testAccLBV2MonitorConfig_udp(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "UDP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_pool" "pool_1" { + name = "%[1]s" + protocol = "UDP" + lb_method = "ROUND_ROBIN" + listener_id = flexibleengine_lb_listener.listener_1.id +} + +resource "flexibleengine_lb_monitor" "monitor_udp" { + pool_id = flexibleengine_lb_pool.pool_1.id + name = "%[1]s" + type = "UDP_CONNECT" + delay = 20 + timeout = 10 + max_retries = 5 +} +`, rName) +} diff --git a/flexibleengine/acceptance/resource_flexibleengine_lb_pool_v2_test.go b/flexibleengine/acceptance/resource_flexibleengine_lb_pool_test.go similarity index 80% rename from flexibleengine/acceptance/resource_flexibleengine_lb_pool_v2_test.go rename to flexibleengine/acceptance/resource_flexibleengine_lb_pool_test.go index 500ad9f3c..384fb05a8 100644 --- a/flexibleengine/acceptance/resource_flexibleengine_lb_pool_v2_test.go +++ b/flexibleengine/acceptance/resource_flexibleengine_lb_pool_test.go @@ -28,7 +28,7 @@ func TestAccLBV2Pool_basic(t *testing.T) { var pool pools.Pool rName := acceptance.RandomAccResourceNameWithDash() rNameUpdate := acceptance.RandomAccResourceNameWithDash() - resourceName := "flexibleengine_lb_pool_v2.pool_1" + resourceName := "flexibleengine_lb_pool.pool_1" rc := acceptance.InitResourceCheck( resourceName, @@ -67,47 +67,47 @@ func TestAccLBV2Pool_basic(t *testing.T) { func testAccLBV2PoolConfig_basic(rName string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "%[1]s" vip_subnet_id = "%[2]s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "%[1]s" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "%[1]s" protocol = "HTTP" lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id + listener_id = flexibleengine_lb_listener.listener_1.id } `, rName, OS_SUBNET_ID) } func testAccLBV2PoolConfig_update(rName, rNameUpdate string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "%[1]s" vip_subnet_id = "%[3]s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "%[1]s" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "%[2]s" protocol = "HTTP" lb_method = "LEAST_CONNECTIONS" admin_state_up = "true" - listener_id = flexibleengine_lb_listener_v2.listener_1.id + listener_id = flexibleengine_lb_listener.listener_1.id } `, rName, rNameUpdate, OS_SUBNET_ID) } diff --git a/flexibleengine/acceptance/resource_flexibleengine_lb_whitelist_test.go b/flexibleengine/acceptance/resource_flexibleengine_lb_whitelist_test.go new file mode 100644 index 000000000..7b5b5bbe7 --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_lb_whitelist_test.go @@ -0,0 +1,130 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk/openstack/elb/v2/whitelists" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getWhitelistResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) { + c, err := conf.LoadBalancerClient(OS_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating FlexibleEngine LB v2 client: %s", err) + } + resp, err := whitelists.Get(c, state.Primary.ID).Extract() + if resp == nil && err == nil { + return resp, fmt.Errorf("Unable to find the whitelist (%s)", state.Primary.ID) + } + return resp, err +} + +func TestAccLBV2Whitelist_basic(t *testing.T) { + var whitelist whitelists.Whitelist + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_lb_whitelist.whitelist_1" + + rc := acceptance.InitResourceCheck( + resourceName, + &whitelist, + getWhitelistResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccLBV2WhitelistConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + ), + }, + { + Config: testAccLBV2WhitelistConfig_update(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "enable_whitelist", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccLBV2WhitelistConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_whitelist" "whitelist_1" { + enable_whitelist = true + whitelist = "192.168.11.1,192.168.0.1/24" + listener_id = flexibleengine_lb_listener.listener_1.id +} +`, rName) +} + +func testAccLBV2WhitelistConfig_update(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/16" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + name = "%[1]s" + cidr = "192.168.0.0/24" + vpc_id = flexibleengine_vpc_v1.test.id + gateway_ip = "192.168.0.1" +} + +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener" "listener_1" { + name = "%[1]s" + protocol = "HTTP" + protocol_port = 8080 + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id +} + +resource "flexibleengine_lb_whitelist" "whitelist_1" { + enable_whitelist = true + whitelist = "192.168.11.1,192.168.0.1/24,192.168.201.18/8" + listener_id = flexibleengine_lb_listener.listener_1.id +} +`, rName) +} diff --git a/flexibleengine/data_source_flexibleengine_lb_certificate_v2.go b/flexibleengine/data_source_flexibleengine_lb_certificate.go similarity index 100% rename from flexibleengine/data_source_flexibleengine_lb_certificate_v2.go rename to flexibleengine/data_source_flexibleengine_lb_certificate.go diff --git a/flexibleengine/data_source_flexibleengine_lb_certificate_v2_test.go b/flexibleengine/data_source_flexibleengine_lb_certificate_test.go similarity index 86% rename from flexibleengine/data_source_flexibleengine_lb_certificate_v2_test.go rename to flexibleengine/data_source_flexibleengine_lb_certificate_test.go index 3cb8573f8..49177d15a 100644 --- a/flexibleengine/data_source_flexibleengine_lb_certificate_v2_test.go +++ b/flexibleengine/data_source_flexibleengine_lb_certificate_test.go @@ -16,13 +16,13 @@ func TestAccCertificateV2DataSource_basic(t *testing.T) { { Config: testAccDataSourceCertificateV2Config, Check: resource.ComposeTestCheckFunc( - testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate_v2.by_id"), - testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate_v2.by_name"), - testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate_v2.by_domain"), + testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate.by_id"), + testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate.by_name"), + testAccCheckCertificateV2DataSourceID("data.flexibleengine_lb_certificate.by_domain"), resource.TestCheckResourceAttr( - "data.flexibleengine_lb_certificate_v2.by_id", "name", "certificate_test"), + "data.flexibleengine_lb_certificate.by_id", "name", "certificate_test"), resource.TestCheckResourceAttr( - "data.flexibleengine_lb_certificate_v2.by_name", "domain", "www.elb.com"), + "data.flexibleengine_lb_certificate.by_name", "domain", "www.elb.com"), ), }, }, @@ -45,7 +45,7 @@ func testAccCheckCertificateV2DataSourceID(n string) resource.TestCheckFunc { } const testAccDataSourceCertificateV2Config = ` -resource "flexibleengine_lb_certificate_v2" "certificate_1" { +resource "flexibleengine_lb_certificate" "certificate_1" { name = "certificate_test" description = "terraform test certificate" domain = "www.elb.com" @@ -105,15 +105,15 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+8Kg== EOT } -data "flexibleengine_lb_certificate_v2" "by_id" { - id = flexibleengine_lb_certificate_v2.certificate_1.id +data "flexibleengine_lb_certificate" "by_id" { + id = flexibleengine_lb_certificate.certificate_1.id } -data "flexibleengine_lb_certificate_v2" "by_domain" { - domain = flexibleengine_lb_certificate_v2.certificate_1.domain +data "flexibleengine_lb_certificate" "by_domain" { + domain = flexibleengine_lb_certificate.certificate_1.domain } -data "flexibleengine_lb_certificate_v2" "by_name" { - name = flexibleengine_lb_certificate_v2.certificate_1.name +data "flexibleengine_lb_certificate" "by_name" { + name = flexibleengine_lb_certificate.certificate_1.name } ` diff --git a/flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2_test.go b/flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2_test.go deleted file mode 100644 index 955554321..000000000 --- a/flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package flexibleengine - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccELBV2LoadbalancerDataSource_basic(t *testing.T) { - rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2LoadBalancerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccELBV2LoadbalancerDataSource_basic(rName), - Check: resource.ComposeTestCheckFunc( - testAccCheckELBV2LoadbalancerDataSourceID("data.flexibleengine_lb_loadbalancer_v2.test_by_name"), - testAccCheckELBV2LoadbalancerDataSourceID("data.flexibleengine_lb_loadbalancer_v2.test_by_id"), - resource.TestCheckResourceAttr( - "data.flexibleengine_lb_loadbalancer_v2.test_by_name", "name", rName), - resource.TestCheckResourceAttr( - "data.flexibleengine_lb_loadbalancer_v2.test_by_id", "name", rName), - ), - }, - }, - }) -} - -func testAccCheckELBV2LoadbalancerDataSourceID(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Can't find elb load balancer data source: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("load balancer data source ID not set") - } - - return nil - } -} - -func testAccELBV2LoadbalancerDataSource_basic(rName string) string { - return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "test" { - name = "%s" - description = "resource for load balancer data source" - vip_subnet_id = "%s" - - tags = { - key = "value" - owner = "terraform" - } -} - -data "flexibleengine_lb_loadbalancer_v2" "test_by_name" { - name = flexibleengine_lb_loadbalancer_v2.test.name -} - -data "flexibleengine_lb_loadbalancer_v2" "test_by_id" { - id = flexibleengine_lb_loadbalancer_v2.test.id -} -`, rName, OS_SUBNET_ID) -} diff --git a/flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2.go b/flexibleengine/deprecated/data_source_flexibleengine_lb_loadbalancer_v2.go similarity index 90% rename from flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2.go rename to flexibleengine/deprecated/data_source_flexibleengine_lb_loadbalancer_v2.go index 2ec630e7c..cbf12f416 100644 --- a/flexibleengine/data_source_flexibleengine_lb_loadbalancer_v2.go +++ b/flexibleengine/deprecated/data_source_flexibleengine_lb_loadbalancer_v2.go @@ -1,4 +1,4 @@ -package flexibleengine +package deprecated import ( "fmt" @@ -8,11 +8,15 @@ import ( "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func dataSourceELBV2Loadbalancer() *schema.Resource { +func DataSourceELBV2Loadbalancer() *schema.Resource { return &schema.Resource{ Read: dataSourceELBV2LoadbalancerRead, + + DeprecationMessage: "flexibleengine_lb_loadbalancer_v2 has deprecated, use flexibleengine_lb_loadbalancer instead.", + Schema: map[string]*schema.Schema{ "region": { Type: schema.TypeString, @@ -57,7 +61,7 @@ func dataSourceELBV2Loadbalancer() *schema.Resource { } func dataSourceELBV2LoadbalancerRead(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) region := GetRegion(d, config) lbClient, err := config.ElbV2Client(region) if err != nil { diff --git a/flexibleengine/deprecated/lb_v2_shared.go b/flexibleengine/deprecated/lb_v2_shared.go new file mode 100644 index 000000000..459105d2f --- /dev/null +++ b/flexibleengine/deprecated/lb_v2_shared.go @@ -0,0 +1,481 @@ +package deprecated + +import ( + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/chnsz/golangsdk" + "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/l7policies" + "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/listeners" + "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/loadbalancers" + "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/monitors" + "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/pools" +) + +// lbPendingStatuses are the valid statuses a LoadBalancer will be in while +// it's updating. +var lbPendingStatuses = []string{"PENDING_CREATE", "PENDING_UPDATE"} + +// lbPendingDeleteStatuses are the valid statuses a LoadBalancer will be before delete +var lbPendingDeleteStatuses = []string{"ERROR", "PENDING_UPDATE", "PENDING_DELETE", "ACTIVE"} + +var lbSkipLBStatuses = []string{"ERROR", "ACTIVE"} + +func waitForLBV2Listener(lbClient *golangsdk.ServiceClient, id string, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for listener %s to become %s.", id, target) + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2ListenerRefreshFunc(lbClient, id), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + switch target { + case "DELETED": + return nil + default: + return fmt.Errorf("Error: listener %s not found: %s", id, err) + } + } + return fmt.Errorf("Error waiting for listener %s to become %s: %s", id, target, err) + } + + return nil +} + +func resourceLBV2ListenerRefreshFunc(lbClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + listener, err := listeners.Get(lbClient, id).Extract() + if err != nil { + return nil, "", err + } + + // The listener resource has no Status attribute, so a successful Get is the best we can do + return listener, "ACTIVE", nil + } +} + +func waitForLBV2LoadBalancer(lbClient *golangsdk.ServiceClient, id string, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for loadbalancer %s to become %s.", id, target) + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2LoadBalancerRefreshFunc(lbClient, id), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + switch target { + case "DELETED": + return nil + default: + return fmt.Errorf("Error: loadbalancer %s not found: %s", id, err) + } + } + return fmt.Errorf("Error waiting for loadbalancer %s to become %s: %s", id, target, err) + } + + return nil +} + +func resourceLBV2LoadBalancerRefreshFunc(lbClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + lb, err := loadbalancers.Get(lbClient, id).Extract() + if err != nil { + return nil, "", err + } + + return lb, lb.ProvisioningStatus, nil + } +} + +func waitForLBV2Member(lbClient *golangsdk.ServiceClient, poolID, memberID string, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for member %s to become %s.", memberID, target) + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2MemberRefreshFunc(lbClient, poolID, memberID), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + switch target { + case "DELETED": + return nil + default: + return fmt.Errorf("Error: member %s not found: %s", memberID, err) + } + } + return fmt.Errorf("Error waiting for member %s to become %s: %s", memberID, target, err) + } + + return nil +} + +func resourceLBV2MemberRefreshFunc(lbClient *golangsdk.ServiceClient, poolID, memberID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + member, err := pools.GetMember(lbClient, poolID, memberID).Extract() + if err != nil { + return nil, "", err + } + + // The member resource has no Status attribute, so a successful Get is the best we can do + return member, "ACTIVE", nil + } +} + +func waitForLBV2Monitor(lbClient *golangsdk.ServiceClient, id string, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for monitor %s to become %s.", id, target) + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2MonitorRefreshFunc(lbClient, id), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + switch target { + case "DELETED": + return nil + default: + return fmt.Errorf("Error: monitor %s not found: %s", id, err) + } + } + return fmt.Errorf("Error waiting for monitor %s to become %s: %s", id, target, err) + } + + return nil +} + +func resourceLBV2MonitorRefreshFunc(lbClient *golangsdk.ServiceClient, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + monitor, err := monitors.Get(lbClient, id).Extract() + if err != nil { + return nil, "", err + } + + // The monitor resource has no Status attribute, so a successful Get is the best we can do + return monitor, "ACTIVE", nil + } +} + +func waitForLBV2Pool(lbClient *golangsdk.ServiceClient, id string, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for pool %s to become %s.", id, target) + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2PoolRefreshFunc(lbClient, id), + Timeout: timeout, + Delay: 5 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + switch target { + case "DELETED": + return nil + default: + return fmt.Errorf("Error: pool %s not found: %s", id, err) + } + } + return fmt.Errorf("Error waiting for pool %s to become %s: %s", id, target, err) + } + + return nil +} + +func resourceLBV2PoolRefreshFunc(lbClient *golangsdk.ServiceClient, poolID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + pool, err := pools.Get(lbClient, poolID).Extract() + if err != nil { + return nil, "", err + } + + // The pool resource has no Status attribute, so a successful Get is the best we can do + return pool, "ACTIVE", nil + } +} + +func waitForLBV2viaPool(lbClient *golangsdk.ServiceClient, id string, target string, timeout time.Duration) error { + pool, err := pools.Get(lbClient, id).Extract() + if err != nil { + return err + } + + if pool.Loadbalancers != nil { + // each pool has an LB in Octavia lbaasv2 API + lbID := pool.Loadbalancers[0].ID + return waitForLBV2LoadBalancer(lbClient, lbID, target, nil, timeout) + } + + if pool.Listeners != nil { + // each pool has a listener in Neutron lbaasv2 API + listenerID := pool.Listeners[0].ID + listener, err := listeners.Get(lbClient, listenerID).Extract() + if err != nil { + return err + } + if listener.Loadbalancers != nil { + lbID := listener.Loadbalancers[0].ID + return waitForLBV2LoadBalancer(lbClient, lbID, target, nil, timeout) + } + } + + // got a pool but no LB - this is wrong + return fmt.Errorf("No Load Balancer on pool %s", id) +} + +func resourceLBV2LoadBalancerStatusRefreshFunc(lbClient *golangsdk.ServiceClient, lbID, resourceType, resourceID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + statuses, err := loadbalancers.GetStatuses(lbClient, lbID).Extract() + if err != nil { + return nil, "", fmt.Errorf("Unable to get statuses from the Load Balancer %s statuses tree: %s", lbID, err) + } + + if !strSliceContains(lbSkipLBStatuses, statuses.Loadbalancer.ProvisioningStatus) { + return statuses.Loadbalancer, statuses.Loadbalancer.ProvisioningStatus, nil + } + + switch resourceType { + case "listener": + for _, listener := range statuses.Loadbalancer.Listeners { + if listener.ID == resourceID { + if listener.ProvisioningStatus != "" { + return listener, listener.ProvisioningStatus, nil + } + } + } + listener, err := listeners.Get(lbClient, resourceID).Extract() + return listener, "ACTIVE", err + + case "pool": + for _, pool := range statuses.Loadbalancer.Pools { + if pool.ID == resourceID { + if pool.ProvisioningStatus != "" { + return pool, pool.ProvisioningStatus, nil + } + } + } + pool, err := pools.Get(lbClient, resourceID).Extract() + return pool, "ACTIVE", err + + case "monitor": + for _, pool := range statuses.Loadbalancer.Pools { + if pool.Monitor.ID == resourceID { + if pool.Monitor.ProvisioningStatus != "" { + return pool.Monitor, pool.Monitor.ProvisioningStatus, nil + } + } + } + monitor, err := monitors.Get(lbClient, resourceID).Extract() + return monitor, "ACTIVE", err + + case "member": + for _, pool := range statuses.Loadbalancer.Pools { + for _, member := range pool.Members { + if member.ID == resourceID { + if member.ProvisioningStatus != "" { + return member, member.ProvisioningStatus, nil + } + } + } + } + return "", "DELETED", nil + + case "l7policy": + for _, listener := range statuses.Loadbalancer.Listeners { + for _, l7policy := range listener.L7Policies { + if l7policy.ID == resourceID { + if l7policy.ProvisioningStatus != "" { + return l7policy, l7policy.ProvisioningStatus, nil + } + } + } + } + l7policy, err := l7policies.Get(lbClient, resourceID).Extract() + return l7policy, "ACTIVE", err + + case "l7rule": + for _, listener := range statuses.Loadbalancer.Listeners { + for _, l7policy := range listener.L7Policies { + for _, l7rule := range l7policy.Rules { + if l7rule.ID == resourceID { + if l7rule.ProvisioningStatus != "" { + return l7rule, l7rule.ProvisioningStatus, nil + } + } + } + } + } + return "", "DELETED", nil + } + + return nil, "", fmt.Errorf("An unexpected error occurred querying the status of %s %s by loadbalancer %s", resourceType, resourceID, lbID) + } +} + +func resourceLBV2L7PolicyRefreshFunc(lbClient *golangsdk.ServiceClient, lbID string, l7policy *l7policies.L7Policy) resource.StateRefreshFunc { + if l7policy.ProvisioningStatus != "" { + return func() (interface{}, string, error) { + lb, status, err := resourceLBV2LoadBalancerRefreshFunc(lbClient, lbID)() + if err != nil { + return lb, status, err + } + if !strSliceContains(lbSkipLBStatuses, status) { + return lb, status, nil + } + + l7policy, err := l7policies.Get(lbClient, l7policy.ID).Extract() + if err != nil { + return nil, "", err + } + + return l7policy, l7policy.ProvisioningStatus, nil + } + } + + return resourceLBV2LoadBalancerStatusRefreshFunc(lbClient, lbID, "l7policy", l7policy.ID) +} + +func waitForLBV2L7Policy(lbClient *golangsdk.ServiceClient, parentListener *listeners.Listener, l7policy *l7policies.L7Policy, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for l7policy %s to become %s.", l7policy.ID, target) + + if len(parentListener.Loadbalancers) == 0 { + return fmt.Errorf("Unable to determine loadbalancer ID from listener %s", parentListener.ID) + } + + lbID := parentListener.Loadbalancers[0].ID + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2L7PolicyRefreshFunc(lbClient, lbID, l7policy), + Timeout: timeout, + Delay: 1 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + if target == "DELETED" { + return nil + } + } + + return fmt.Errorf("Error waiting for l7policy %s to become %s: %s", l7policy.ID, target, err) + } + + return nil +} + +func getListenerIDForL7Policy(lbClient *golangsdk.ServiceClient, id string) (string, error) { + log.Printf("[DEBUG] Trying to get Listener ID associated with the %s L7 Policy ID", id) + lbsPages, err := loadbalancers.List(lbClient, loadbalancers.ListOpts{}).AllPages() + if err != nil { + return "", fmt.Errorf("No Load Balancers were found: %s", err) + } + + lbs, err := loadbalancers.ExtractLoadBalancers(lbsPages) + if err != nil { + return "", fmt.Errorf("Unable to extract Load Balancers list: %s", err) + } + + for _, lb := range lbs { + statuses, err := loadbalancers.GetStatuses(lbClient, lb.ID).Extract() + if err != nil { + return "", fmt.Errorf("Failed to get Load Balancer statuses: %s", err) + } + for _, listener := range statuses.Loadbalancer.Listeners { + for _, l7policy := range listener.L7Policies { + if l7policy.ID == id { + return listener.ID, nil + } + } + } + } + + return "", fmt.Errorf("Unable to find Listener ID associated with the %s L7 Policy ID", id) +} + +func resourceLBV2L7RuleRefreshFunc(lbClient *golangsdk.ServiceClient, lbID string, l7policyID string, l7rule *l7policies.Rule) resource.StateRefreshFunc { + if l7rule.ProvisioningStatus != "" { + return func() (interface{}, string, error) { + lb, status, err := resourceLBV2LoadBalancerRefreshFunc(lbClient, lbID)() + if err != nil { + return lb, status, err + } + if !strSliceContains(lbSkipLBStatuses, status) { + return lb, status, nil + } + + l7rule, err := l7policies.GetRule(lbClient, l7policyID, l7rule.ID).Extract() + if err != nil { + return nil, "", err + } + + return l7rule, l7rule.ProvisioningStatus, nil + } + } + + return resourceLBV2LoadBalancerStatusRefreshFunc(lbClient, lbID, "l7rule", l7rule.ID) +} + +func waitForLBV2L7Rule(lbClient *golangsdk.ServiceClient, parentListener *listeners.Listener, parentL7policy *l7policies.L7Policy, l7rule *l7policies.Rule, target string, pending []string, timeout time.Duration) error { + log.Printf("[DEBUG] Waiting for l7rule %s to become %s.", l7rule.ID, target) + + if len(parentListener.Loadbalancers) == 0 { + return fmt.Errorf("Unable to determine loadbalancer ID from listener %s", parentListener.ID) + } + + lbID := parentListener.Loadbalancers[0].ID + + stateConf := &resource.StateChangeConf{ + Target: []string{target}, + Pending: pending, + Refresh: resourceLBV2L7RuleRefreshFunc(lbClient, lbID, parentL7policy.ID, l7rule), + Timeout: timeout, + Delay: 1 * time.Second, + MinTimeout: 1 * time.Second, + } + + _, err := stateConf.WaitForState() + if err != nil { + if _, ok := err.(golangsdk.ErrDefault404); ok { + if target == "DELETED" { + return nil + } + } + + return fmt.Errorf("Error waiting for l7rule %s to become %s: %s", l7rule.ID, target, err) + } + + return nil +} diff --git a/flexibleengine/resource_flexibleengine_lb_member_v2.go b/flexibleengine/deprecated/resource_flexibleengine_lb_member_v2.go similarity index 94% rename from flexibleengine/resource_flexibleengine_lb_member_v2.go rename to flexibleengine/deprecated/resource_flexibleengine_lb_member_v2.go index 05ed2e62f..378519adc 100644 --- a/flexibleengine/resource_flexibleengine_lb_member_v2.go +++ b/flexibleengine/deprecated/resource_flexibleengine_lb_member_v2.go @@ -1,4 +1,4 @@ -package flexibleengine +package deprecated import ( "fmt" @@ -7,17 +7,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/pools" ) -func resourceMemberV2() *schema.Resource { +func ResourceMemberV2() *schema.Resource { return &schema.Resource{ Create: resourceMemberV2Create, Read: resourceMemberV2Read, Update: resourceMemberV2Update, Delete: resourceMemberV2Delete, + DeprecationMessage: "flexibleengine_lb_member_v2 have deprecated, use flexibleengine_lb_member instead.", + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), @@ -94,7 +97,7 @@ func resourceMemberV2() *schema.Resource { } func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -157,7 +160,7 @@ func resourceMemberV2Create(d *schema.ResourceData, meta interface{}) error { } func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -184,7 +187,7 @@ func resourceMemberV2Read(d *schema.ResourceData, meta interface{}) error { } func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -232,7 +235,7 @@ func resourceMemberV2Update(d *schema.ResourceData, meta interface{}) error { } func resourceMemberV2Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) diff --git a/flexibleengine/resource_flexibleengine_lb_monitor_v2.go b/flexibleengine/deprecated/resource_flexibleengine_lb_monitor_v2.go similarity index 94% rename from flexibleengine/resource_flexibleengine_lb_monitor_v2.go rename to flexibleengine/deprecated/resource_flexibleengine_lb_monitor_v2.go index 2bf0781ed..a7329df48 100644 --- a/flexibleengine/resource_flexibleengine_lb_monitor_v2.go +++ b/flexibleengine/deprecated/resource_flexibleengine_lb_monitor_v2.go @@ -1,4 +1,4 @@ -package flexibleengine +package deprecated import ( "fmt" @@ -7,17 +7,20 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/monitors" ) -func resourceMonitorV2() *schema.Resource { +func ResourceMonitorV2() *schema.Resource { return &schema.Resource{ Create: resourceMonitorV2Create, Read: resourceMonitorV2Read, Update: resourceMonitorV2Update, Delete: resourceMonitorV2Delete, + DeprecationMessage: "flexibleengine_lb_monitor_v2 has deprecated, use flexibleengine_lb_monitor instead.", + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), @@ -99,8 +102,8 @@ func resourceMonitorV2() *schema.Resource { } func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) - lbClient, err := config.ElbV2Client(GetRegion(d, config)) + config := meta.(*config.Config) + lbClient, err := config.ElbV2Client(config.GetRegion(d)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) } @@ -154,7 +157,7 @@ func resourceMonitorV2Create(d *schema.ResourceData, meta interface{}) error { } func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -184,7 +187,7 @@ func resourceMonitorV2Read(d *schema.ResourceData, meta interface{}) error { } func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -250,7 +253,7 @@ func resourceMonitorV2Update(d *schema.ResourceData, meta interface{}) error { } func resourceMonitorV2Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) diff --git a/flexibleengine/resource_flexibleengine_lb_whitelist_v2.go b/flexibleengine/deprecated/resource_flexibleengine_lb_whitelist_v2.go similarity index 83% rename from flexibleengine/resource_flexibleengine_lb_whitelist_v2.go rename to flexibleengine/deprecated/resource_flexibleengine_lb_whitelist_v2.go index 67c068497..f37007781 100644 --- a/flexibleengine/resource_flexibleengine_lb_whitelist_v2.go +++ b/flexibleengine/deprecated/resource_flexibleengine_lb_whitelist_v2.go @@ -1,21 +1,27 @@ -package flexibleengine +package deprecated import ( "fmt" "log" + "reflect" + "sort" + "strings" "time" "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/whitelists" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) -func resourceWhitelistV2() *schema.Resource { +func ResourceWhitelistV2() *schema.Resource { return &schema.Resource{ Create: resourceWhitelistV2Create, Read: resourceWhitelistV2Read, Update: resourceWhitelistV2Update, Delete: resourceWhitelistV2Delete, + DeprecationMessage: "flexibleengine_lb_whitelist_v2 has deprecated, use flexibleengine_lb_whitelist instead.", + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(10 * time.Minute), Update: schema.DefaultTimeout(10 * time.Minute), @@ -52,7 +58,7 @@ func resourceWhitelistV2() *schema.Resource { } func resourceWhitelistV2Create(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -77,7 +83,7 @@ func resourceWhitelistV2Create(d *schema.ResourceData, meta interface{}) error { } func resourceWhitelistV2Read(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -100,7 +106,7 @@ func resourceWhitelistV2Read(d *schema.ResourceData, meta interface{}) error { } func resourceWhitelistV2Update(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -125,7 +131,7 @@ func resourceWhitelistV2Update(d *schema.ResourceData, meta interface{}) error { } func resourceWhitelistV2Delete(d *schema.ResourceData, meta interface{}) error { - config := meta.(*Config) + config := meta.(*config.Config) lbClient, err := config.ElbV2Client(GetRegion(d, config)) if err != nil { return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) @@ -139,3 +145,15 @@ func resourceWhitelistV2Delete(d *schema.ResourceData, meta interface{}) error { d.SetId("") return nil } + +func suppressLBWhitelistDiffs(k, old, new string, d *schema.ResourceData) bool { + if len(old) != len(new) { + return false + } + old_array := strings.Split(old, ",") + new_array := strings.Split(new, ",") + sort.Strings(old_array) + sort.Strings(new_array) + + return reflect.DeepEqual(old_array, new_array) +} diff --git a/flexibleengine/deprecated/tags.go b/flexibleengine/deprecated/tags.go new file mode 100644 index 000000000..815f3d2df --- /dev/null +++ b/flexibleengine/deprecated/tags.go @@ -0,0 +1,98 @@ +package deprecated + +import ( + "fmt" + + "github.com/chnsz/golangsdk" + "github.com/chnsz/golangsdk/openstack/common/tags" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +const ( + tagVPCEP string = "endpoint" + tagVPCEPService string = "endpoint_service" +) + +// tagsSchema returns the schema to use for tags. +func tagsSchema() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + } +} + +// UpdateResourceTags is a helper to update the tags for a resource. +// It expects the tags field to be named "tags" +func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, resourceType, id string) error { + if d.HasChange("tags") { + oRaw, nRaw := d.GetChange("tags") + oMap := oRaw.(map[string]interface{}) + nMap := nRaw.(map[string]interface{}) + + // remove old tags + if len(oMap) > 0 { + taglist := expandResourceTags(oMap) + err := tags.Delete(conn, resourceType, id, taglist).ExtractErr() + if err != nil { + return err + } + } + + // set new tags + if len(nMap) > 0 { + taglist := expandResourceTags(nMap) + err := tags.Create(conn, resourceType, id, taglist).ExtractErr() + if err != nil { + return err + } + } + } + + return nil +} + +// tagsToMap returns the list of tags into a map. +func tagsToMap(tags []tags.ResourceTag) map[string]string { + result := make(map[string]string) + for _, val := range tags { + result[val.Key] = val.Value + } + + return result +} + +// expandResourceTags returns the tags for the given map of data. +func expandResourceTags(tagmap map[string]interface{}) []tags.ResourceTag { + var taglist []tags.ResourceTag + + for k, v := range tagmap { + tag := tags.ResourceTag{ + Key: k, + Value: v.(string), + } + taglist = append(taglist, tag) + } + + return taglist +} + +// get resource tag type of DNS zone by zoneType +func getDNSZoneTagType(zoneType string) (string, error) { + if zoneType == "public" { + return "DNS-public_zone", nil + } else if zoneType == "private" { + return "DNS-private_zone", nil + } + return "", fmt.Errorf("invalid zone type: %s", zoneType) +} + +// get resource tag type of DNS record set by zoneType +func getDNSRecordSetTagType(zoneType string) (string, error) { + if zoneType == "public" { + return "DNS-public_recordset", nil + } else if zoneType == "private" { + return "DNS-private_recordset", nil + } + return "", fmt.Errorf("invalid zone type: %s", zoneType) +} diff --git a/flexibleengine/deprecated/utils.go b/flexibleengine/deprecated/utils.go index caae7007f..082663327 100644 --- a/flexibleengine/deprecated/utils.go +++ b/flexibleengine/deprecated/utils.go @@ -1,11 +1,21 @@ package deprecated import ( + "bytes" + "encoding/json" "fmt" + "log" "net" "reflect" "regexp" "strings" + + "github.com/chnsz/golangsdk" + "github.com/hashicorp/go-uuid" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" ) func validateName(v interface{}, k string) (ws []string, errors []error) { @@ -95,3 +105,208 @@ func navigateValue(d interface{}, index []string, arrayIndex map[string]int) (in return d, nil } + +// ErrorResp is the response when API failed +type ErrorResp struct { + ErrorCode string `json:"error_code"` + ErrorMsg string `json:"error_msg"` +} + +// ParseErrorMsg is used to unmarshal the error body to ErrorResp +// usage: resp, pErr := ParseErrorMsg(err.Body) +func ParseErrorMsg(body []byte) (ErrorResp, error) { + resp := ErrorResp{} + err := json.Unmarshal(body, &resp) + return resp, err +} + +// CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so, +// sets the resource ID to the empty string instead of throwing an error. +func CheckDeleted(d *schema.ResourceData, err error, msg string) error { + if _, ok := err.(golangsdk.ErrDefault404); ok { + d.SetId("") + return nil + } + + return fmt.Errorf("%s: %s", msg, err) +} + +// CheckDeletedDiag checks the error to see if it's a 404 (Not Found) and, if so, +// sets the resource ID to the empty string instead of throwing an error. +func CheckDeletedDiag(d *schema.ResourceData, err error, msg string) diag.Diagnostics { + if _, ok := err.(golangsdk.ErrDefault404); ok { + d.SetId("") + return nil + } + + return diag.Errorf("%s: %s", msg, err) +} + +// GetRegion returns the region that was specified in the resource. If a +// region was not set, the provider-level region is checked. The provider-level +// region can either be set by the region argument or by OS_REGION_NAME. +func GetRegion(d *schema.ResourceData, config *config.Config) string { + if v, ok := d.GetOk("region"); ok { + return v.(string) + } + + return config.Region +} + +func checkForRetryableError(err error) *resource.RetryError { + switch errCode := err.(type) { + case golangsdk.ErrDefault500: + return resource.RetryableError(err) + case golangsdk.ErrUnexpectedResponseCode: + switch errCode.Actual { + case 409, 503: + return resource.RetryableError(err) + default: + return resource.NonRetryableError(err) + } + default: + return resource.NonRetryableError(err) + } +} + +func isResourceNotFound(err error) bool { + if err == nil { + return false + } + _, ok := err.(golangsdk.ErrDefault404) + return ok +} + +func hasFilledOpt(d *schema.ResourceData, param string) bool { + _, b := d.GetOkExists(param) + return b +} + +// strSliceContains checks if a given string is contained in a slice +// When anybody asks why Go needs generics, here you go. +func strSliceContains(haystack []string, needle string) bool { + for _, s := range haystack { + if s == needle { + return true + } + } + return false +} + +func jsonBytesEqual(b1, b2 []byte) bool { + var o1 interface{} + if err := json.Unmarshal(b1, &o1); err != nil { + return false + } + + var o2 interface{} + if err := json.Unmarshal(b2, &o2); err != nil { + return false + } + + return reflect.DeepEqual(o1, o2) +} + +// convertStructToMap converts an instance of struct to a map object, and +// changes each key of fileds to the value of 'nameMap' if the key in it +// or to its corresponding lowercase. +func convertStructToMap(obj interface{}, nameMap map[string]string) (map[string]interface{}, error) { + b, err := json.Marshal(obj) + if err != nil { + return nil, fmt.Errorf("Error converting struct to map, marshal failed:%v", err) + } + + m, err := regexp.Compile(`"[a-z0-9A-Z_]+":`) + if err != nil { + return nil, fmt.Errorf("Error converting struct to map, compile regular express failed") + } + nb := m.ReplaceAllFunc( + b, + func(src []byte) []byte { + k := fmt.Sprintf("%s", src[1:len(src)-2]) + v, ok := nameMap[k] + if !ok { + v = strings.ToLower(k) + } + return []byte(fmt.Sprintf("\"%s\":", v)) + }, + ) + log.Printf("[DEBUG]convertStructToMap:: before change b =%s", b) + log.Printf("[DEBUG]convertStructToMap:: after change nb=%s", nb) + + p := make(map[string]interface{}) + err = json.Unmarshal(nb, &p) + if err != nil { + return nil, fmt.Errorf("Error converting struct to map, unmarshal failed:%v", err) + } + log.Printf("[DEBUG]convertStructToMap:: map= %#v\n", p) + return p, nil +} + +func looksLikeJsonString(s interface{}) bool { + return regexp.MustCompile(`^\s*{`).MatchString(s.(string)) +} + +func compareJsonTemplateAreEquivalent(tem1, tem2 string) (bool, error) { + var obj1 interface{} + err := json.Unmarshal([]byte(tem1), &obj1) + if err != nil { + return false, err + } + + canonicalJson1, _ := json.Marshal(obj1) + + var obj2 interface{} + err = json.Unmarshal([]byte(tem2), &obj2) + if err != nil { + return false, err + } + + canonicalJson2, _ := json.Marshal(obj2) + + equal := bytes.Compare(canonicalJson1, canonicalJson2) == 0 + if !equal { + log.Printf("[DEBUG] Canonical template are not equal.\nFirst: %s\nSecond: %s\n", + canonicalJson1, canonicalJson2) + } + return equal, nil +} + +// HashStrings hashes a list of strings to a unique hashcode. +func HashStrings(strings []string) string { + var buf bytes.Buffer + + for _, s := range strings { + buf.WriteString(fmt.Sprintf("%s-", s)) + } + + return fmt.Sprintf("%d", schema.HashString(buf.String())) +} + +func IsUUIDFormat(str string) bool { + if _, err := uuid.ParseUUID(str); err != nil { + log.Printf("[WARN] '%s' is not a valid UUID: %s", str, err) + return false + } + return true +} + +// isStrContainsSliceElement returns true if the string exists in given slice or contains in one of slice elements when +// open exact flag. Also you can ignore case for this check. +func isStrContainsSliceElement(str string, sl []string, ignoreCase, isExcat bool) bool { + if ignoreCase { + str = strings.ToLower(str) + } + for _, s := range sl { + if ignoreCase { + s = strings.ToLower(s) + } + if isExcat && s == str { + return true + } + if !isExcat && strings.Contains(str, s) { + return true + } + } + return false +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 5a861c878..386c932f9 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -7,8 +7,10 @@ import ( "strings" "sync" + fedeprecated "github.com/FlexibleEngineCloud/terraform-provider-flexibleengine/flexibleengine/deprecated" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/deprecated" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" @@ -24,7 +26,6 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dcs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/ddm" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dds" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/deprecated" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dew" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dli" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dms" @@ -289,8 +290,7 @@ func Provider() *schema.Provider { "flexibleengine_dds_flavors_v3": dataSourceDDSFlavorsV3(), - "flexibleengine_lb_certificate_v2": dataSourceCertificateV2(), - "flexibleengine_lb_loadbalancer_v2": dataSourceELBV2Loadbalancer(), + "flexibleengine_lb_certificate": dataSourceCertificateV2(), "flexibleengine_sdrs_domain_v1": dataSourceSdrsDomainV1(), @@ -347,7 +347,8 @@ func Provider() *schema.Provider { "flexibleengine_fgs_dependencies": fgs.DataSourceFunctionGraphDependencies(), - "flexibleengine_lb_listeners_v2": lb.DataSourceListeners(), + "flexibleengine_lb_listeners": lb.DataSourceListeners(), + "flexibleengine_lb_loadbalancer": lb.DataSourceELBV2Loadbalancer(), "flexibleengine_gaussdb_cassandra_flavors": gaussdb.DataSourceCassandraFlavors(), "flexibleengine_gaussdb_cassandra_instances": gaussdb.DataSourceGeminiDBInstances(), @@ -390,19 +391,26 @@ func Provider() *schema.Provider { "flexibleengine_rds_flavors_v3": rds.DataSourceRdsFlavor(), // v1.34.0 // Deprecated data source - "flexibleengine_compute_availability_zones_v2": dataSourceAvailabilityZones(), "flexibleengine_blockstorage_availability_zones_v3": dataSourceBlockStorageAvailabilityZonesV3(), + "flexibleengine_compute_availability_zones_v2": dataSourceAvailabilityZones(), + + "flexibleengine_dcs_az_v1": dataSourceDcsAZV1(), + + "flexibleengine_dds_flavor_v3": dataSourceDDSFlavorV3(), + "flexibleengine_images_image_v2": dataSourceImagesImageV2(), + "flexibleengine_lb_certificate_v2": dataSourceCertificateV2(), + "flexibleengine_lb_listeners_v2": lb.DataSourceListeners(), + "flexibleengine_lb_loadbalancer_v2": fedeprecated.DataSourceELBV2Loadbalancer(), + + "flexibleengine_rds_flavors_v1": dataSourceRdsFlavorV1(), + "flexibleengine_networking_network_v2": dataSourceNetworkingNetworkV2(), "flexibleengine_vpc_eip_v1": dataSourceVpcEipV1(), "flexibleengine_vpc_route_v2": dataSourceVPCRouteV2(), "flexibleengine_vpc_route_ids_v2": dataSourceVPCRouteIdsV2(), - - "flexibleengine_dcs_az_v1": dataSourceDcsAZV1(), - "flexibleengine_dds_flavor_v3": dataSourceDDSFlavorV3(), - "flexibleengine_rds_flavors_v1": dataSourceRdsFlavorV1(), }, ResourcesMap: map[string]*schema.Resource{ @@ -433,13 +441,10 @@ func Provider() *schema.Provider { "flexibleengine_kms_key_v1": resourceKmsKeyV1(), - "flexibleengine_lb_loadbalancer_v2": resourceLoadBalancerV2(), - "flexibleengine_lb_listener_v2": resourceListenerV2(), - "flexibleengine_lb_member_v2": resourceMemberV2(), - "flexibleengine_lb_monitor_v2": resourceMonitorV2(), - "flexibleengine_lb_whitelist_v2": resourceWhitelistV2(), - "flexibleengine_lb_l7policy_v2": resourceL7PolicyV2(), - "flexibleengine_lb_l7rule_v2": resourceL7RuleV2(), + "flexibleengine_lb_loadbalancer": resourceLoadBalancerV2(), + "flexibleengine_lb_listener": resourceListenerV2(), + "flexibleengine_lb_l7policy": resourceL7PolicyV2(), + "flexibleengine_lb_l7rule": resourceL7RuleV2(), "flexibleengine_mrs_cluster_v2": resourceMRSClusterV2(), "flexibleengine_mrs_job_v2": resourceMRSJobV2(), @@ -674,6 +679,10 @@ func Provider() *schema.Provider { "flexibleengine_elb_security_policy": elb.ResourceSecurityPolicy(), "flexibleengine_elb_logtank": elb.ResourceLogTank(), + "flexibleengine_lb_member": lb.ResourceMemberV2(), + "flexibleengine_lb_monitor": lb.ResourceMonitorV2(), + "flexibleengine_lb_whitelist": lb.ResourceWhitelistV2(), + "flexibleengine_modelarts_dataset": modelarts.ResourceDataset(), "flexibleengine_modelarts_dataset_version": modelarts.ResourceDatasetVersion(), "flexibleengine_smn_message_template": smn.ResourceSmnMessageTemplate(), @@ -682,7 +691,7 @@ func Provider() *schema.Provider { "flexibleengine_rds_instance_v3": rds.ResourceRdsInstance(), // v1.29.0 "flexibleengine_vpc_v1": vpc.ResourceVirtualPrivateCloudV1(), // v1.29.0 "flexibleengine_vpc_subnet_v1": vpc.ResourceVpcSubnetV1(), // v1.31.0 - "flexibleengine_lb_pool_v2": lb.ResourcePoolV2(), // v1.35.0 + "flexibleengine_lb_pool": lb.ResourcePoolV2(), // v1.35.0 "flexibleengine_lb_pool_v3": elb.ResourcePoolV3(), // v1.35.0 "flexibleengine_lb_monitor_v3": elb.ResourceMonitorV3(), // v1.35.0 "flexibleengine_lb_member_v3": elb.ResourceMemberV3(), // v1.35.0 @@ -691,18 +700,27 @@ func Provider() *schema.Provider { "flexibleengine_sfs_turbo": sfs.ResourceSFSTurbo(), // Deprecated resource + "flexibleengine_apig_vpc_channel": deprecated.ResourceApigVpcChannelV2(), + "flexibleengine_as_group_v1": resourceASGroup(), "flexibleengine_as_configuration_v1": resourceASConfiguration(), - "flexibleengine_elb_loadbalancer": resourceELoadBalancer(), - "flexibleengine_elb_listener": resourceEListener(), - "flexibleengine_elb_backend": resourceBackend(), - "flexibleengine_elb_health": resourceHealth(), - "flexibleengine_images_image_v2": resourceImagesImageV2(), - "flexibleengine_lb_certificate_v2": resourceCertificateV2(), - "flexibleengine_rds_instance_v1": resourceRdsInstance(), - "flexibleengine_vpc_eip_v1": resourceVpcEIPV1(), - "flexibleengine_vpc_route_v2": resourceVPCRouteV2(), + "flexibleengine_elb_loadbalancer": resourceELoadBalancer(), + "flexibleengine_elb_listener": resourceEListener(), + "flexibleengine_elb_backend": resourceBackend(), + "flexibleengine_elb_health": resourceHealth(), + + "flexibleengine_images_image_v2": resourceImagesImageV2(), + + "flexibleengine_lb_certificate_v2": resourceCertificateV2(), + "flexibleengine_lb_l7policy_v2": resourceL7PolicyV2(), + "flexibleengine_lb_l7rule_v2": resourceL7RuleV2(), + "flexibleengine_lb_listener_v2": resourceListenerV2(), + "flexibleengine_lb_loadbalancer_v2": resourceLoadBalancerV2(), + "flexibleengine_lb_pool_v2": lb.ResourcePoolV2(), + "flexibleengine_lb_member_v2": fedeprecated.ResourceMemberV2(), + "flexibleengine_lb_monitor_v2": fedeprecated.ResourceMonitorV2(), + "flexibleengine_lb_whitelist_v2": fedeprecated.ResourceWhitelistV2(), "flexibleengine_mrs_hybrid_cluster_v1": resourceMRSHybridClusterV1(), "flexibleengine_mrs_cluster_v1": resourceMRSClusterV1(), @@ -716,7 +734,10 @@ func Provider() *schema.Provider { "flexibleengine_networking_router_interface_v2": resourceNetworkingRouterInterfaceV2(), "flexibleengine_networking_router_route_v2": resourceNetworkingRouterRouteV2(), - "flexibleengine_apig_vpc_channel": deprecated.ResourceApigVpcChannelV2(), + "flexibleengine_rds_instance_v1": resourceRdsInstance(), + + "flexibleengine_vpc_eip_v1": resourceVpcEIPV1(), + "flexibleengine_vpc_route_v2": resourceVPCRouteV2(), }, // configuring the provider ConfigureContextFunc: configureProvider, diff --git a/flexibleengine/resource_flexibleengine_as_group_v1_test.go b/flexibleengine/resource_flexibleengine_as_group_v1_test.go index d905b7e86..3f56ac9f0 100644 --- a/flexibleengine/resource_flexibleengine_as_group_v1_test.go +++ b/flexibleengine/resource_flexibleengine_as_group_v1_test.go @@ -155,23 +155,23 @@ func testASV1Group_basic(rName string) string { return fmt.Sprintf(` %s -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener_1" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "pool_1" protocol = "HTTP" lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id + listener_id = flexibleengine_lb_listener.listener_1.id } resource "flexibleengine_as_group_v1" "as_group"{ @@ -186,8 +186,8 @@ resource "flexibleengine_as_group_v1" "as_group"{ id = flexibleengine_networking_secgroup_v2.secgroup.id } lbaas_listeners { - pool_id = flexibleengine_lb_pool_v2.pool_1.id - protocol_port = flexibleengine_lb_listener_v2.listener_1.protocol_port + pool_id = flexibleengine_lb_pool.pool_1.id + protocol_port = flexibleengine_lb_listener.listener_1.protocol_port } tags = { foo = "bar" diff --git a/flexibleengine/resource_flexibleengine_elb_listener_test.go b/flexibleengine/resource_flexibleengine_elb_listener_test.go index 062327613..104f44315 100644 --- a/flexibleengine/resource_flexibleengine_elb_listener_test.go +++ b/flexibleengine/resource_flexibleengine_elb_listener_test.go @@ -42,7 +42,7 @@ func testAccCheckELBListenerDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_listener_v2" { + if rs.Type != "flexibleengine_lb_listener" { continue } diff --git a/flexibleengine/resource_flexibleengine_lb_l7policy_v2.go b/flexibleengine/resource_flexibleengine_lb_l7policy.go similarity index 100% rename from flexibleengine/resource_flexibleengine_lb_l7policy_v2.go rename to flexibleengine/resource_flexibleengine_lb_l7policy.go diff --git a/flexibleengine/resource_flexibleengine_lb_l7policy_v2_test.go b/flexibleengine/resource_flexibleengine_lb_l7policy_test.go similarity index 72% rename from flexibleengine/resource_flexibleengine_lb_l7policy_v2_test.go rename to flexibleengine/resource_flexibleengine_lb_l7policy_test.go index 764b8c251..785d47f40 100644 --- a/flexibleengine/resource_flexibleengine_lb_l7policy_v2_test.go +++ b/flexibleengine/resource_flexibleengine_lb_l7policy_test.go @@ -22,17 +22,17 @@ func TestAccLBV2L7Policy_basic(t *testing.T) { { Config: testAccCheckLBV2L7PolicyConfig_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2L7PolicyExists("flexibleengine_lb_l7policy_v2.l7policy_1", &l7Policy), + testAccCheckLBV2L7PolicyExists("flexibleengine_lb_l7policy.l7policy_1", &l7Policy), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7policy_v2.l7policy_1", "name", "test"), + "flexibleengine_lb_l7policy.l7policy_1", "name", "test"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7policy_v2.l7policy_1", "description", "test description"), + "flexibleengine_lb_l7policy.l7policy_1", "description", "test description"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7policy_v2.l7policy_1", "action", "REDIRECT_TO_POOL"), + "flexibleengine_lb_l7policy.l7policy_1", "action", "REDIRECT_TO_POOL"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7policy_v2.l7policy_1", "position", "1"), + "flexibleengine_lb_l7policy.l7policy_1", "position", "1"), resource.TestMatchResourceAttr( - "flexibleengine_lb_l7policy_v2.l7policy_1", "listener_id", + "flexibleengine_lb_l7policy.l7policy_1", "listener_id", regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")), ), }, @@ -48,7 +48,7 @@ func testAccCheckLBV2L7PolicyDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_l7policy_v2" { + if rs.Type != "flexibleengine_lb_l7policy" { continue } @@ -94,31 +94,31 @@ func testAccCheckLBV2L7PolicyExists(n string, l7Policy *l7policies.L7Policy) res } var testAccCheckLBV2L7PolicyConfig_basic = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener_1" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "pool_1" protocol = "HTTP" lb_method = "ROUND_ROBIN" - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_l7policy_v2" "l7policy_1" { +resource "flexibleengine_lb_l7policy" "l7policy_1" { name = "test" action = "REDIRECT_TO_POOL" description = "test description" position = 1 - listener_id = flexibleengine_lb_listener_v2.listener_1.id - redirect_pool_id = flexibleengine_lb_pool_v2.pool_1.id + listener_id = flexibleengine_lb_listener.listener_1.id + redirect_pool_id = flexibleengine_lb_pool.pool_1.id } `, OS_SUBNET_ID) diff --git a/flexibleengine/resource_flexibleengine_lb_l7rule_v2.go b/flexibleengine/resource_flexibleengine_lb_l7rule.go similarity index 100% rename from flexibleengine/resource_flexibleengine_lb_l7rule_v2.go rename to flexibleengine/resource_flexibleengine_lb_l7rule.go diff --git a/flexibleengine/resource_flexibleengine_lb_l7rule_v2_test.go b/flexibleengine/resource_flexibleengine_lb_l7rule_test.go similarity index 71% rename from flexibleengine/resource_flexibleengine_lb_l7rule_v2_test.go rename to flexibleengine/resource_flexibleengine_lb_l7rule_test.go index 19b3b8c05..6b813e009 100644 --- a/flexibleengine/resource_flexibleengine_lb_l7rule_v2_test.go +++ b/flexibleengine/resource_flexibleengine_lb_l7rule_test.go @@ -22,33 +22,33 @@ func TestAccLBV2L7Rule_basic(t *testing.T) { { Config: testAccCheckLBV2L7RuleConfig_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2L7RuleExists("flexibleengine_lb_l7rule_v2.l7rule_1", &l7rule), + testAccCheckLBV2L7RuleExists("flexibleengine_lb_l7rule.l7rule_1", &l7rule), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "type", "PATH"), + "flexibleengine_lb_l7rule.l7rule_1", "type", "PATH"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "compare_type", "EQUAL_TO"), + "flexibleengine_lb_l7rule.l7rule_1", "compare_type", "EQUAL_TO"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "value", "/api"), + "flexibleengine_lb_l7rule.l7rule_1", "value", "/api"), resource.TestMatchResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "listener_id", + "flexibleengine_lb_l7rule.l7rule_1", "listener_id", regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")), resource.TestMatchResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "l7policy_id", + "flexibleengine_lb_l7rule.l7rule_1", "l7policy_id", regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")), ), }, { Config: testAccCheckLBV2L7RuleConfig_update, Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2L7RuleExists("flexibleengine_lb_l7rule_v2.l7rule_1", &l7rule), + testAccCheckLBV2L7RuleExists("flexibleengine_lb_l7rule.l7rule_1", &l7rule), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "type", "PATH"), + "flexibleengine_lb_l7rule.l7rule_1", "type", "PATH"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "compare_type", "STARTS_WITH"), + "flexibleengine_lb_l7rule.l7rule_1", "compare_type", "STARTS_WITH"), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "key", ""), + "flexibleengine_lb_l7rule.l7rule_1", "key", ""), resource.TestCheckResourceAttr( - "flexibleengine_lb_l7rule_v2.l7rule_1", "value", "/images"), + "flexibleengine_lb_l7rule.l7rule_1", "value", "/images"), ), }, }, @@ -63,7 +63,7 @@ func testAccCheckLBV2L7RuleDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_l7rule_v2" { + if rs.Type != "flexibleengine_lb_l7rule" { continue } @@ -133,40 +133,40 @@ func testAccCheckLBV2L7RuleExists(n string, l7rule *l7rules.Rule) resource.TestC } var testAccCheckLBV2L7RuleConfig = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener_1" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "pool_1" protocol = "HTTP" lb_method = "ROUND_ROBIN" - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_l7policy_v2" "l7policy_1" { +resource "flexibleengine_lb_l7policy" "l7policy_1" { name = "test" action = "REDIRECT_TO_POOL" description = "test description" position = 1 - listener_id = flexibleengine_lb_listener_v2.listener_1.id - redirect_pool_id = flexibleengine_lb_pool_v2.pool_1.id + listener_id = flexibleengine_lb_listener.listener_1.id + redirect_pool_id = flexibleengine_lb_pool.pool_1.id } `, OS_SUBNET_ID) var testAccCheckLBV2L7RuleConfig_basic = fmt.Sprintf(` %s -resource "flexibleengine_lb_l7rule_v2" "l7rule_1" { - l7policy_id = flexibleengine_lb_l7policy_v2.l7policy_1.id +resource "flexibleengine_lb_l7rule" "l7rule_1" { + l7policy_id = flexibleengine_lb_l7policy.l7policy_1.id type = "PATH" compare_type = "EQUAL_TO" value = "/api" @@ -176,8 +176,8 @@ resource "flexibleengine_lb_l7rule_v2" "l7rule_1" { var testAccCheckLBV2L7RuleConfig_update = fmt.Sprintf(` %s -resource "flexibleengine_lb_l7rule_v2" "l7rule_1" { - l7policy_id = flexibleengine_lb_l7policy_v2.l7policy_1.id +resource "flexibleengine_lb_l7rule" "l7rule_1" { + l7policy_id = flexibleengine_lb_l7policy.l7policy_1.id type = "PATH" compare_type = "STARTS_WITH" value = "/images" diff --git a/flexibleengine/resource_flexibleengine_lb_listener_v2.go b/flexibleengine/resource_flexibleengine_lb_listener.go similarity index 100% rename from flexibleengine/resource_flexibleengine_lb_listener_v2.go rename to flexibleengine/resource_flexibleengine_lb_listener.go diff --git a/flexibleengine/resource_flexibleengine_lb_listener_v2_test.go b/flexibleengine/resource_flexibleengine_lb_listener_test.go similarity index 89% rename from flexibleengine/resource_flexibleengine_lb_listener_v2_test.go rename to flexibleengine/resource_flexibleengine_lb_listener_test.go index f1f413740..401808dfe 100644 --- a/flexibleengine/resource_flexibleengine_lb_listener_v2_test.go +++ b/flexibleengine/resource_flexibleengine_lb_listener_test.go @@ -12,7 +12,7 @@ import ( func TestAccLBV2Listener_basic(t *testing.T) { var listener listeners.Listener - resourceName := "flexibleengine_lb_listener_v2.listener_1" + resourceName := "flexibleengine_lb_listener.listener_1" rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ @@ -55,7 +55,7 @@ func TestAccLBV2Listener_basic(t *testing.T) { func TestAccLBV2Listener_withCert(t *testing.T) { var listener listeners.Listener - resourceName := "flexibleengine_lb_listener_v2.listener_1" + resourceName := "flexibleengine_lb_listener.listener_1" rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ @@ -78,7 +78,7 @@ func TestAccLBV2Listener_withCert(t *testing.T) { func TestAccLBV2Listener_v3(t *testing.T) { var listener listeners.Listener - resourceName := "flexibleengine_lb_listener_v2.listener_1" + resourceName := "flexibleengine_lb_listener.listener_1" rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) resource.Test(t, resource.TestCase{ @@ -109,7 +109,7 @@ func testAccCheckLBV2ListenerDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_listener_v2" { + if rs.Type != "flexibleengine_lb_listener" { continue } @@ -156,33 +156,33 @@ func testAccCheckLBV2ListenerExists(n string, listener *listeners.Listener) reso func testAccLBV2ListenerConfig_basic(name string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener-%s" description = "created by acceptance test" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } `, name, OS_SUBNET_ID, name) } func testAccLBV2ListenerConfig_tags(name string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener-%s" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id tags = { key = "value" @@ -194,17 +194,17 @@ resource "flexibleengine_lb_listener_v2" "listener_1" { func testAccLBV2ListenerConfig_update(name string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener-%s_updated" description = "created by acceptance test updated" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id tags = { foo = "bar" @@ -216,7 +216,7 @@ resource "flexibleengine_lb_listener_v2" "listener_1" { func testAccLBV2ListenerConfig_cert(name string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } @@ -280,12 +280,12 @@ i1YhgnQbn5E0hz55OLu5jvOkKQjPCW+9Aa== EOT } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener-%s" protocol = "TERMINATED_HTTPS" protocol_port = 8080 http2_enable = true - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id default_tls_container_ref = flexibleengine_elb_certificate.certificate_1.id } `, name, OS_SUBNET_ID, name, name) @@ -293,16 +293,16 @@ resource "flexibleengine_lb_listener_v2" "listener_1" { func testAccLBV2ListenerConfig_v3(name string) string { return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "lb-%s" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener-%s" protocol = "TCP" protocol_port = 443 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id idle_timeout = 500 transparent_client_ip_enable = true diff --git a/flexibleengine/resource_flexibleengine_lb_loadbalancer_v2.go b/flexibleengine/resource_flexibleengine_lb_loadbalancer.go similarity index 100% rename from flexibleengine/resource_flexibleengine_lb_loadbalancer_v2.go rename to flexibleengine/resource_flexibleengine_lb_loadbalancer.go diff --git a/flexibleengine/resource_flexibleengine_lb_loadbalancer_v2_test.go b/flexibleengine/resource_flexibleengine_lb_loadbalancer_test.go similarity index 93% rename from flexibleengine/resource_flexibleengine_lb_loadbalancer_v2_test.go rename to flexibleengine/resource_flexibleengine_lb_loadbalancer_test.go index 65d192d9a..5a3443b3a 100644 --- a/flexibleengine/resource_flexibleengine_lb_loadbalancer_v2_test.go +++ b/flexibleengine/resource_flexibleengine_lb_loadbalancer_test.go @@ -15,7 +15,7 @@ import ( func TestAccLBV2LoadBalancer_basic(t *testing.T) { var lb loadbalancers.LoadBalancer - resourceName := "flexibleengine_lb_loadbalancer_v2.loadbalancer_1" + resourceName := "flexibleengine_lb_loadbalancer.loadbalancer_1" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -54,7 +54,7 @@ func TestAccLBV2LoadBalancer_basic(t *testing.T) { func TestAccLBV2LoadBalancer_secGroup(t *testing.T) { var lb loadbalancers.LoadBalancer var sg_1, sg_2 groups.SecGroup - resourceName := "flexibleengine_lb_loadbalancer_v2.loadbalancer_1" + resourceName := "flexibleengine_lb_loadbalancer.loadbalancer_1" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -115,7 +115,7 @@ func testAccCheckLBV2LoadBalancerDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_loadbalancer_v2" { + if rs.Type != "flexibleengine_lb_loadbalancer" { continue } @@ -186,7 +186,7 @@ func testAccCheckLBV2LoadBalancerHasSecGroup( } var testAccLBV2LoadBalancerConfig_basic = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" description = "created by acceptance test" vip_subnet_id = "%s" @@ -199,7 +199,7 @@ resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { `, OS_SUBNET_ID) var testAccLBV2LoadBalancerConfig_update = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1_updated" admin_state_up = "true" vip_subnet_id = "%s" @@ -222,7 +222,7 @@ resource "flexibleengine_networking_secgroup_v2" "secgroup_2" { description = "secgroup_2" } -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" @@ -243,7 +243,7 @@ resource "flexibleengine_networking_secgroup_v2" "secgroup_2" { description = "secgroup_2" } -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" @@ -265,7 +265,7 @@ resource "flexibleengine_networking_secgroup_v2" "secgroup_2" { description = "secgroup_2" } -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" diff --git a/flexibleengine/resource_flexibleengine_lb_member_v2_test.go b/flexibleengine/resource_flexibleengine_lb_member_v2_test.go deleted file mode 100644 index 2f105ce2b..000000000 --- a/flexibleengine/resource_flexibleengine_lb_member_v2_test.go +++ /dev/null @@ -1,168 +0,0 @@ -package flexibleengine - -import ( - "fmt" - "testing" - - "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/pools" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccLBV2Member_basic(t *testing.T) { - var member_1 pools.Member - var member_2 pools.Member - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MemberDestroy, - Steps: []resource.TestStep{ - { - Config: testAccLBV2MemberConfig_basic, - ExpectNonEmptyPlan: true, // Because admin_state_up remains false, unfinished elb? - Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2MemberExists("flexibleengine_lb_member_v2.member_1", &member_1), - testAccCheckLBV2MemberExists("flexibleengine_lb_member_v2.member_2", &member_2), - ), - }, - { - Config: testAccLBV2MemberConfig_update, - ExpectNonEmptyPlan: true, // Because admin_state_up remains false, unfinished elb? - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("flexibleengine_lb_member_v2.member_1", "weight", "10"), - resource.TestCheckResourceAttr("flexibleengine_lb_member_v2.member_2", "weight", "15"), - ), - }, - }, - }) -} - -func testAccCheckLBV2MemberDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_member_v2" { - continue - } - - poolId := rs.Primary.Attributes["pool_id"] - _, err := pools.GetMember(lbClient, poolId, rs.Primary.ID).Extract() - if err == nil { - return fmt.Errorf("Member still exists: %s", rs.Primary.ID) - } - } - - return nil -} - -func testAccCheckLBV2MemberExists(n string, member *pools.Member) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - poolId := rs.Primary.Attributes["pool_id"] - found, err := pools.GetMember(lbClient, poolId, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmt.Errorf("Member not found") - } - - *member = *found - - return nil - } -} - -var testAccLBV2MemberConfig_basic = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_1" - vip_subnet_id = "%[1]s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_1" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_pool_v2" "pool_1" { - name = "pool_1" - protocol = "HTTP" - lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} - -resource "flexibleengine_lb_member_v2" "member_1" { - address = "172.16.10.10" - protocol_port = 8080 - pool_id = flexibleengine_lb_pool_v2.pool_1.id - subnet_id = "%[1]s" -} - -resource "flexibleengine_lb_member_v2" "member_2" { - address = "172.16.10.11" - protocol_port = 8080 - pool_id = flexibleengine_lb_pool_v2.pool_1.id - subnet_id = "%[1]s" -} -`, OS_SUBNET_ID) - -var testAccLBV2MemberConfig_update = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_1" - vip_subnet_id = "%[1]s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_1" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_pool_v2" "pool_1" { - name = "pool_1" - protocol = "HTTP" - lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} - -resource "flexibleengine_lb_member_v2" "member_1" { - address = "172.16.10.10" - protocol_port = 8080 - weight = 10 - admin_state_up = "true" - pool_id = flexibleengine_lb_pool_v2.pool_1.id - subnet_id = "%[1]s" -} - -resource "flexibleengine_lb_member_v2" "member_2" { - address = "172.16.10.11" - protocol_port = 8080 - weight = 15 - admin_state_up = "true" - pool_id = flexibleengine_lb_pool_v2.pool_1.id - subnet_id = "%[1]s" -} -`, OS_SUBNET_ID) diff --git a/flexibleengine/resource_flexibleengine_lb_monitor_v2_test.go b/flexibleengine/resource_flexibleengine_lb_monitor_v2_test.go deleted file mode 100644 index 6ba97bc37..000000000 --- a/flexibleengine/resource_flexibleengine_lb_monitor_v2_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package flexibleengine - -import ( - "fmt" - "testing" - - "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/monitors" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccLBV2Monitor_basic(t *testing.T) { - var monitor monitors.Monitor - rand := acctest.RandString(5) - resourceName := "flexibleengine_lb_monitor_v2.monitor_1" - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2MonitorDestroy, - Steps: []resource.TestStep{ - { - Config: testAccLBV2MonitorConfig_basic(rand), - Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2MonitorExists(t, resourceName, &monitor), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("monitor_%s", rand)), - resource.TestCheckResourceAttr(resourceName, "delay", "20"), - resource.TestCheckResourceAttr(resourceName, "timeout", "10"), - resource.TestCheckResourceAttr(resourceName, "max_retries", "5"), - resource.TestCheckResourceAttr(resourceName, "port", "8888"), - ), - }, - { - Config: testAccLBV2MonitorConfig_update(rand), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("monitor_%s_updated", rand)), - resource.TestCheckResourceAttr(resourceName, "delay", "30"), - resource.TestCheckResourceAttr(resourceName, "timeout", "15"), - resource.TestCheckResourceAttr(resourceName, "max_retries", "10"), - resource.TestCheckResourceAttr(resourceName, "port", "9999"), - ), - }, - }, - }) -} - -func testAccCheckLBV2MonitorDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_monitor_v2" { - continue - } - - _, err := monitors.Get(lbClient, rs.Primary.ID).Extract() - if err == nil { - return fmt.Errorf("Monitor still exists: %s", rs.Primary.ID) - } - } - - return nil -} - -func testAccCheckLBV2MonitorExists(t *testing.T, n string, monitor *monitors.Monitor) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - found, err := monitors.Get(lbClient, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmt.Errorf("Monitor not found") - } - - *monitor = *found - - return nil - } -} - -func testAccLBV2MonitorConfig_basic(rand string) string { - return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_%s" - vip_subnet_id = "%s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_%s" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_pool_v2" "pool_1" { - name = "pool_%s" - protocol = "HTTP" - lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} - -resource "flexibleengine_lb_monitor_v2" "monitor_1" { - name = "monitor_%s" - type = "PING" - delay = 20 - timeout = 10 - max_retries = 5 - pool_id = flexibleengine_lb_pool_v2.pool_1.id - port = 8888 -} -`, rand, OS_SUBNET_ID, rand, rand, rand) -} - -func testAccLBV2MonitorConfig_update(rand string) string { - return fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_%s" - vip_subnet_id = "%s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_%s" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_pool_v2" "pool_1" { - name = "pool_%s" - protocol = "HTTP" - lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} - -resource "flexibleengine_lb_monitor_v2" "monitor_1" { - name = "monitor_%s_updated" - type = "PING" - delay = 30 - timeout = 15 - max_retries = 10 - admin_state_up = "true" - pool_id = flexibleengine_lb_pool_v2.pool_1.id - port = 9999 -} -`, rand, OS_SUBNET_ID, rand, rand, rand) -} diff --git a/flexibleengine/resource_flexibleengine_lb_pool_v2.go b/flexibleengine/resource_flexibleengine_lb_pool.go similarity index 100% rename from flexibleengine/resource_flexibleengine_lb_pool_v2.go rename to flexibleengine/resource_flexibleengine_lb_pool.go diff --git a/flexibleengine/resource_flexibleengine_lb_pool_v2_test.go b/flexibleengine/resource_flexibleengine_lb_pool_test.go similarity index 73% rename from flexibleengine/resource_flexibleengine_lb_pool_v2_test.go rename to flexibleengine/resource_flexibleengine_lb_pool_test.go index 46f18ce54..dfde278fb 100644 --- a/flexibleengine/resource_flexibleengine_lb_pool_v2_test.go +++ b/flexibleengine/resource_flexibleengine_lb_pool_test.go @@ -20,14 +20,14 @@ func TestAccLBV2Pool_basic(t *testing.T) { { Config: testAccLBV2PoolConfig_basic, Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2PoolExists("flexibleengine_lb_pool_v2.pool_1", &pool), - resource.TestCheckResourceAttr("flexibleengine_lb_pool_v2.pool_1", "name", "pool_1"), + testAccCheckLBV2PoolExists("flexibleengine_lb_pool.pool_1", &pool), + resource.TestCheckResourceAttr("flexibleengine_lb_pool.pool_1", "name", "pool_1"), ), }, { Config: testAccLBV2PoolConfig_update, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("flexibleengine_lb_pool_v2.pool_1", "name", "pool_1_updated"), + resource.TestCheckResourceAttr("flexibleengine_lb_pool.pool_1", "name", "pool_1_updated"), ), }, }, @@ -42,7 +42,7 @@ func testAccCheckLBV2PoolDestroy(s *terraform.State) error { } for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_pool_v2" { + if rs.Type != "flexibleengine_lb_pool" { continue } @@ -88,44 +88,44 @@ func testAccCheckLBV2PoolExists(n string, pool *pools.Pool) resource.TestCheckFu } var testAccLBV2PoolConfig_basic = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener_1" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "pool_1" protocol = "HTTP" lb_method = "ROUND_ROBIN" - listener_id = flexibleengine_lb_listener_v2.listener_1.id + listener_id = flexibleengine_lb_listener.listener_1.id } `, OS_SUBNET_ID) var testAccLBV2PoolConfig_update = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { +resource "flexibleengine_lb_loadbalancer" "loadbalancer_1" { name = "loadbalancer_1" vip_subnet_id = "%s" } -resource "flexibleengine_lb_listener_v2" "listener_1" { +resource "flexibleengine_lb_listener" "listener_1" { name = "listener_1" protocol = "HTTP" protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id + loadbalancer_id = flexibleengine_lb_loadbalancer.loadbalancer_1.id } -resource "flexibleengine_lb_pool_v2" "pool_1" { +resource "flexibleengine_lb_pool" "pool_1" { name = "pool_1_updated" protocol = "HTTP" lb_method = "LEAST_CONNECTIONS" admin_state_up = "true" - listener_id = flexibleengine_lb_listener_v2.listener_1.id + listener_id = flexibleengine_lb_listener.listener_1.id } `, OS_SUBNET_ID) diff --git a/flexibleengine/resource_flexibleengine_lb_whitelist_v2_test.go b/flexibleengine/resource_flexibleengine_lb_whitelist_v2_test.go deleted file mode 100644 index 9f0ddb128..000000000 --- a/flexibleengine/resource_flexibleengine_lb_whitelist_v2_test.go +++ /dev/null @@ -1,127 +0,0 @@ -package flexibleengine - -import ( - "fmt" - "testing" - - "github.com/chnsz/golangsdk/openstack/networking/v2/extensions/lbaas_v2/whitelists" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -func TestAccLBV2Whitelist_basic(t *testing.T) { - var whitelist whitelists.Whitelist - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckLBV2WhitelistDestroy, - Steps: []resource.TestStep{ - { - Config: testAccLBV2WhitelistConfig_basic, - Check: resource.ComposeTestCheckFunc( - testAccCheckLBV2WhitelistExists("flexibleengine_lb_whitelist_v2.whitelist_1", &whitelist), - ), - }, - { - Config: testAccLBV2WhitelistConfig_update, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("flexibleengine_lb_whitelist_v2.whitelist_1", "enable_whitelist", "true"), - ), - }, - }, - }) -} - -func testAccCheckLBV2WhitelistDestroy(s *terraform.State) error { - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - for _, rs := range s.RootModule().Resources { - if rs.Type != "flexibleengine_lb_whitelist_v2" { - continue - } - - _, err := whitelists.Get(lbClient, rs.Primary.ID).Extract() - if err == nil { - return fmt.Errorf("Whitelist still exists: %s", rs.Primary.ID) - } - } - - return nil -} - -func testAccCheckLBV2WhitelistExists(n string, whitelist *whitelists.Whitelist) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - - if rs.Primary.ID == "" { - return fmt.Errorf("No ID is set") - } - - config := testAccProvider.Meta().(*Config) - lbClient, err := config.ElbV2Client(OS_REGION_NAME) - if err != nil { - return fmt.Errorf("Error creating FlexibleEngine ELB v2.0 client: %s", err) - } - - found, err := whitelists.Get(lbClient, rs.Primary.ID).Extract() - if err != nil { - return err - } - - if found.ID != rs.Primary.ID { - return fmt.Errorf("Whitelist not found") - } - - *whitelist = *found - - return nil - } -} - -var testAccLBV2WhitelistConfig_basic = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_1" - vip_subnet_id = "%s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_1" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_whitelist_v2" "whitelist_1" { - enable_whitelist = true - whitelist = "192.168.11.1,192.168.0.1/24" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} -`, OS_SUBNET_ID) - -var testAccLBV2WhitelistConfig_update = fmt.Sprintf(` -resource "flexibleengine_lb_loadbalancer_v2" "loadbalancer_1" { - name = "loadbalancer_1" - vip_subnet_id = "%s" -} - -resource "flexibleengine_lb_listener_v2" "listener_1" { - name = "listener_1" - protocol = "HTTP" - protocol_port = 8080 - loadbalancer_id = flexibleengine_lb_loadbalancer_v2.loadbalancer_1.id -} - -resource "flexibleengine_lb_whitelist_v2" "whitelist_1" { - enable_whitelist = true - whitelist = "192.168.11.1,192.168.0.1/24,192.168.201.18/8" - listener_id = flexibleengine_lb_listener_v2.listener_1.id -} -`, OS_SUBNET_ID)