oracle / terraform-provider-oci

Terraform Oracle Cloud Infrastructure provider
https://www.terraform.io/docs/providers/oci/
Mozilla Public License 2.0
758 stars 679 forks source link

Unable to get the actual ocid user on the identity_users_data_source #2147

Open ajdurr opened 4 months ago

ajdurr commented 4 months ago

Community Note

Terraform Version and Provider Version

Terraform v1.8.0 on windows_amd64

Affected Resource(s)

affected_data_source = oci_identity_users

Terraform Configuration Files

# Fetch list of users
data "oci_identity_users" "users" {
  for_each = toset(var.user_names)
  compartment_id = var.tenancy_ocid

  filter {
    name         = "name"
    values       = [each.value]
  }
}

resource "oci_identity_user_group_membership" "group_membership" {
    for_each = { for idx, user in data.oci_identity_users.users : idx => user }
    #Required
    group_id = oci_identity_group.group.id
    user_id = each.value.id
}

Plan snippit output

 + resource "oci_identity_user_group_membership" "group_membership" {
      + compartment_id = (known after apply)
      + group_id       = "ocid1.group.oc1..aaaaaaaaoh"
      + id             = (known after apply)
      + inactive_state = (known after apply)
      + state          = (known after apply)
      + time_created   = (known after apply)
      + user_id        = "IdentityUsersDataSource-182991342"
    }

Expected Behavior

Return a ocid User

Actual Behavior

Returns a bogus ID "IdentityUsersDataSource-1829913042"

Steps to Reproduce

  1. terraform apply

References

https://github.com/oracle/oci-go-sdk/blob/master/identity/list_users_request_response.go

https://github.com/oracle/terraform-provider-oci/blob/master/internal/service/identity/identity_users_data_source.go

https://docs.oracle.com/en-us/iaas/tools/dotnet/89.2.0/api/Oci.IdentityService.Requests.ListUsersRequest.html

https://discuss.hashicorp.com/t/hi-i-need-to-get-data-source-for-oci-identity-user/53872

tf-oci-pub commented 3 months ago

Thank you for reporting the issue. We have raised an internal ticket to track this. Our service engineers will get back to you.

jansonkwo commented 2 months ago

Hi,ajdurr

try to change "user_id = each.value.users[0].id", can return a ocid User.

Terraform Configuration Files: resource "oci_identity_user_group_membership" "group_membership" { for_each = { for idx, user in data.oci_identity_users.users : idx => user }

Required

group_id = oci_identity_group.group.id
user_id = each.value.users[0].id

user_id = each.value.id

}