Skip to content

Commit

Permalink
feat(workspace/warehouse_app): add resource to manage warehouse app
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhuanhong committed Nov 15, 2024
1 parent de71d65 commit abc5287
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 0 deletions.
110 changes: 110 additions & 0 deletions docs/resources/workspace_app_warehouse_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
subcategory: "Workspace"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_workspace_app_warehouse_app"
description: |-
Use this resource to add a application to Workspace APP warehouse within HuaweiCloud.
---

# huaweicloud_workspace_app_warehouse_app

Use this resource to add a application to Workspace APP warehouse within HuaweiCloud.

## Example Usage

```hcl
var "application_name" {}
var "version" {}
var "version_name" {}
var "file_store_obs_path" {}
resource "huaweicloud_workspace_app_warehouse_app" "test" {
name = var.application_name
category = "OTHER"
os_type = "Windows"
version = var.version
version_name = var.version_name
file_store_path = var.file_store_obs_path
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used.
Changing this creates a new resource.

* `name` - (Required, String) The name of the application.
The valid length is limited from `1` to `64`, only Chinese and English characters, digits, underscores (_) and
hyphens (-) are allowed.

* `category` - (Required, String) The category of the application.
The vaild values are as follows:
+ **GAME**
+ **SECURE_STORAGE**
+ **MULTIMEDIA_AND_CODING**
+ **PROJECT_MANAGEMENT**
+ **PRODUCTIVITY_AND_COLLABORATION**
+ **GRAPHIC_DESIGN**
+ **OTHER**

* `os_type` - (Required, String) The operating system type of the application.
The valid values are as follows:
+ **Windows**
+ **Linux**
+ **Other**

* `version` - (Required, String) The version of the application.
The valid length is limited from `1` to `64` and cannot contain spaces.

* `version_name` - (Required, String) The version name of the application.
The valid length is limited from `1` to `64` and cannot contain spaces.

* `file_store_path` - (Required, String, ForceNew) The storage path of the OBS bucket where the application is located.
Changing this creates a new resource.

-> 1.The OBS bucket name where the uploaded file is located must consist of `wks-app` and the project ID, connected by
a hyphen (-). e.g. `wks-app-0970dd7a1300f5672ff2c003c60ae115`.<br>2.The path is the relative path of the file in the
OBS bucket. For example, the relative path of the `https:/xxx.xxx.com/file/workspace_app.exe` file is
`file/workspace_app.exe`.<br>3.Deleting the resource to which this `file_store_path` belongs, the file in the OBS
storage path will also be deleted synchronously.

* `description` - (Optional, String) The description of the application.

* `icon` - (Optional, String) The icon of the application.
The valid value ranges from `0` to `10,977`.

## Attribute Reference

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

* `id` - The resource ID, also application ID.

## Import

The resource can be imported using `id`, e.g.

```bash
$ terraform import huaweicloud_workspace_app_warehouse_app.test <id>
```

Note that the imported state may not be identical to your resource definition, due to some attributes missing from the
API response, security or some other reason.
The missing attributes include: `icon`.
It is generally recommended running `terraform plan` after importing the resource.
You can then decide if changes should be applied to the instance, or the resource definition should be updated to
align with the instance. Also you can ignore changes as below.

```hcl
resource "huaweicloud_workspace_app_warehouse_app" "test" {
...
lifecycle {
ignore_changes = [
icon,
]
}
}
```
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,7 @@ func Provider() *schema.Provider {
"huaweicloud_workspace_app_policy_group": workspace.ResourceAppPolicyGroup(),
"huaweicloud_workspace_app_publishment": workspace.ResourceAppPublishment(),
"huaweicloud_workspace_app_server_group": workspace.ResourceAppServerGroup(),
"huaweicloud_workspace_app_warehouse_app": workspace.ResourceWarehouseApplication(),
"huaweicloud_workspace_user_group": workspace.ResourceUserGroup(),
"huaweicloud_workspace_access_policy": workspace.ResourceAccessPolicy(),
"huaweicloud_workspace_desktop_name_rule": workspace.ResourceDesktopNameRule(),
Expand Down
8 changes: 8 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ var (
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_ID = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_ID")
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID")
HW_WORKSPACE_OU_NAME = os.Getenv("HW_WORKSPACE_OU_NAME")
HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH = os.Getenv("HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH")

HW_FGS_AGENCY_NAME = os.Getenv("HW_FGS_AGENCY_NAME")
HW_FGS_TEMPLATE_ID = os.Getenv("HW_FGS_TEMPLATE_ID")
Expand Down Expand Up @@ -1503,6 +1504,13 @@ func TestAccPreCheckWorkspaceOUName(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckWorkspaceFileStorePath(t *testing.T) {
if HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH == "" {
t.Skip("HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH must be set for Workspace service acceptance tests.")
}
}

// lintignore:AT003
func TestAccPreCheckER(t *testing.T) {
if HW_ER_TEST_ON == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package workspace

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/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/workspace"
)

func getWarehouseApplicationFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.NewServiceClient("appstream", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating Workspace APP client: %s", err)
}
return workspace.GetWarehouseApplicationById(client, state.Primary.ID)
}

func TestAccAppWarehouseApp_basic(t *testing.T) {
var (
application interface{}
resourceName = "huaweicloud_workspace_app_warehouse_app.test"
name = acceptance.RandomAccResourceName()
updateName = acceptance.RandomAccResourceName()
rc = acceptance.InitResourceCheck(
resourceName,
&application,
getWarehouseApplicationFunc,
)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceFileStorePath(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccWarehouseApp_basic_step1(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "category", "OTHER"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"),
resource.TestCheckResourceAttr(resourceName, "version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "version_name", "terraform"),
resource.TestCheckResourceAttr(resourceName, "file_store_path", acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH),
resource.TestCheckResourceAttr(resourceName, "description", "Created by script"),
),
},
{
Config: testAccWarehouseApp_basic_step2(updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", updateName),
resource.TestCheckResourceAttr(resourceName, "category", "PRODUCTIVITY_AND_COLLABORATION"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"),
resource.TestCheckResourceAttr(resourceName, "version", "2.0"),
resource.TestCheckResourceAttr(resourceName, "version_name", "terraform_update"),
resource.TestCheckResourceAttr(resourceName, "description", "Updated by script"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"icon",
},
},
},
})
}

func testAccWarehouseApp_basic_step1(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_workspace_app_warehouse_app" "test" {
name = "%[1]s"
category = "OTHER"
os_type = "Windows"
version = "1.0"
version_name = "terraform"
file_store_path = "%[2]s"
description = "Created by script"
}
`, name, acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH)
}

func testAccWarehouseApp_basic_step2(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_workspace_app_warehouse_app" "test" {
name = "%[1]s"
category = "PRODUCTIVITY_AND_COLLABORATION"
os_type = "Linux"
version = "2.0"
version_name = "terraform_update"
file_store_path = "%[2]s"
description = "Updated by script"
}
`, name, acceptance.HW_WORKSPACE_APP_FILE_STRORE_OBS_PATH)
}
Loading

0 comments on commit abc5287

Please sign in to comment.