Skip to content

Commit f010fe4

Browse files
janabhimutant
authored andcommitted
Add workaround for missing UUID parameter for data source
1 parent 91eb275 commit f010fe4

5 files changed

Lines changed: 91 additions & 48 deletions

nutanix/data_source_address_group.go

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package nutanix
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
)
9+
10+
func dataSourceNutanixAddressGroup() *schema.Resource {
11+
return &schema.Resource{
12+
Read: dataSourceNutanixAddressGroupRead,
13+
Schema: map[string]*schema.Schema{
14+
"uuid": {
15+
Type: schema.TypeString,
16+
Required: true,
17+
},
18+
"name": {
19+
Type: schema.TypeString,
20+
Computed: true,
21+
},
22+
"description": {
23+
Type: schema.TypeString,
24+
Optional: true,
25+
},
26+
"ip_address_block_list": {
27+
Type: schema.TypeList,
28+
Required: true,
29+
Elem: &schema.Resource{
30+
Schema: map[string]*schema.Schema{
31+
"ip": {
32+
Type: schema.TypeString,
33+
Required: true,
34+
},
35+
"prefix_length": {
36+
Type: schema.TypeInt,
37+
Required: true,
38+
},
39+
},
40+
},
41+
},
42+
"address_group_string": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
},
46+
},
47+
}
48+
}
49+
50+
func dataSourceNutanixAddressGroupRead(d *schema.ResourceData, meta interface{}) error {
51+
conn := meta.(*Client).API
52+
53+
if uuid, uuidOk := d.GetOk("uuid"); uuidOk {
54+
group, reqErr := conn.V3.GetAddressGroup(uuid.(string))
55+
56+
if reqErr != nil {
57+
if strings.Contains(fmt.Sprint(reqErr), "ENTITY_NOT_FOUND") {
58+
d.SetId("")
59+
}
60+
return fmt.Errorf("error reading user with error %s", reqErr)
61+
}
62+
63+
if name, nameOk := d.GetOk("name"); nameOk {
64+
d.Set("name", name.(string))
65+
}
66+
67+
if desc, descOk := d.GetOk("description"); descOk {
68+
d.Set("description", desc.(string))
69+
}
70+
71+
if str, strOk := d.GetOk("address_group_string"); strOk {
72+
d.Set("address_group_string", str.(string))
73+
}
74+
75+
if err := d.Set("ip_address_block_list", flattenAddressEntry(group.AddressGroup.BlockList)); err != nil {
76+
return err
77+
}
78+
79+
d.SetId(uuid.(string))
80+
} else {
81+
return fmt.Errorf("please provide `uuid`")
82+
}
83+
return nil
84+
}

nutanix/data_source_nutanix_address_groups.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ func flattenAddressGroup(entries []*v3.AddressGroupListEntry) interface{} {
146146
entities := make([]map[string]interface{}, len(entries))
147147

148148
for i, entry := range entries {
149-
150149
entities[i] = map[string]interface{}{
151150
"address_group": map[string]interface{}{
152151
"name": entry.AddressGroup.Name,

nutanix/resource_nutanix_address_group.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package nutanix
22

33
import (
44
"fmt"
5+
"log"
6+
"strings"
7+
58
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
69
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
710
"github.com/terraform-providers/terraform-provider-nutanix/utils"
8-
"log"
9-
"strings"
1011
)
1112

1213
func resourceNutanixAddressGroup() *schema.Resource {
@@ -49,7 +50,6 @@ func resourceNutanixAddressGroup() *schema.Resource {
4950
},
5051
},
5152
}
52-
5353
}
5454

5555
func resourceNutanixAddressGroupUpdate(d *schema.ResourceData, meta interface{}) error {
@@ -96,7 +96,6 @@ func resourceNutanixAddressGroupUpdate(d *schema.ResourceData, meta interface{})
9696
}
9797

9898
return resourceNutanixAddressGroupRead(d, meta)
99-
10099
}
101100

102101
func resourceNutanixAddressGroupDelete(d *schema.ResourceData, meta interface{}) error {

nutanix/resource_nutanix_service_group.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package nutanix
33
import (
44
"encoding/json"
55
"fmt"
6-
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
7-
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
8-
"github.com/terraform-providers/terraform-provider-nutanix/utils"
96
"log"
107
"strconv"
118
"strings"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
11+
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
12+
"github.com/terraform-providers/terraform-provider-nutanix/utils"
1213
)
1314

1415
func resourceNutanixServiceGroup() *schema.Resource {

0 commit comments

Comments
 (0)