Skip to content

Commit

Permalink
V2 SDK Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-kulshrestha authored and siddharth-nutanix committed Feb 15, 2022
1 parent 59ddb85 commit f20a454
Show file tree
Hide file tree
Showing 101 changed files with 2,200 additions and 6,350 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ linters:
- nestif
- godot
- goconst
- unparam
- unused
- staticcheck
- deadcode

issues:
exclude:
Expand Down
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"net/url"

"github.com/PaesslerAG/jsonpath"
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
)

const (
Expand Down
15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ module github.com/terraform-providers/terraform-provider-nutanix

require (
github.com/PaesslerAG/jsonpath v0.1.1
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 // indirect
github.com/client9/misspell v0.3.4
github.com/golang/snappy v0.0.1 // indirect
github.com/golangci/golangci-lint v1.25.0
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/magiconair/properties v1.8.1 // indirect
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba // indirect
github.com/magiconair/properties v1.8.1
github.com/mitchellh/gox v1.0.1
github.com/pierrec/lz4 v2.0.5+incompatible // indirect
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.6.1
golang.org/x/tools v0.0.0-20200530233709-52effbd89c51 // indirect
gopkg.in/yaml.v2 v2.2.8
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
)

go 1.13
366 changes: 366 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/hashicorp/terraform-plugin-sdk/plugin"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix"
)

Expand Down
8 changes: 4 additions & 4 deletions nutanix/categories.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package nutanix

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)

func categoriesSchema() *schema.Schema {
Expand All @@ -12,7 +12,7 @@ func categoriesSchema() *schema.Schema {
Computed: true,
Set: func(v interface{}) int {
category := v.(map[string]interface{})
return hashcode.String(category["name"].(string) + category["value"].(string))
return utils.HashcodeString(category["name"].(string) + category["value"].(string))
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -62,7 +62,7 @@ func categoriesSchemaOptional() *schema.Schema {
Optional: true,
Set: func(v interface{}) int {
category := v.(map[string]interface{})
return hashcode.String(category["name"].(string) + category["value"].(string))
return utils.HashcodeString(category["name"].(string) + category["value"].(string))
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
89 changes: 16 additions & 73 deletions nutanix/data_source_nutanix_access_control_policies.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package nutanix

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"context"

"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"
v3 "github.com/terraform-providers/terraform-provider-nutanix/client/v3"
"github.com/terraform-providers/terraform-provider-nutanix/utils"
)

func dataSourceNutanixAccessControlPolicies() *schema.Resource {
return &schema.Resource{
Read: dataSourceNutanixAccessControlPoliciesRead,
ReadContext: dataSourceNutanixAccessControlPoliciesRead,
Schema: map[string]*schema.Schema{
"api_version": {
Type: schema.TypeString,
Expand All @@ -31,78 +34,23 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
"metadata": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"last_update_time": {
Type: schema.TypeString,
Computed: true,
},
"kind": {
Type: schema.TypeString,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"creation_time": {
Type: schema.TypeString,
Computed: true,
},
"spec_version": {
Type: schema.TypeString,
Computed: true,
},
"spec_hash": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"categories": categoriesSchema(),
"owner_reference": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kind": {
Type: schema.TypeString,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"project_reference": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kind": {
Type: schema.TypeString,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Expand Down Expand Up @@ -160,7 +108,6 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
"role_reference": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kind": {
Expand Down Expand Up @@ -199,7 +146,6 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
"right_hand_side": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"collection": {
Expand All @@ -208,7 +154,6 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
},
"categories": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -251,7 +196,6 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
"right_hand_side": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"collection": {
Expand All @@ -260,7 +204,6 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
},
"categories": {
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -336,7 +279,7 @@ func dataSourceNutanixAccessControlPolicies() *schema.Resource {
}
}

func dataSourceNutanixAccessControlPoliciesRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceNutanixAccessControlPoliciesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
// Get client connection
conn := meta.(*Client).API
req := &v3.DSMetadata{}
Expand All @@ -348,11 +291,11 @@ func dataSourceNutanixAccessControlPoliciesRead(d *schema.ResourceData, meta int

resp, err := conn.V3.ListAllAccessControlPolicy(utils.StringValue(req.Filter))
if err != nil {
return err
return diag.FromErr(err)
}

if err := d.Set("api_version", resp.APIVersion); err != nil {
return err
return diag.FromErr(err)
}

entities := make([]map[string]interface{}, len(resp.Entities))
Expand Down Expand Up @@ -385,7 +328,7 @@ func dataSourceNutanixAccessControlPoliciesRead(d *schema.ResourceData, meta int
}

if err := d.Set("entities", entities); err != nil {
return err
return diag.FromErr(err)
}

d.SetId(resource.UniqueId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nutanix
import (
"testing"

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

func TestAccNutanixAccessControlPoliciesDataSource_basic(t *testing.T) {
Expand Down
Loading

0 comments on commit f20a454

Please sign in to comment.