diff --git a/docs/data-sources/lb_certificate_v2.md b/docs/data-sources/lb_certificate_v2.md index 3313c124..405c9975 100644 --- a/docs/data-sources/lb_certificate_v2.md +++ b/docs/data-sources/lb_certificate_v2.md @@ -4,7 +4,7 @@ subcategory: "Elastic Load Balance (ELB)" # flexibleengine_lb_certificate_v2 -flexibleengine_lb_certificate_v2 provides details about a specific Certificate. +Use this data source to get the certificate details in FlexibleEngine Elastic Load Balance (ELB). ## Example Usage diff --git a/docs/data-sources/lb_listeners_v2.md b/docs/data-sources/lb_listeners_v2.md new file mode 100644 index 00000000..9dfb8715 --- /dev/null +++ b/docs/data-sources/lb_listeners_v2.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/resources/lb_logtank_v3.md b/docs/resources/lb_logtank_v3.md new file mode 100644 index 00000000..01e44878 --- /dev/null +++ b/docs/resources/lb_logtank_v3.md @@ -0,0 +1,49 @@ +--- +subcategory: "Dedicated Load Balance (Dedicated ELB)" +--- + +# flexibleengine_lb_logtank_v3 + +Manage an LB logtank resource within FlexibleEngine. + +## Example Usage + +```hcl +variable "loadbalancer_id" {} +variable "group_id" {} +variable "topic_id" {} + +resource "flexibleengine_lb_logtank_v3" "test" { + loadbalancer_id = var.loadbalancer_id + log_group_id = var.group_id + log_topic_id = var.topic_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String, ForceNew) The region in which to create the logtank resource. + If omitted, the provider-level region will be used. Changing this creates a new logtank. + +* `loadbalancer_id` - (Required, String, ForceNew) Specifies the ID of a loadbalancer. Changing this + creates a new logtank. + +* `log_group_id` - (Required, String) Specifies the ID of a log group. It is provided by other service. + +* `log_topic_id` - (Required, String) Specifies the ID of the subscribe topic. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The logtank ID. + +## Import + +LB logtank can be imported using the logtank ID, e.g. + +```bash +terraform import flexibleengine_lb_logtank_v3.test 2f148a75-acd3-4ce7-8f63-d5c9fadab3a0 +``` diff --git a/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go b/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go new file mode 100644 index 00000000..d3fe909e --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_lb_listeners_v2_test.go @@ -0,0 +1,139 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +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") + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDatasourceListeners_basic(rName), + Check: resource.ComposeTestCheckFunc( + dcByName.CheckResourceExists(), + resource.TestCheckOutput("name_query_result_validation", "true"), + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.name"), + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.protocol"), + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.protocol_port"), + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.connection_limit"), + resource.TestCheckResourceAttrSet("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.http2_enable"), + resource.TestCheckResourceAttr("data.flexibleengine_lb_listeners_v2.by_name", + "listeners.0.loadbalancers.#", "1"), + dcByProtocol.CheckResourceExists(), + resource.TestCheckOutput("protocol_query_result_validation", "true"), + dcByProtocolPort.CheckResourceExists(), + resource.TestCheckOutput("protocol_port_query_result_validation", "true"), + ), + }, + }, + }) +} + +func testAccDatasourceListeners_base(rName string) string { + rCidr := acceptance.RandomCidr() + return fmt.Sprintf(` +variable "listener_configuration" { + type = list(object({ + protocol_port = number + protocol = string + })) + default = [ + {protocol_port = 306, protocol = "TCP"}, + {protocol_port = 406, protocol = "UDP"}, + {protocol_port = 506, protocol = "HTTP"}, + ] +} + +resource "flexibleengine_vpc_v1" "test" { + name = "%[1]s" + cidr = "%[2]s" +} + +resource "flexibleengine_vpc_subnet_v1" "test" { + vpc_id = flexibleengine_vpc_v1.test.id + + name = "%[1]s" + cidr = cidrsubnet(flexibleengine_vpc_v1.test.cidr, 4, 1) + gateway_ip = cidrhost(cidrsubnet(flexibleengine_vpc_v1.test.cidr, 4, 1), 1) +} + +resource "flexibleengine_lb_loadbalancer_v2" "test" { + name = "%[1]s" + vip_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id +} + +resource "flexibleengine_lb_listener_v2" "test" { + count = length(var.listener_configuration) + + loadbalancer_id = flexibleengine_lb_loadbalancer_v2.test.id + + name = "%[1]s-${count.index}" + protocol = var.listener_configuration[count.index]["protocol"] + protocol_port = var.listener_configuration[count.index]["protocol_port"] +} +`, rName, rCidr) +} + +func testAccDatasourceListeners_basic(rName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_lb_listeners_v2" "by_name" { + depends_on = [flexibleengine_lb_listener_v2.test] + + name = flexibleengine_lb_listener_v2.test[0].name +} + +data "flexibleengine_lb_listeners_v2" "by_protocol" { + depends_on = [flexibleengine_lb_listener_v2.test] + + protocol = flexibleengine_lb_listener_v2.test[1].protocol +} + +data "flexibleengine_lb_listeners_v2" "by_protocol_port" { + depends_on = [flexibleengine_lb_listener_v2.test] + + protocol_port = flexibleengine_lb_listener_v2.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) +} + +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) +} + +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) +} +`, testAccDatasourceListeners_base(rName)) +} diff --git a/flexibleengine/acceptance/resource_flexibleengine_lb_logtank_v3_test.go b/flexibleengine/acceptance/resource_flexibleengine_lb_logtank_v3_test.go new file mode 100644 index 00000000..c7e4991c --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_lb_logtank_v3_test.go @@ -0,0 +1,129 @@ +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/v3/logtanks" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getELBLogTankResourceFunc(c *config.Config, state *terraform.ResourceState) (interface{}, error) { + client, err := c.ElbV3Client(OS_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating ELB client: %s", err) + } + return logtanks.Get(client, state.Primary.ID).Extract() +} + +func TestAccElbLogTank_basic(t *testing.T) { + var logTanks logtanks.LogTank + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_lb_logtank_v3.test" + + rc := acceptance.InitResourceCheck( + resourceName, + &logTanks, + getELBLogTankResourceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccElbLogTankConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttrPair(resourceName, "log_group_id", + "flexibleengine_lts_group.test", "id"), + resource.TestCheckResourceAttrPair(resourceName, "log_topic_id", + "flexibleengine_lts_topic.test", "id"), + ), + }, + { + Config: testAccElbLogTankConfig_update(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttrPair(resourceName, "log_group_id", + "flexibleengine_lts_group.test_update", "id"), + resource.TestCheckResourceAttrPair(resourceName, "log_topic_id", + "flexibleengine_lts_topic.test_update", "id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccElbLogTankConfig_base(rName, updateName string) string { + return fmt.Sprintf(` +data "flexibleengine_availability_zones" "test" {} + +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" + gateway_ip = "192.168.0.1" + vpc_id = flexibleengine_vpc_v1.test.id + ipv6_enable = true +} + +resource "flexibleengine_lb_loadbalancer_v3" "test" { + name = "%[1]s" + ipv4_subnet_id = flexibleengine_vpc_subnet_v1.test.ipv4_subnet_id + ipv6_network_id = flexibleengine_vpc_subnet_v1.test.id + + availability_zone = [ + data.flexibleengine_availability_zones.test.names[0] + ] +} + +resource "flexibleengine_lts_group" "%[2]s" { + group_name = "%[2]s" +} + +resource "flexibleengine_lts_topic" "%[2]s" { + group_id = flexibleengine_lts_group.%[2]s.id + topic_name = "%[1]s" +} +`, rName, updateName) +} + +func testAccElbLogTankConfig_basic(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_lb_logtank_v3" "test" { + loadbalancer_id = flexibleengine_lb_loadbalancer_v3.test.id + log_group_id = flexibleengine_lts_group.test.id + log_topic_id = flexibleengine_lts_topic.test.id +} +`, testAccElbLogTankConfig_base(rName, "test")) +} + +func testAccElbLogTankConfig_update(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_lb_logtank_v3" "test" { + loadbalancer_id = flexibleengine_lb_loadbalancer_v3.test.id + log_group_id = flexibleengine_lts_group.test_update.id + log_topic_id = flexibleengine_lts_topic.test_update.id +} +`, testAccElbLogTankConfig_base(rName, "test_update")) +} diff --git a/flexibleengine/data_source_flexibleengine_lb_certificates_v2.go b/flexibleengine/data_source_flexibleengine_lb_certificate_v2.go similarity index 100% rename from flexibleengine/data_source_flexibleengine_lb_certificates_v2.go rename to flexibleengine/data_source_flexibleengine_lb_certificate_v2.go diff --git a/flexibleengine/data_source_flexibleengine_lb_certificates_v2_test.go b/flexibleengine/data_source_flexibleengine_lb_certificate_v2_test.go similarity index 100% rename from flexibleengine/data_source_flexibleengine_lb_certificates_v2_test.go rename to flexibleengine/data_source_flexibleengine_lb_certificate_v2_test.go diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 7b3b7e0d..c25fc6fc 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -322,6 +322,8 @@ func Provider() *schema.Provider { "flexibleengine_fgs_dependencies": fgs.DataSourceFunctionGraphDependencies(), + "flexibleengine_lb_listeners_v2": lb.DataSourceListeners(), + "flexibleengine_gaussdb_cassandra_flavors": gaussdb.DataSourceCassandraFlavors(), "flexibleengine_gaussdb_cassandra_instances": gaussdb.DataSourceGeminiDBInstances(), "flexibleengine_gaussdb_nosql_flavors": gaussdb.DataSourceGaussDBNoSQLFlavors(), @@ -607,6 +609,7 @@ func Provider() *schema.Provider { "flexibleengine_waf_dedicated_domain": ResourceWafDedicatedDomainV1(), "flexibleengine_lb_loadbalancer_v3": elb.ResourceLoadBalancerV3(), + "flexibleengine_lb_logtank_v3": elb.ResourceLogTank(), "flexibleengine_lb_listener_v3": elb.ResourceListenerV3(), "flexibleengine_elb_certificate": elb.ResourceCertificateV3(), "flexibleengine_elb_ipgroup": elb.ResourceIpGroupV3(),