-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workspace/app): add data source to query authorizations (#5930)
- Loading branch information
1 parent
39e78ac
commit b4a4d1d
Showing
5 changed files
with
377 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
subcategory: "Workspace" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_workspace_app_group_authorizations" | ||
description: |- | ||
Use this data source to get the list of the application group authorizations within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_workspace_app_group_authorizations | ||
|
||
Use this data source to get the list of the application group authorizations within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
### Query all application group authorizations | ||
|
||
```hcl | ||
data "huaweicloud_workspace_app_group_authorizations" "test" {} | ||
``` | ||
|
||
### Query the application group authorizations that contains the same name segment and the account type is USER | ||
|
||
```hcl | ||
variable "account_name_prefix" {} | ||
data "huaweicloud_workspace_app_group_authorizations" "test" { | ||
account = var.account_name_prefix | ||
account_type = "USER" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the authorizations. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `app_group_id` - (Optional, String) Specifies the authorized application group ID. | ||
|
||
* `account` - (Optional, String) Specifies the name of the authorized account. Fuzzy search is supported. | ||
|
||
* `account_type` - (Optional, String) Specifies the type of the authorized account. | ||
The valid values are as follows: | ||
+ **USER** | ||
+ **USER_GROUP** | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `authorizations` - All authorizations that match the filter parameters. | ||
|
||
The [authorizations](#app_group_authorizations) structure is documented below. | ||
|
||
<a name="app_group_authorizations"></a> | ||
The `authorizations` block supports: | ||
|
||
* `id` - The authorized ID. | ||
|
||
* `account_id` - The ID of the authorized account. | ||
|
||
* `account` - The name of the authorized account. | ||
|
||
* `account_type` - The type of the authorized account. | ||
|
||
* `app_group_id` - The application group ID corresponding to the authorized account. | ||
|
||
* `app_group_name` - The application group name corresponding to the authorized account. | ||
|
||
* `created_at` - The time when the account is authorized to the specified application group, in RFC3339 format. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...s/acceptance/workspace/data_source_huaweicloud_workspace_app_group_authorizations_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package workspace | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceAppGroupAuthorizations_basic(t *testing.T) { | ||
var ( | ||
rName = acceptance.RandomAccResourceName() | ||
dataSource = "data.huaweicloud_workspace_app_group_authorizations.test" | ||
dc = acceptance.InitDataSourceCheck(dataSource) | ||
|
||
byAppGroupId = "data.huaweicloud_workspace_app_group_authorizations.filter_by_app_group_id" | ||
dcByAppGroupId = acceptance.InitDataSourceCheck(byAppGroupId) | ||
|
||
byAccount = "data.huaweicloud_workspace_app_group_authorizations.filter_by_account" | ||
dcByAccount = acceptance.InitDataSourceCheck(byAccount) | ||
|
||
byAccountType = "data.huaweicloud_workspace_app_group_authorizations.filter_by_account_type" | ||
dcByAccountType = acceptance.InitDataSourceCheck(byAccountType) | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckWorkspaceAppServerGroup(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceAppGroupAuthorizations_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestMatchResourceAttr(dataSource, "authorizations.#", regexp.MustCompile(`^[1-9]([0-9]*)?$`)), | ||
dcByAppGroupId.CheckResourceExists(), | ||
resource.TestCheckOutput("is_app_group_id_filter_useful", "true"), | ||
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.id"), | ||
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.account_id"), | ||
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.app_group_id"), | ||
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.app_group_name"), | ||
resource.TestMatchResourceAttr(byAppGroupId, "authorizations.0.created_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
dcByAccount.CheckResourceExists(), | ||
resource.TestCheckOutput("is_account_filter_useful", "true"), | ||
dcByAccountType.CheckResourceExists(), | ||
resource.TestCheckOutput("is_account_type_filter_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceAppGroupAuthorizations_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "huaweicloud_workspace_app_group_authorizations" "test" { | ||
depends_on = [huaweicloud_workspace_app_group_authorization.test] | ||
} | ||
locals { | ||
app_group_id = huaweicloud_workspace_app_group.test.id | ||
authorized_account = huaweicloud_workspace_app_group_authorization.test.accounts[0].account | ||
authorized_account_type = huaweicloud_workspace_app_group_authorization.test.accounts[0].type | ||
} | ||
data "huaweicloud_workspace_app_group_authorizations" "filter_by_app_group_id" { | ||
depends_on = [huaweicloud_workspace_app_group_authorization.test] | ||
app_group_id = local.app_group_id | ||
} | ||
locals { | ||
app_group_id_filter_result = [ | ||
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_app_group_id.authorizations[*].app_group_id : v == local.app_group_id | ||
] | ||
} | ||
output "is_app_group_id_filter_useful" { | ||
value = length(local.app_group_id_filter_result) > 0 && alltrue(local.app_group_id_filter_result) | ||
} | ||
# Fuzzy search is supported. | ||
data "huaweicloud_workspace_app_group_authorizations" "filter_by_account" { | ||
depends_on = [huaweicloud_workspace_app_group_authorization.test] | ||
account = local.authorized_account | ||
} | ||
locals { | ||
account_filter_result = [ | ||
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_account.authorizations[*].account : | ||
strcontains(v, local.authorized_account) | ||
] | ||
} | ||
output "is_account_filter_useful" { | ||
value = length(local.account_filter_result) > 0 && alltrue(local.account_filter_result) | ||
} | ||
data "huaweicloud_workspace_app_group_authorizations" "filter_by_account_type" { | ||
depends_on = [huaweicloud_workspace_app_group_authorization.test] | ||
account_type = local.authorized_account_type | ||
} | ||
locals { | ||
account_type_filter_result = [ | ||
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_account_type.authorizations[*].account_type : | ||
v == local.authorized_account_type | ||
] | ||
} | ||
output "is_account_type_filter_useful" { | ||
value = length(local.account_type_filter_result) > 0 && alltrue(local.account_type_filter_result) | ||
} | ||
`, testAccAppGroupAuthorization_basic(name)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.