Skip to content

Commit

Permalink
crud for service groups
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Mar 7, 2024
1 parent 1887a43 commit a4327e8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ require (
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/mitchellh/gox v1.0.1
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-4914 // indirect
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-alpha.1 // indirect
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.1-beta.1 // indirect
github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.3-alpha.2 // indirect
// github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4 v4.0.3-alpha.2 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.8.0-3635 h1:eVNonw1w8i0lVNNK4Ep/P8fAb2j6EEe+VNXAQXPLThc=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/networking-go-client/v16 v16.8.0-3635/go.mod h1:vHyQVF3IKxmip+xGxXDQznKk1ffrVa4HSiEEueiekaE=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-4914 h1:xl9+7uyYFvhFRkNdgzn5mWsrNjoRd0ookC4n/x42GH0=
github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16 v16.9.0-4914/go.mod h1:qmOw/29LhPpII8cDmbTL0OF3btwp97ss7nFcQz72NDM=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-alpha.1 h1:BDXkI6DSjScmSBLsbNs4orhvVWpYAjTTE9XNsEPiZ/c=
github.com/nutanix/ntnx-api-golang-clients/microseg-go-client/v4 v4.0.1-alpha.1/go.mod h1:75Ro+aFIepNAkf2eWjFrFR7m+Ct36EVrD9n9pwAYBrc=
github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4 v4.0.1-beta.1 h1:EBTbuV4zFgv+MY7a5MYIELStXPMMds1aULHllA5xdFM=
Expand Down
8 changes: 4 additions & 4 deletions nutanix/sdks/v4/prism/prism.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package prism

import (
"github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/api"
prism "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/client"
"github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16/api"
prism "github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16/client"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
)

type Client struct {
TaskRefAPI *api.TaskApi
TaskRefAPI *api.TasksApi
}

func NewPrismClient(credentials client.Credentials) (*Client, error) {
Expand All @@ -27,7 +27,7 @@ func NewPrismClient(credentials client.Credentials) (*Client, error) {
}

f := &Client{
TaskRefAPI: api.NewTaskApi(baseClient),
TaskRefAPI: api.NewTasksApi(baseClient),
}

return f, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package networking
import (
"context"
"encoding/json"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -138,7 +139,9 @@ func DatasourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.Resourc
// }

resp, err := conn.AddressGroupAPIInstance.ListAddressGroups(page, limit, filter, orderBy)
fmt.Println("HEELLLLLLLLL")
if err != nil {
fmt.Println(err)
var errordata map[string]interface{}
e := json.Unmarshal([]byte(err.Error()), &errordata)
if e != nil {
Expand All @@ -160,7 +163,7 @@ func DatasourceNutanixAddressGroupsV4Read(ctx context.Context, d *schema.Resourc
}

func flattenAddressGroupsEntities(pr []import1.AddressGroup) []interface{} {
if pr != nil {
if len(pr) > 0 {
addGroups := make([]interface{}, len(pr))

for k, v := range pr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func DatasourceNutanixServiceGroupsV4Read(ctx context.Context, d *schema.Resourc
}

getResp := resp.Data.GetValue().([]import1.ServiceGroup)
if err := d.Set("address_groups", flattenServiceGroupsEntities(getResp)); err != nil {
if err := d.Set("service_groups", flattenServiceGroupsEntities(getResp)); err != nil {
return diag.FromErr(err)
}

Expand All @@ -208,9 +208,9 @@ func flattenServiceGroupsEntities(pr []import1.ServiceGroup) []interface{} {
sg["ext_id"] = v.ExtId
sg["name"] = v.Name
sg["description"] = v.Description
sg["tcp_services"] = v.TcpServices
sg["udp_services"] = v.UdpServices
sg["icmp_services"] = v.IcmpServices
sg["tcp_services"] = flattenTcpPortRangeSpec(v.TcpServices)
sg["udp_services"] = flattenUdpPortRangeSpec(v.UdpServices)
sg["icmp_services"] = flattenIcmpTypeCodeSpec(v.IcmpServices)
sg["is_system_defined"] = v.IsSystemDefined

serviceGroups[k] = sg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
import2 "github.com/nutanix-core/ntnx-api-golang-sdk-internal/prism-go-client/v16/models/prism/v4/config"
import1 "github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4/models/networking/v4/config"
import4 "github.com/nutanix/ntnx-api-golang-clients/networking-go-client/v4/models/prism/v4/config"
import2 "github.com/nutanix/ntnx-api-golang-clients/prism-go-client/v4/models/prism/v4/config"
conns "github.com/terraform-providers/terraform-provider-nutanix/nutanix"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/prism"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
Expand Down Expand Up @@ -552,7 +552,7 @@ func taskStateRefreshPrismTaskGroupFunc(ctx context.Context, client *prism.Clien
return func() (interface{}, string, error) {
data := base64.StdEncoding.EncodeToString([]byte("ergon"))
encodeUUID := data + ":" + taskUUID
vresp, err := client.TaskRefAPI.TaskGet(utils.StringPtr(encodeUUID))
vresp, err := client.TaskRefAPI.GetTaskById(utils.StringPtr(encodeUUID), nil)

if err != nil {
var errordata map[string]interface{}
Expand Down

0 comments on commit a4327e8

Please sign in to comment.