Skip to content

Commit

Permalink
feat(identitycenter): add datasource access control attribute configu…
Browse files Browse the repository at this point in the history
…rations
  • Loading branch information
luoping-12345 committed Dec 19, 2024
1 parent 818ad5d commit 2a71f16
Show file tree
Hide file tree
Showing 4 changed files with 436 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
subcategory: "IAM Identity Center"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_identitycenter_access_control_attribute_configuration"
description: |-
Manages an Identity Center access control attribute configuration resource within HuaweiCloud.
---

# huaweicloud_identitycenter_access_control_attribute_configuration

Manages an Identity Center access control attribute configuration resource within HuaweiCloud.

## Example Usage

```hcl
variable "instance_id" {}
resource "huaweicloud_identitycenter_access_control_attribute_configuration" "test" {
instance_id = var.instance_id
access_control_attributes {
key = "test"
value = ["$${user:email}"]
}
}
```

## 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.

* `instance_id` - (Required, String, ForceNew) Specifies the ID of the IAM Identity Center instance.
Changing this creates a new resource.

* `access_control_attributes` - (Optional, List) Specifies the properties of ABAC configuration in IAM Identity Center instance.
The [access_control_attributes](#access_control_attributes) structure is documented below.

<a name="access_control_attributes"></a>
The `access_control_attributes` block supports:

* `key` - (Required, String) Specifies the name of the attribute associated with the identity in your identity source.

* `value` - (Required, List) Specifies the value used to map the specified attribute to the identity source.

## Attribute Reference

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

* `id` - The resource ID.
19 changes: 10 additions & 9 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,15 +1764,16 @@ func Provider() *schema.Provider {
"huaweicloud_identity_user_token": iam.ResourceIdentityUserToken(),
"huaweicloud_identity_policy": iam.ResourceIdentityPolicy(),

"huaweicloud_identitycenter_user": identitycenter.ResourceIdentityCenterUser(),
"huaweicloud_identitycenter_group": identitycenter.ResourceIdentityCenterGroup(),
"huaweicloud_identitycenter_group_membership": identitycenter.ResourceGroupMembership(),
"huaweicloud_identitycenter_permission_set": identitycenter.ResourcePermissionSet(),
"huaweicloud_identitycenter_system_policy_attachment": identitycenter.ResourceSystemPolicyAttachment(),
"huaweicloud_identitycenter_system_identity_policy_attachment": identitycenter.ResourceSystemIdentityPolicyAttachment(),
"huaweicloud_identitycenter_account_assignment": identitycenter.ResourceIdentityCenterAccountAssignment(),
"huaweicloud_identitycenter_custom_policy_attachment": identitycenter.ResourceCustomPolicyAttachment(),
"huaweicloud_identitycenter_custom_role_attachment": identitycenter.ResourceCustomRoleAttachment(),
"huaweicloud_identitycenter_user": identitycenter.ResourceIdentityCenterUser(),
"huaweicloud_identitycenter_group": identitycenter.ResourceIdentityCenterGroup(),
"huaweicloud_identitycenter_group_membership": identitycenter.ResourceGroupMembership(),
"huaweicloud_identitycenter_permission_set": identitycenter.ResourcePermissionSet(),
"huaweicloud_identitycenter_system_policy_attachment": identitycenter.ResourceSystemPolicyAttachment(),
"huaweicloud_identitycenter_system_identity_policy_attachment": identitycenter.ResourceSystemIdentityPolicyAttachment(),
"huaweicloud_identitycenter_account_assignment": identitycenter.ResourceIdentityCenterAccountAssignment(),
"huaweicloud_identitycenter_custom_policy_attachment": identitycenter.ResourceCustomPolicyAttachment(),
"huaweicloud_identitycenter_custom_role_attachment": identitycenter.ResourceCustomRoleAttachment(),
"huaweicloud_identitycenter_access_control_attribute_configuration": identitycenter.ResourceAccessControlAttributeConfiguration(),

"huaweicloud_iec_eip": iec.ResourceEip(),
"huaweicloud_iec_keypair": iec.ResourceKeypair(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package identitycenter

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/chnsz/golangsdk"

"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/identitycenter"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func getAccessControlAttributeConfigurationResourceFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
region := acceptance.HW_REGION_NAME
client, err := cfg.NewServiceClient("identitycenter", region)
if err != nil {
return nil, fmt.Errorf("error creating Identity Center client: %s", err)
}

resp, err := identitycenter.GetAccessControlAttributeConfiguration(client, state.Primary.ID)
if err != nil {
return nil, err
}

status := utils.PathSearch("status", resp, "").(string)
if status != "ENABLED" {
return nil, golangsdk.ErrDefault404{}
}

return resp, nil
}

func TestAccAccessControlAttributeConfiguration_basic(t *testing.T) {
var obj interface{}

name := acceptance.RandomAccResourceName()
rName := "huaweicloud_identitycenter_access_control_attribute_configuration.test"

rc := acceptance.InitResourceCheck(
rName,
&obj,
getAccessControlAttributeConfigurationResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckMultiAccount(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccessControlAttributeConfiguration_basic(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttrPair(rName, "instance_id", "data.huaweicloud_identitycenter_instance.system", "id"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.#", "1"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.0.key", name+"_1"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.0.value.0", "${user:email}"),
),
},
{
Config: testAccessControlAttributeConfiguration_update(name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(rName, "instance_id", "data.huaweicloud_identitycenter_instance.system", "id"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.#", "2"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.0.key", name+"_1"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.0.value.0", "${user:email}"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.1.key", name+"_2"),
resource.TestCheckResourceAttr(rName, "access_control_attributes.1.value.0", "${user:familyName}"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"instance_id"},
},
},
})
}

func testAccessControlAttributeConfiguration_basic(name string) string {
return fmt.Sprintf(`
data "huaweicloud_identitycenter_instance" "system" {}
resource "huaweicloud_identitycenter_access_control_attribute_configuration" "test" {
instance_id = data.huaweicloud_identitycenter_instance.system.id
access_control_attributes {
key = "%[1]s_1"
value = ["$${user:email}"]
}
}
`, name)
}

func testAccessControlAttributeConfiguration_update(name string) string {
return fmt.Sprintf(`
data "huaweicloud_identitycenter_instance" "system" {}
resource "huaweicloud_identitycenter_access_control_attribute_configuration" "test" {
instance_id = data.huaweicloud_identitycenter_instance.system.id
access_control_attributes {
key = "%[1]s_1"
value = ["$${user:email}"]
}
access_control_attributes {
key = "%[1]s_2"
value = ["$${user:familyName}"]
}
}
`, name)
}
Loading

0 comments on commit 2a71f16

Please sign in to comment.