Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renamed ds attributes and prints #213

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions nutanix/data_source_nutanix_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ func dataSourceNutanixUser() *schema.Resource {
return &schema.Resource{
Read: dataSourceNutanixUserRead,
Schema: map[string]*schema.Schema{
"uuid": {
Type: schema.TypeString,
Optional: true,
"user_id": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"user_name"},
},
"name": {
"user_name": {
Type: schema.TypeString,
Optional: true,
ConflictsWith: []string{"uuid"},
ConflictsWith: []string{"user_id"},
},
"api_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -237,11 +238,11 @@ func dataSourceNutanixUserRead(d *schema.ResourceData, meta interface{}) error {
// Get client connection
conn := meta.(*Client).API

uuid, iok := d.GetOk("uuid")
name, nok := d.GetOk("name")
uuid, iok := d.GetOk("user_id")
name, nok := d.GetOk("user_name")

if !iok && !nok {
return fmt.Errorf("please provide one of uuid or name attributes")
return fmt.Errorf("please provide one of user_id or user_name attributes")
}

var reqErr error
Expand All @@ -263,47 +264,47 @@ func dataSourceNutanixUserRead(d *schema.ResourceData, meta interface{}) error {
m, c := setRSEntityMetadata(resp.Metadata)

if err := d.Set("metadata", m); err != nil {
return fmt.Errorf("error setting metadata for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting metadata for user UUID(%s), %s", d.Id(), err)
}
if err := d.Set("categories", c); err != nil {
return fmt.Errorf("error setting categories for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting categories for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("owner_reference", flattenReferenceValues(resp.Metadata.OwnerReference)); err != nil {
return fmt.Errorf("error setting owner_reference for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting owner_reference for user UUID(%s), %s", d.Id(), err)
}
d.Set("api_version", utils.StringValue(resp.APIVersion))
d.Set("name", utils.StringValue(resp.Status.Name))

if err := d.Set("state", resp.Status.State); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("directory_service_user", flattenDirectoryServiceUser(resp.Status.Resources.DirectoryServiceUser)); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("identity_provider_user", flattenIdentityProviderUser(resp.Status.Resources.IdentityProviderUser)); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("user_type", resp.Status.Resources.UserType); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("display_name", resp.Status.Resources.DisplayName); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

if err := d.Set("project_reference_list", flattenArrayReferenceValues(resp.Status.Resources.ProjectsReferenceList)); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

refe := flattenArrayReferenceValues(resp.Status.Resources.AccessControlPolicyReferenceList)
utils.PrintToJSON(refe, "acceess")

if err := d.Set("access_control_policy_reference_list", refe); err != nil {
return fmt.Errorf("error setting state for image UUID(%s), %s", d.Id(), err)
return fmt.Errorf("error setting state for user UUID(%s), %s", d.Id(), err)
}

d.SetId(*resp.Metadata.UUID)
Expand Down
1 change: 0 additions & 1 deletion nutanix/data_source_nutanix_user_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func dataSourceNutanixUserGroupRead(d *schema.ResourceData, meta interface{}) er
}

func flattenDirectoryServiceUserGroup(dsu *v3.DirectoryServiceUserGroup) []interface{} {

if dsu != nil {
directoryServiceUserMap := map[string]interface{}{}

Expand Down
4 changes: 2 additions & 2 deletions nutanix/data_source_nutanix_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "nutanix_user" "user" {
}

data "nutanix_user" "user" {
uuid = nutanix_user.user.id
user_id = nutanix_user.user.id
}
`, pn, dsuuid)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ resource "nutanix_user" "user" {
}

data "nutanix_user" "user" {
name = nutanix_user.user.name
user_name = nutanix_user.user.name
}
`, pn, dsuuid)
}