Skip to content
Closed
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
56 changes: 56 additions & 0 deletions docs/resources/workspace_ou.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
subcategory: "Workspace"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_workspace_ou"
description: |-
Manages an OU resource of Workspace within HuaweiCloud.
---
# huaweicloud_workspace_ou

Manages an OU resource of Workspace within HuaweiCloud.

-> Before creating an OU, you need to create OUs on the AD server and register the Workspace service
to connect to the AD domain.

## Example Usage

```hcl
variable "ou_name" {}
variable "ad_domain_name" {}

resource "huaweicloud_workspace_ou" "test" {
name = var.ou_name
domain = var.ad_domain_name
}
```

## 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) Specifies the name of the OU.
The name only allows Chinese and English characters, digits, spaces and special characters (-_$!@*?.).
Multiple levels of OUs are separated by slashes (/) and no space is allowed before or after the slashes (/),
a maximum of five layers of OUs are supported. e.g. `ab/cd/ef`.

* `domain` - (Required, String, ForceNew) Specifies the AD domain name to which the OU belongs.

* `description` - (Optional, String) Specifies the description of the OU.

## Attribute Reference

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

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

## Import

The OU resource can be imported using `name`, e.g.

```bash
$ terraform import huaweicloud_workspace_ou.test <name>
```
3 changes: 2 additions & 1 deletion huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2291,11 +2291,12 @@ func Provider() *schema.Provider {
"huaweicloud_workspace_access_policy": workspace.ResourceAccessPolicy(),
"huaweicloud_workspace_desktop_name_rule": workspace.ResourceDesktopNameRule(),
"huaweicloud_workspace_desktop": workspace.ResourceDesktop(),
"huaweicloud_workspace_eip_associate": workspace.ResourceEipAssociate(),
"huaweicloud_workspace_ou": workspace.ResourceOu(),
"huaweicloud_workspace_policy_group": workspace.ResourcePolicyGroup(),
"huaweicloud_workspace_service": workspace.ResourceService(),
"huaweicloud_workspace_terminal_binding": workspace.ResourceTerminalBinding(),
"huaweicloud_workspace_user": workspace.ResourceUser(),
"huaweicloud_workspace_eip_associate": workspace.ResourceEipAssociate(),

"huaweicloud_cpts_project": cpts.ResourceProject(),
"huaweicloud_cpts_task": cpts.ResourceTask(),
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 @@ -234,6 +234,7 @@ var (
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_PRODUCT_ID")
HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_SPEC_CODE = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_IMAGE_SPEC_CODE")
HW_WORKSPACE_OU_NAME = os.Getenv("HW_WORKSPACE_OU_NAME")
HW_WORKSPACE_OU_UPDATE_NAME = os.Getenv("HW_WORKSPACE_OU_UPDATE_NAME")
HW_WORKSPACE_APP_FILE_NAME = os.Getenv("HW_WORKSPACE_APP_FILE_NAME")
HW_WORKSPACE_USER_NAMES = os.Getenv("HW_WORKSPACE_USER_NAMES")

Expand Down Expand Up @@ -1622,6 +1623,13 @@ func TestAccPreCheckWorkspaceOUName(t *testing.T) {
}
}

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

// lintignore:AT003
func TestAccPreCheckWorkspaceAppFileName(t *testing.T) {
if HW_WORKSPACE_APP_FILE_NAME == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
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 getOuFun(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.NewServiceClient("workspace", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating Workspace client: %s", err)
}

return workspace.GetOuByName(client, state.Primary.Attributes["name"])
}

func TestAccOu_basic(t *testing.T) {
var (
ouObj interface{}
resourceName = "huaweicloud_workspace_ou.test"
rc = acceptance.InitResourceCheck(
resourceName,
&ouObj,
getOuFun,
)
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceAD(t)
acceptance.TestAccPreCheckWorkspaceOUName(t)
acceptance.TestAccPreCheckWorkspaceOUUpdateName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccOu_step1(),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", acceptance.HW_WORKSPACE_OU_NAME),
resource.TestCheckResourceAttrPair(resourceName, "domain",
"huaweicloud_workspace_service.test", "ad_domain.0.name"),
resource.TestCheckResourceAttr(resourceName, "description", "Created by terraform script"),
),
},
{
Config: testAccOu_step2(),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", acceptance.HW_WORKSPACE_OU_UPDATE_NAME),
resource.TestCheckResourceAttr(resourceName, "description", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccOuImportStateFunc(resourceName),
},
},
})
}

func testAccOu_base() string {
return fmt.Sprintf(`
resource "huaweicloud_workspace_service" "test" {
ad_domain {
name = try(element(regexall("\\w+\\.(.*)", element(split(",", "%[1]s"), 0))[0], 0), "")
active_domain_name = element(split(",", "%[1]s"), 0)
active_domain_ip = element(split(",", "%[2]s"), 0)
active_dns_ip = element(split(",", "%[2]s"), 0)
admin_account = "%[3]s"
password = "%[4]s"
delete_computer_object = true
}

auth_type = "LOCAL_AD"
access_mode = "INTERNET"
vpc_id = "%[5]s"
network_ids = ["%[6]s"]
}
`, acceptance.HW_WORKSPACE_AD_DOMAIN_NAMES,
acceptance.HW_WORKSPACE_AD_DOMAIN_IPS,
acceptance.HW_WORKSPACE_AD_SERVER_ACCOUNT,
acceptance.HW_WORKSPACE_AD_SERVER_PWD,
acceptance.HW_WORKSPACE_AD_VPC_ID,
acceptance.HW_WORKSPACE_AD_NETWORK_ID)
}

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

resource "huaweicloud_workspace_ou" "test" {
depends_on = [huaweicloud_workspace_service.test]

name = "%[2]s"
domain = huaweicloud_workspace_service.test.ad_domain[0].name
description = "Created by terraform script"
}
`, testAccOu_base(), acceptance.HW_WORKSPACE_OU_NAME)
}

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

resource "huaweicloud_workspace_ou" "test" {
depends_on = [huaweicloud_workspace_service.test]

name = "%[2]s"
domain = huaweicloud_workspace_service.test.ad_domain[0].name
}
`, testAccOu_base(), acceptance.HW_WORKSPACE_OU_UPDATE_NAME)
}

func testAccOuImportStateFunc(rName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[rName]
if !ok {
return "", fmt.Errorf("resource (%s) not found: %s", rName, rs)
}
ouName := rs.Primary.Attributes["name"]
if ouName == "" {
return "", fmt.Errorf("invalid format specified for import ID, want '<name>', but got '%s'", ouName)
}
return ouName, nil
}
}
Loading
Loading