Skip to content

Commit

Permalink
refactor(workspace): add a constraint description and refactor test c…
Browse files Browse the repository at this point in the history
…ase (#3929)
  • Loading branch information
wuzhuanhong authored Jan 4, 2024
1 parent a240974 commit b08e1d0
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/resources/workspace_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ The following arguments are supported:

* `internet_access_port` - (Optional, Int) Specifies the internet access port.
The valid value is range from `1,025` to `65,535`.


-> If you want to modify the internet access port, please open a service ticket to enable this function.

* `dedicated_subnets` - (Optional, List) The subnet segments of the dedicated access.

* `management_subnet_cidr` - (Optional, String, ForceNew) The subnet segment of the management component.
Expand Down
9 changes: 9 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ var (
HW_WORKSPACE_AD_DOMAIN_IP = os.Getenv("HW_WORKSPACE_AD_DOMAIN_IP") // Active domain IP, e.g. "192.168.196.3".
HW_WORKSPACE_AD_VPC_ID = os.Getenv("HW_WORKSPACE_AD_VPC_ID") // The VPC ID to which the AD server and desktops belongs.
HW_WORKSPACE_AD_NETWORK_ID = os.Getenv("HW_WORKSPACE_AD_NETWORK_ID") // The network ID to which the AD server belongs.
// The internet access port to which the Workspace service.
HW_WORKSPACE_INTERNET_ACCESS_PORT = os.Getenv("HW_WORKSPACE_INTERNET_ACCESS_PORT")

HW_FGS_TRIGGER_LTS_AGENCY = os.Getenv("HW_FGS_TRIGGER_LTS_AGENCY")

Expand Down Expand Up @@ -769,6 +771,13 @@ func TestAccPreCheckWorkspaceAD(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckWorkspaceInternetAccessPort(t *testing.T) {
if HW_WORKSPACE_INTERNET_ACCESS_PORT == "" {
t.Skip("HW_WORKSPACE_INTERNET_ACCESS_PORT 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
Expand Up @@ -60,7 +60,6 @@ func TestAccService_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "infrastructure_security_group.0.id"),
resource.TestCheckResourceAttrSet(resourceName, "desktop_security_group.0.name"),
resource.TestCheckResourceAttrSet(resourceName, "desktop_security_group.0.id"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_port"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_address"),
resource.TestCheckResourceAttrSet(resourceName, "status"),
),
Expand All @@ -73,7 +72,6 @@ func TestAccService_basic(t *testing.T) {
"huaweicloud_vpc_subnet.master", "id"),
resource.TestCheckResourceAttrPair(resourceName, "network_ids.1",
"huaweicloud_vpc_subnet.standby", "id"),
resource.TestCheckResourceAttr(resourceName, "internet_access_port", "9001"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_address"),
resource.TestCheckResourceAttr(resourceName, "enterprise_id", rName),
resource.TestCheckResourceAttr(resourceName, "enterprise_id", rName),
Expand All @@ -98,6 +96,45 @@ func TestAccService_basic(t *testing.T) {
})
}

func TestAccService_internetAccessPort(t *testing.T) {
var (
service services.Service
resourceName = "huaweicloud_workspace_service.test"
rName = acceptance.RandomAccResourceNameWithDash()
)

rc := acceptance.InitResourceCheck(
resourceName,
&service,
getServiceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceInternetAccessPort(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccService_basic_step1(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_port"),
),
},
{
Config: testAccService_internetAccessPort_update(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "internet_access_port", acceptance.HW_WORKSPACE_INTERNET_ACCESS_PORT),
),
},
},
})
}

func TestAccService_localAD(t *testing.T) {
var (
service services.Service
Expand Down Expand Up @@ -138,7 +175,6 @@ func TestAccService_localAD(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "infrastructure_security_group.0.id"),
resource.TestCheckResourceAttrSet(resourceName, "desktop_security_group.0.name"),
resource.TestCheckResourceAttrSet(resourceName, "desktop_security_group.0.id"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_port"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_address"),
resource.TestCheckResourceAttrSet(resourceName, "status"),
),
Expand All @@ -152,7 +188,6 @@ func TestAccService_localAD(t *testing.T) {
"huaweicloud_vpc_subnet.master", "id"),
resource.TestCheckResourceAttrPair(resourceName, "network_ids.2",
"huaweicloud_vpc_subnet.standby", "id"),
resource.TestCheckResourceAttr(resourceName, "internet_access_port", "9001"),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_address"),
resource.TestCheckResourceAttr(resourceName, "enterprise_id", rName),
resource.TestCheckResourceAttr(resourceName, "otp_config_info.0.enable", "true"),
Expand All @@ -179,6 +214,45 @@ func TestAccService_localAD(t *testing.T) {
})
}

func TestAccService_internetAccessPort_localAD(t *testing.T) {
var (
service services.Service
resourceName = "huaweicloud_workspace_service.test"
rName = acceptance.RandomAccResourceNameWithDash()
)

rc := acceptance.InitResourceCheck(
resourceName,
&service,
getServiceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceInternetAccessPort(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccService_localAD_step1(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(resourceName, "internet_access_port"),
),
},
{
Config: testAccService_localAD_internetAccessPort_update(rName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "internet_access_port", acceptance.HW_WORKSPACE_INTERNET_ACCESS_PORT),
),
},
},
})
}

func testAccService_base(rName string) string {
return fmt.Sprintf(`
resource "huaweicloud_vpc" "test" {
Expand Down Expand Up @@ -230,7 +304,6 @@ resource "huaweicloud_workspace_service" "test" {
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = 9001
enterprise_id = "%[2]s"
otp_config_info {
Expand All @@ -253,7 +326,6 @@ resource "huaweicloud_workspace_service" "test" {
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = 9001
enterprise_id = "%[2]s"
otp_config_info {
Expand Down Expand Up @@ -341,7 +413,6 @@ resource "huaweicloud_workspace_service" "test" {
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = 9001
enterprise_id = "%[7]s"
otp_config_info {
Expand Down Expand Up @@ -382,7 +453,6 @@ resource "huaweicloud_workspace_service" "test" {
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = 9001
enterprise_id = "%[7]s"
otp_config_info {
Expand All @@ -396,3 +466,57 @@ resource "huaweicloud_workspace_service" "test" {
acceptance.HW_WORKSPACE_AD_DOMAIN_IP, acceptance.HW_WORKSPACE_AD_VPC_ID, acceptance.HW_WORKSPACE_AD_NETWORK_ID,
rName)
}

func testAccService_internetAccessPort_update(rName string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_workspace_service" "test" {
access_mode = "INTERNET"
vpc_id = huaweicloud_vpc.test.id
network_ids = [
huaweicloud_vpc_subnet.master.id,
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = "%[2]s"
enterprise_id = "%[3]s"
}
`, testAccService_base(rName), acceptance.HW_WORKSPACE_INTERNET_ACCESS_PORT, rName)
}

func testAccService_localAD_internetAccessPort_update(rName string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_workspace_service" "test" {
depends_on = [
huaweicloud_vpc_subnet.master,
huaweicloud_vpc_subnet.standby,
]
ad_domain {
name = "%[2]s"
admin_account = "Administrator"
password = "%[3]s"
active_domain_ip = "%[4]s"
active_domain_name = "server.%[2]s"
active_dns_ip = "%[4]s"
}
auth_type = "LOCAL_AD"
access_mode = "INTERNET"
vpc_id = "%[5]s"
network_ids = [
"%[6]s",
huaweicloud_vpc_subnet.master.id,
huaweicloud_vpc_subnet.standby.id,
]
internet_access_port = "%[7]s"
enterprise_id = "%[8]s"
}
`, testAccService_localAD_base(rName), acceptance.HW_WORKSPACE_AD_DOMAIN_NAME, acceptance.HW_WORKSPACE_AD_SERVER_PWD,
acceptance.HW_WORKSPACE_AD_DOMAIN_IP, acceptance.HW_WORKSPACE_AD_VPC_ID, acceptance.HW_WORKSPACE_AD_NETWORK_ID,
acceptance.HW_WORKSPACE_INTERNET_ACCESS_PORT, rName)
}

0 comments on commit b08e1d0

Please sign in to comment.