Skip to content

Commit

Permalink
Add workaround for missing UUID parameter for data source
Browse files Browse the repository at this point in the history
  • Loading branch information
jan committed Dec 27, 2021
1 parent f04ba96 commit 0503909
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 48 deletions.
40 changes: 0 additions & 40 deletions nutanix/data_source_address_group.go

This file was deleted.

85 changes: 85 additions & 0 deletions nutanix/data_source_nutanix_address_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package nutanix

import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceNutanixAddressGroup() *schema.Resource {
return &schema.Resource{
Read: dataSourceNutanixAddressGroupRead,
Schema: map[string]*schema.Schema{
"uuid": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
},
"ip_address_block_list": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip": {
Type: schema.TypeString,
Required: true,
},
"prefix_length": {
Type: schema.TypeInt,
Required: true,
},
},
},
},
"address_group_string": {
Type: schema.TypeString,
Computed: true,
},
},
}

}

func dataSourceNutanixAddressGroupRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*Client).API

if uuid, uuidOk := d.GetOk("uuid"); uuidOk {
group, reqErr := conn.V3.GetAddressGroup(uuid.(string))

if reqErr != nil {
if strings.Contains(fmt.Sprint(reqErr), "ENTITY_NOT_FOUND") {
d.SetId("")
}
return fmt.Errorf("error reading user with error %s", reqErr)
}

if name, nameOk := d.GetOk("name"); nameOk {
d.Set("name", name.(string))
}

if desc, descOk := d.GetOk("description"); descOk {
d.Set("description", desc.(string))
}

if str, strOk := d.GetOk("address_group_string"); strOk {
d.Set("address_group_string", str.(string))
}

if err := d.Set("ip_address_block_list", flattenAddressEntry(group.AddressGroup.BlockList)); err != nil {
return err
}

d.SetId(uuid.(string))
} else {
return fmt.Errorf("please provide `uuid`")
}
return nil
}
1 change: 0 additions & 1 deletion nutanix/data_source_nutanix_address_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func flattenAddressGroup(entries []*v3.AddressGroupListEntry) interface{} {
entities := make([]map[string]interface{}, len(entries))

for i, entry := range entries {

entities[i] = map[string]interface{}{
"address_group": map[string]interface{}{
"name": entry.AddressGroup.Name,
Expand Down
7 changes: 3 additions & 4 deletions nutanix/resource_nutanix_address_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package nutanix

import (
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
"log"
"strings"
)

func resourceNutanixAddressGroup() *schema.Resource {
Expand Down Expand Up @@ -49,7 +50,6 @@ func resourceNutanixAddressGroup() *schema.Resource {
},
},
}

}

func resourceNutanixAddressGroupUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -96,7 +96,6 @@ func resourceNutanixAddressGroupUpdate(d *schema.ResourceData, meta interface{})
}

return resourceNutanixAddressGroupRead(d, meta)

}

func resourceNutanixAddressGroupDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
7 changes: 4 additions & 3 deletions nutanix/resource_nutanix_service_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package nutanix
import (
"encoding/json"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
"log"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)

func resourceNutanixServiceGroup() *schema.Resource {
Expand Down

0 comments on commit 0503909

Please sign in to comment.