Skip to content

feat(apig): add apig_groups data source #1076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions docs/data-sources/apig_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
subcategory: "API Gateway (Dedicated APIG)"
---

# flexibleengine_apig_groups

Use this data source to query and filter the group list under the APIG instance within FlexibleEngine.

## Example Usage

```hcl
variable "instance_id" {}
variable "group_name" {}

data "flexibleengine_apig_groups" "test" {
instance_id = var.instance_id
name = var.group_name
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the API group list.
If omitted, the provider-level region will be used.

* `instance_id` - (Required, String) Specifies an ID of the APIG dedicated instance to which the API group belongs.

* `group_id` - (Optional, String) Specifies the API group ID used to query.

* `name` - (Optional, String) Specifies the API group name used to query.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - Data source ID.

* `groups` - All groups that match the filter parameters.
The [groups](#APIG_Groups) structure is documented below.

<a name="APIG_Groups"></a>
The `groups` block supports:

* `id` - The API group ID.

* `name` - The API group name.

* `status` - The current status of the API group.
The valid values are as follows:
+ **1**: Normal.

* `sl_domain` - The subdomain name assigned by the system by default.

* `created_at` - The creation time of the API group.

* `updated_at` - The latest update time of the API group.

* `on_sell_status` - Whether it has been listed on the cloud store.
The valid values are as follows:
+ **1**: Listed.
+ **2**: Not listed.
+ **3**: Under review.

* `url_domains` - List of independent domains bound on the API group.
The [url_domains](#APIG_Groups_urlDomains) structure is documented below.

* `sl_domains` - List of subdomain names assigned by the system by default.

* `description` - The description of the API group.

* `is_default` - Indicates whether the API group is the default group.

* `environment` - The array of one or more environments of the API group.
The [environment](#APIG_Groups_environment_attr) structure is documented below.

<a name="APIG_Groups_urlDomains"></a>
The `url_domains` block supports:

* `id` - The domain ID.

* `name` - The domain name.

* `cname_status` - CNAME resolution status of the domain name.
The valid values are as follows:
+ **1**: Not resolved.
+ **2**: Resolving.
+ **3**: Resolved.
+ **4**: Resolution failed.

* `ssl_id` - The SSL certificate ID.

* `ssl_name` - The SSL certificate name.

* `min_ssl_version` - Minimum SSL version. The default is **TLSv1.1**.
The valid values are as follows:
+ **TLSv1.1**
+ **TLSv1.2**

* `verified_client_certificate_enabled` - Whether to enable client certificate verification.
This parameter is available only when a certificate is bound. It is enabled by default if trusted_root_ca exists,
and disabled if trusted_root_ca does not exist. The default is **false**.

* `is_has_trusted_root_ca` - Whether a trusted root certificate (CA) exists. The value is true
if trusted_root_ca exists in the bound certificate. The default is **false**.

<a name="APIG_Groups_environment_attr"></a>
The `environment` block supports:

* `variable` - The array of one or more environment variables.
The [variable](#APIG_Groups_environment_variable_attr) structure is documented below.

* `environment_id` - The ID of the environment to which the variables belong.

<a name="APIG_Groups_environment_variable_attr"></a>
The `variable` block supports:

* `name` - The variable name.

* `value` - The variable value.

* `id` - The variable ID.
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccGroupsDataSource_basic(t *testing.T) {
var (
dataSourceName = "data.flexibleengine_apig_groups.filter_by_name"
rName = acceptance.RandomAccResourceName()
dc = acceptance.InitDataSourceCheck(dataSourceName)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccGroupsDataSource_filterByName(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckOutput("is_name_filter_useful", "true"),
resource.TestCheckOutput("not_found_validation_pass", "true"),
),
},
},
})
}

func testAccGroupsDataSource_filterByName(name string) string {
return fmt.Sprintf(`
%[1]s

data "flexibleengine_apig_groups" "filter_by_name" {
// The behavior of parameter 'name' is 'Required', means this parameter does not have 'Know After Apply' behavior.
depends_on = [
flexibleengine_apig_group.test,
]

instance_id = flexibleengine_apig_instance.test.id
name = flexibleengine_apig_group.test.name
}

data "flexibleengine_apig_groups" "not_found" {
// Since a specified name is used, there is no dependency relationship with resource attachment, and the dependency
// needs to be manually set.
depends_on = [
flexibleengine_apig_group.test,
]

instance_id = flexibleengine_apig_instance.test.id
name = "resource_not_found"
}

locals {
filter_result = [for v in data.flexibleengine_apig_groups.filter_by_name.groups[*].id : v == flexibleengine_apig_group.test.id]
}

output "is_name_filter_useful" {
value = alltrue(local.filter_result) && length(local.filter_result) > 0
}

output "not_found_validation_pass" {
value = length(data.flexibleengine_apig_groups.not_found.groups) == 0
}
`, testAccApigGroup_basic(name))
}

func TestAccGroupsDataSource_filterById(t *testing.T) {
var (
dataSourceName = "data.flexibleengine_apig_groups.filter_by_id"
rName = acceptance.RandomAccResourceName()
dc = acceptance.InitDataSourceCheck(dataSourceName)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccGroupsDataSource_filterById(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckOutput("is_id_filter_useful", "true"),
resource.TestCheckOutput("not_found_validation_pass", "true"),
),
},
},
})
}

func testAccGroupsDataSource_filterById(name string) string {
randUUID, _ := uuid.GenerateUUID()

return fmt.Sprintf(`
%[1]s

data "flexibleengine_apig_groups" "filter_by_id" {
instance_id = flexibleengine_apig_instance.test.id
group_id = flexibleengine_apig_group.test.id
}

data "flexibleengine_apig_groups" "not_found" {
// Since a random ID is used, there is no dependency relationship with resource attachment, and the dependency needs
// to be manually set.
depends_on = [
flexibleengine_apig_group.test,
]

instance_id = flexibleengine_apig_instance.test.id
group_id = "%[2]s"
}

locals {
filter_result = [for v in data.flexibleengine_apig_groups.filter_by_id.groups[*].id : v == flexibleengine_apig_group.test.id]
}

output "is_id_filter_useful" {
value = alltrue(local.filter_result) && length(local.filter_result) > 0
}

output "not_found_validation_pass" {
value = length(data.flexibleengine_apig_groups.not_found.groups) == 0
}
`, testAccApigGroup_basic(name), randUUID)
}
1 change: 1 addition & 0 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func Provider() *schema.Provider {

// importing new data source
"flexibleengine_apig_environments": apig.DataSourceEnvironments(),
"flexibleengine_apig_groups": apig.DataSourceGroups(),

"flexibleengine_as_configurations": as.DataSourceASConfigurations(),
"flexibleengine_as_groups": as.DataSourceASGroups(),
Expand Down