-
Notifications
You must be signed in to change notification settings - Fork 162
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 get list of the image servers
- Loading branch information
1 parent
bac964d
commit d5ce381
Showing
4 changed files
with
476 additions
and
2 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,93 @@ | ||
--- | ||
subcategory: "Workspace" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_workspace_app_image_servers" | ||
description: |- | ||
Use this data source to get the list of the image servers within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_workspace_app_image_servers | ||
|
||
Use this data source to get the list of the image servers within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "huaweicloud_workspace_app_image_servers" "test" {} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `name` - (Optional, String) Specified the name of the image server. | ||
|
||
* `server_id` - (Optional, String) Specified the ID of the image server. | ||
|
||
* `enterprise_project_id` - (Optional, String) Specifies the ID of the enterprise project to which the image server belong. | ||
This parameter is only valid for enterprise users, if omitted, all enterprise project IDs will be queried. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `servers` - All image servers that match the filter parameters. | ||
|
||
The [servers](#servers_struct) structure is documented below. | ||
|
||
<a name="servers_struct"></a> | ||
The `servers` block supports: | ||
|
||
* `id` - The ID of the image server. | ||
|
||
* `name` - The name of the image server. | ||
|
||
* `description` - The description of the image server. | ||
|
||
* `image_generated_product_id` - The ID of the generated image product. | ||
|
||
* `image_id` - The ID of the basic image to which the image server belongs. | ||
|
||
* `image_type` - The type of the basic image to which the image server belongs. | ||
+ **gold**: The market image. | ||
+ **public**: The public image. | ||
+ **private**: The private image. | ||
+ **shared**: The shared image. | ||
+ **other** | ||
|
||
* `spce_code` - The specification code of the basic image to which the image server belongs. | ||
|
||
* `aps_server_group_id` - The ID of the APS server group associated with the image server. | ||
|
||
* `aps_server_id` - The ID of the APS server associated with the image server. | ||
|
||
* `app_group_id` - The ID of the application group associated with the image server. | ||
|
||
* `status` - The current status of the image server. | ||
+ **ACTIVE** | ||
+ **BUILT**: Image task is finished. | ||
+ **ERROR** | ||
|
||
* `authorize_accounts` - The list of authorized users of the application group associated with the image server. | ||
|
||
The [authorize_accounts](#servers_authorize_accounts_struct) structure is documented below. | ||
|
||
* `enterprise_project_id` - The enterprise project ID to which the image server belongs. | ||
|
||
* `created_at` - The creation time of the image server, in RFC3339 format. | ||
|
||
* `updated_at` - The latest update time of the image server, in RFC3339 format. | ||
|
||
<a name="servers_authorize_accounts_struct"></a> | ||
The `authorize_accounts` block supports: | ||
|
||
* `account` - The name of the account. | ||
|
||
* `type` - The type of the account. | ||
|
||
* `domain` - The domain name of the Workspace service. |
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
129 changes: 129 additions & 0 deletions
129
...services/acceptance/workspace/data_source_huaweicloud_workspace_app_image_servers_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,129 @@ | ||
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 TestAccDataSourceAppImageServers_basic(t *testing.T) { | ||
var ( | ||
dataSource = "data.huaweicloud_workspace_app_image_servers.test" | ||
rName = acceptance.RandomAccResourceName() | ||
dc = acceptance.InitDataSourceCheck(dataSource) | ||
|
||
byServerId = "data.huaweicloud_workspace_app_image_servers.filter_by_server_id" | ||
dcByServerId = acceptance.InitDataSourceCheck(byServerId) | ||
|
||
byName = "data.huaweicloud_workspace_app_image_servers.filter_by_name" | ||
dcByName = acceptance.InitDataSourceCheck(byName) | ||
|
||
byEpsId = "data.huaweicloud_workspace_app_image_servers.filter_by_eps_id" | ||
dcByEpsId = acceptance.InitDataSourceCheck(byEpsId) | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckWorkspaceAppServerGroup(t) | ||
acceptance.TestAccPreCheckWorkspaceAppImageSpecCode(t) | ||
acceptance.TestAccPrecheckWorkspaceUserNames(t) | ||
acceptance.TestAccPreCheckWorkspaceOUName(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceAppImageServers_basic(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestMatchResourceAttr(dataSource, "servers.#", regexp.MustCompile(`^[1-9]([0-9]*)?$`)), | ||
dcByServerId.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.image_id"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.image_type"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.spce_code"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.aps_server_group_id"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.aps_server_id"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.app_group_id"), | ||
resource.TestCheckResourceAttrSet(byServerId, "servers.0.status"), | ||
resource.TestCheckResourceAttr(byServerId, "servers.0.authorize_accounts.#", "1"), | ||
resource.TestCheckResourceAttr(byServerId, "servers.0.authorize_accounts.0.type", "USER"), | ||
resource.TestCheckResourceAttr(byServerId, "servers.0.authorize_accounts.0.domain", acceptance.HW_WORKSPACE_AD_DOMAIN_NAME), | ||
resource.TestCheckOutput("is_server_id_filter_useful", "true"), | ||
resource.TestMatchResourceAttr(byServerId, "servers.0.created_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
resource.TestMatchResourceAttr(byServerId, "servers.0.updated_at", | ||
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)), | ||
dcByName.CheckResourceExists(), | ||
resource.TestCheckOutput("is_name_filter_useful", "true"), | ||
dcByEpsId.CheckResourceExists(), | ||
resource.TestCheckOutput("is_eps_id_filter_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceAppImageServers_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
data "huaweicloud_workspace_app_image_servers" "test" { | ||
depends_on = [huaweicloud_workspace_app_image_server.test] | ||
} | ||
locals { | ||
server_id = huaweicloud_workspace_app_image_server.test.id | ||
server_name = huaweicloud_workspace_app_image_server.test.name | ||
eps_id = huaweicloud_workspace_app_image_server.test.enterprise_project_id | ||
} | ||
data "huaweicloud_workspace_app_image_servers" "filter_by_server_id" { | ||
depends_on = [huaweicloud_workspace_app_image_server.test] | ||
server_id = local.server_id | ||
} | ||
locals { | ||
server_id_filter_result = [for v in data.huaweicloud_workspace_app_image_servers.filter_by_server_id.servers[*].id : | ||
v == local.server_id] | ||
} | ||
output "is_server_id_filter_useful" { | ||
value = length(local.server_id_filter_result) == 1 && alltrue(local.server_id_filter_result) | ||
} | ||
data "huaweicloud_workspace_app_image_servers" "filter_by_name" { | ||
depends_on = [huaweicloud_workspace_app_image_server.test] | ||
name = local.server_name | ||
} | ||
locals { | ||
name_filter_result = [for v in data.huaweicloud_workspace_app_image_servers.filter_by_name.servers[*].name : | ||
v == local.server_name] | ||
} | ||
output "is_name_filter_useful" { | ||
value = length(local.server_id_filter_result) > 0 && alltrue(local.server_id_filter_result) | ||
} | ||
data "huaweicloud_workspace_app_image_servers" "filter_by_eps_id" { | ||
depends_on = [huaweicloud_workspace_app_image_server.test] | ||
enterprise_project_id = local.eps_id | ||
} | ||
locals { | ||
eps_id_filter_result = [for v in data.huaweicloud_workspace_app_image_servers.filter_by_eps_id.servers[*].enterprise_project_id : | ||
v == local.eps_id] | ||
} | ||
output "is_eps_id_filter_useful" { | ||
value = length(local.eps_id_filter_result) > 0 && alltrue(local.eps_id_filter_result) | ||
} | ||
`, testResourceAppImageServer_basic(name, "Data source test")) | ||
} |
Oops, something went wrong.