Skip to content

Commit

Permalink
feat(identitycenter): add datasource permission set provisionings
Browse files Browse the repository at this point in the history
  • Loading branch information
luoping-12345 committed Jan 2, 2025
1 parent b52b574 commit 40b1d05
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
55 changes: 55 additions & 0 deletions docs/data-sources/identitycenter_permission_set_provisionings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
subcategory: "IAM Identity Center"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_identitycenter_permission_set_provisionings"
description: |-
Use this data source to get the Identity Center permission set provisionings.
---

# huaweicloud_identitycenter_permission_set_provisionings

Use this data source to get the Identity Center permission set provisionings.

## Example Usage

```hcl
variable "instance_id" {}
data "huaweicloud_identitycenter_permission_set_provisionings" "test" {
instance_id = var.instance_id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the resource.
If omitted, the provider-level region will be used.

* `instance_id` - (Required, String) Specifies the ID of an IAM Identity Center instance.

* `status` - (Optional, String) Specifies the status of the permission set provisioning process.
The valid values are as follows:
+ **IN_PROGRESS**
+ **SUCCEEDED**
+ **FAILED**

## Attribute Reference

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

* `id` - The data source ID.

* `provisionings` - The authorization status of a permission set.

The [provisionings](#provisionings_struct) structure is documented below.

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

* `created_at` - The date when a permission set was created.

* `request_id` - The unique ID of a request.

* `status` - The authorization status of a permission set.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ func Provider() *schema.Provider {
"huaweicloud_identitycenter_permission_sets": identitycenter.DataSourceIdentitycenterPermissionSets(),
"huaweicloud_identitycenter_account_provisioning_permission_sets": identitycenter.DataSourceAccountProvisioningPermissionSets(),
"huaweicloud_identitycenter_permission_set_provisioning_accounts": identitycenter.DataSourcePermissionSetProvisioningAccounts(),
"huaweicloud_identitycenter_permission_set_provisionings": identitycenter.DataSourceIdentitycenterPermissionSetProvisionings(),

"huaweicloud_iec_bandwidths": iec.DataSourceBandWidths(),
"huaweicloud_iec_eips": iec.DataSourceEips(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package identitycenter

import (
"fmt"
"regexp"
"testing"

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

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccDataSourcePermissionSetProvisionings_basic(t *testing.T) {
dataSource := "data.huaweicloud_identitycenter_permission_set_provisionings.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckMultiAccount(t)
acceptance.TestAccPreCheckIdentityCenterAccountId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourcePermissionSetProvisionings_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "provisionings.#"),
resource.TestCheckResourceAttrSet(dataSource, "provisionings.0.request_id"),
resource.TestCheckResourceAttrSet(dataSource, "provisionings.0.status"),
resource.TestMatchResourceAttr(dataSource,
"provisionings.0.created_at", regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
resource.TestCheckOutput("is_status_filter_useful", "true"),
),
},
},
})
}

func testDataSourcePermissionSetProvisionings_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_identitycenter_permission_set_provisionings" "test" {
instance_id = data.huaweicloud_identitycenter_instance.test.id
}
locals {
status = data.huaweicloud_identitycenter_permission_set_provisionings.test.provisionings[0].status
}
data "huaweicloud_identitycenter_permission_set_provisionings" "filter_by_status" {
instance_id = data.huaweicloud_identitycenter_instance.test.id
status = local.status
}
locals {
list_by_status = data.huaweicloud_identitycenter_permission_set_provisionings.filter_by_status.provisionings
}
output "is_status_filter_useful" {
value = length(local.list_by_status) > 0 && alltrue(
[for v in local.list_by_status[*].status : v == local.status]
)
}
`, testProvisionPermissionSet_basic(name))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Generated by PMS #485
package identitycenter

import (
"context"
"strings"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/tidwall/gjson"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/httphelper"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/schemas"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func DataSourceIdentitycenterPermissionSetProvisionings() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIdentitycenterPermissionSetProvisioningsRead,

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Specifies the region in which to query the resource. If omitted, the provider-level region will be used.`,
},
"instance_id": {
Type: schema.TypeString,
Required: true,
Description: `Specifies the ID of an IAM Identity Center instance.`,
},
"status": {
Type: schema.TypeString,
Optional: true,
Description: `Specifies the status of the permission set provisioning process.`,
},
"provisionings": {
Type: schema.TypeList,
Computed: true,
Description: `The authorization status of a permission set.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"created_at": {
Type: schema.TypeString,
Computed: true,
Description: `The date when a permission set was created.`,
},
"request_id": {
Type: schema.TypeString,
Computed: true,
Description: `The unique ID of a request.`,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: `The authorization status of a permission set.`,
},
},
},
},
},
}
}

type PermissionSetProvisioningsDSWrapper struct {
*schemas.ResourceDataWrapper
Config *config.Config
}

func newPermissionSetProvisioningsDSWrapper(d *schema.ResourceData, meta interface{}) *PermissionSetProvisioningsDSWrapper {
return &PermissionSetProvisioningsDSWrapper{
ResourceDataWrapper: schemas.NewSchemaWrapper(d),
Config: meta.(*config.Config),
}
}

func dataSourceIdentitycenterPermissionSetProvisioningsRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
wrapper := newPermissionSetProvisioningsDSWrapper(d, meta)
lisPerSetProStaRst, err := wrapper.ListPermissionSetProvisioningStatus()
if err != nil {
return diag.FromErr(err)
}

id, err := uuid.GenerateUUID()
if err != nil {
return diag.FromErr(err)
}
d.SetId(id)

err = wrapper.listPermissionSetProvisioningStatusToSchema(lisPerSetProStaRst)
if err != nil {
return diag.FromErr(err)
}

return nil
}

// @API IDENTITYCENTER GET /v1/instances/{instance_id}/permission-sets/provisioning-statuses
func (w *PermissionSetProvisioningsDSWrapper) ListPermissionSetProvisioningStatus() (*gjson.Result, error) {
client, err := w.NewClient(w.Config, "identitycenter")
if err != nil {
return nil, err
}

uri := "/v1/instances/{instance_id}/permission-sets/provisioning-statuses"
uri = strings.ReplaceAll(uri, "{instance_id}", w.Get("instance_id").(string))
params := map[string]any{
"status": w.Get("status"),
}
params = utils.RemoveNil(params)
return httphelper.New(client).
Method("GET").
URI(uri).
Query(params).
MarkerPager("permission_sets_provisioning_status", "page_info.next_marker", "marker").
Request().
Result()
}

func (w *PermissionSetProvisioningsDSWrapper) listPermissionSetProvisioningStatusToSchema(body *gjson.Result) error {
d := w.ResourceData
mErr := multierror.Append(nil,
d.Set("region", w.Config.GetRegion(w.ResourceData)),
d.Set("provisionings", schemas.SliceToList(body.Get("permission_sets_provisioning_status"),
func(provisionings gjson.Result) any {
return map[string]any{
"created_at": w.setPerSetProStaCreDate(provisionings),
"request_id": provisionings.Get("request_id").Value(),
"status": provisionings.Get("status").Value(),
}
},
)),
)
return mErr.ErrorOrNil()
}

func (*PermissionSetProvisioningsDSWrapper) setPerSetProStaCreDate(data gjson.Result) string {
return utils.FormatTimeStampRFC3339((data.Get("created_date").Int())/1000, false)
}

0 comments on commit 40b1d05

Please sign in to comment.