-
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(workspack): add application group authorization resource
- Loading branch information
1 parent
d136157
commit b56410b
Showing
4 changed files
with
429 additions
and
11 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,80 @@ | ||
--- | ||
subcategory: "Workspace" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_workspace_app_group_authorization" | ||
description: |- | ||
Manages an APP group authorization resource within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_workspace_app_group_authorization | ||
|
||
Manages an APP group authorization resource within HuaweiCloud. | ||
|
||
-> Deleting this resource will revoke authorization for the users or user groups. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "app_group_id" {} | ||
variable "user_groups" { | ||
type = list(object({ | ||
id = string | ||
name = string | ||
})) | ||
} | ||
resource "huaweicloud_workspace_app_group_authorization" "test" { | ||
app_group_id = var.app_group_id | ||
dynamic "accounts" { | ||
for_each = var.user_groups | ||
content { | ||
id = accounts.value.id | ||
account = accounts.value.name | ||
type = "USER_GROUP" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 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. | ||
|
||
* `app_group_id` - (Required, String, ForceNew) Specifies the ID of the application group. | ||
Changing this creates a new resource. | ||
|
||
* `accounts` - (Required, List, ForceNew) Specifies the list of the accounts to be authorized. The maximum length is `50`. | ||
Changing this creates a new resource. | ||
The [accounts](#app_group_auth_accounts) structure is documented below. | ||
|
||
-> If the parameter contains non-existent objects, the resource creation will fail, but the remaining existing objects | ||
will be authorized successfully. | ||
|
||
<a name="app_group_auth_accounts"></a> | ||
The `accounts` block supports: | ||
|
||
* `id` - (Optional, String, ForceNew) Specifies the ID of the user (group). | ||
Changing this creates a new resource. | ||
This parameter is required when `type` is set to **USER_GROUP**. | ||
|
||
* `account` - (Required, String, ForceNew) Specifies the name of the user (group). | ||
Changing this creates a new resource. | ||
|
||
* `type` - (Required, String, ForceNew) Specifies the type of the object to be authorized. | ||
Changing this creates a new resource. | ||
The valid values are as follows: | ||
+ **USER**: | ||
+ **USER_GROUP**: | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The resource ID (also `app_group_id`). |
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
118 changes: 118 additions & 0 deletions
118
...vices/acceptance/workspace/resource_huaweicloud_workspace_app_group_authorization_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,118 @@ | ||
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 TestAccResourceAppGroupAuthorization_basic(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckWorkspaceAppServerGroupId(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAppGroupAuthorization_basic(name), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAppGroupAuthorization_base(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_workspace_user" "test" { | ||
name = "%[2]s" | ||
email = "[email protected]" | ||
} | ||
resource "huaweicloud_workspace_user_group" "test" { | ||
count = 2 | ||
name = "%[2]s${count.index}" | ||
type = "LOCAL" | ||
} | ||
`, testResourceWorkspaceAppGroup_basic_step1(name), name) | ||
} | ||
|
||
func testAccAppGroupAuthorization_basic(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_workspace_app_group_authorization" "test" { | ||
app_group_id = huaweicloud_workspace_app_group.test.id | ||
accounts { | ||
account = huaweicloud_workspace_user.test.name | ||
type = "USER" | ||
} | ||
dynamic "accounts" { | ||
for_each = huaweicloud_workspace_user_group.test[*] | ||
content { | ||
id = accounts.value.id | ||
account = accounts.value.name | ||
type = "USER_GROUP" | ||
} | ||
} | ||
} | ||
`, testAccAppGroupAuthorization_base(name)) | ||
} | ||
|
||
func TestAccResourceAppGroupAuthorization_expectErr(t *testing.T) { | ||
name := acceptance.RandomAccResourceName() | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckWorkspaceAppServerGroupId(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
CheckDestroy: nil, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAppGroupAuthorization_expectErr(name), | ||
ExpectError: regexp.MustCompile(`unable to authorize for some accounts: not_exist_user_group_tf | USER`), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAppGroupAuthorization_expectErr(name string) string { | ||
return fmt.Sprintf(` | ||
%[1]s | ||
resource "huaweicloud_workspace_user" "test" { | ||
count = 2 | ||
name = "%[2]s${count.index}" | ||
email = "[email protected]" | ||
} | ||
resource "huaweicloud_workspace_app_group_authorization" "test" { | ||
app_group_id = huaweicloud_workspace_app_group.test.id | ||
dynamic "accounts" { | ||
for_each = huaweicloud_workspace_user.test[*] | ||
content { | ||
account = accounts.value.name | ||
type = "USER" | ||
} | ||
} | ||
accounts { | ||
account = "not_exist_user_group_tf" | ||
type = "USER" | ||
} | ||
} | ||
`, testResourceWorkspaceAppGroup_basic_step1(name), name) | ||
} |
Oops, something went wrong.