Skip to content

Commit

Permalink
datasource for subnets,vpcs, fips
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimutant committed Nov 24, 2023
1 parent a4e76cc commit 25562e0
Show file tree
Hide file tree
Showing 11 changed files with 2,378 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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/networking-go-client/v16 v16.8.0-3635 // 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
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
Expand All @@ -283,6 +285,7 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBM
github.com/hashicorp/go-getter v1.5.3 h1:NF5+zOlQegim+w/EUhSLh6QhXHmZMEeHLQzllkQ3ROU=
github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v0.16.1 h1:IVQwpTGNRRIHafnTs2dQLIk4ENtneRIEEJWOVDqz99o=
github.com/hashicorp/go-hclog v0.16.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
Expand All @@ -292,6 +295,8 @@ github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9
github.com/hashicorp/go-plugin v1.3.0/go.mod h1:F9eH4LrE/ZsRdbwhfjs9k9HoDUwAHnYtXdgmf1AVNs0=
github.com/hashicorp/go-plugin v1.4.1 h1:6UltRQlLN9iZO513VveELp5xyaFxVD2+1OVylE+2E+w=
github.com/hashicorp/go-plugin v1.4.1/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
Expand Down Expand Up @@ -439,6 +444,8 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d/go.mod h1:o96d
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
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/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
Expand Down
7 changes: 7 additions & 0 deletions nutanix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/karbon"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v4/networking"

"github.com/terraform-providers/terraform-provider-nutanix/nutanix/client"
era "github.com/terraform-providers/terraform-provider-nutanix/nutanix/sdks/v3/era"
Expand Down Expand Up @@ -72,13 +73,18 @@ func (c *Config) Client() (*Client, error) {
if err != nil {
return nil, err
}
networkingClient, err := networking.NewNetworkingClient(configCreds)
if err != nil {
return nil, err
}
return &Client{
WaitTimeout: c.WaitTimeout,
API: v3Client,
KarbonAPI: karbonClient,
FoundationClientAPI: foundationClient,
FoundationCentral: fcClient,
Era: eraClient,
NetworkingAPI: networkingClient,
}, nil
}

Expand All @@ -90,4 +96,5 @@ type Client struct {
WaitTimeout int64
FoundationCentral *foundation_central.Client
Era *era.Client
NetworkingAPI *networking.NetworkingClient
}
7 changes: 7 additions & 0 deletions nutanix/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v1/ndb"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v1/nke"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v1/prism"
"github.com/terraform-providers/terraform-provider-nutanix/nutanix/services/v2/networking"
)

var requiredProviderFields map[string][]string = map[string][]string{
Expand Down Expand Up @@ -218,6 +219,12 @@ func Provider() *schema.Provider {
"nutanix_ndb_dbserver": ndb.DataSourceNutanixNDBDBServer(),
"nutanix_ndb_dbservers": ndb.DataSourceNutanixNDBDBServers(),
"nutanix_ndb_network_available_ips": ndb.DataSourceNutanixNDBProfileAvailableIPs(),
"nutanix_subnet_v4": networking.DataSourceNutanixSubnetv4(),
"nutanix_subnets_v4": networking.DataSourceNutanixSubnetsv4(),
"nutanix_vpc_v4": networking.DataSourceNutanixVPCv4(),
"nutanix_vpcs_v4": networking.DataSourceNutanixVPCsv4(),
"nutanix_floating_ip_v4": networking.DatasourceNutanixFloatingIPV4(),
"nutanix_floating_ips_v4": networking.DatasourceNutanixFloatingIPsV4(),
},
ResourcesMap: map[string]*schema.Resource{
"nutanix_virtual_machine": prism.ResourceNutanixVirtualMachine(),
Expand Down
38 changes: 38 additions & 0 deletions nutanix/sdks/v4/networking/networking.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package networking

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

type NetworkingClient struct {
SubnetApiInstance *api.SubnetApi
VpcApiInstance *api.VpcApi
FloatingIpApiInstance *api.FloatingIpApi
}

func NewNetworkingClient(credentials client.Credentials) (*NetworkingClient, error) {
var baseClient *network.ApiClient

// check if all required fields are present. Else create an empty client
if credentials.Username != "" && credentials.Password != "" && credentials.Endpoint != "" {
pcClient := network.NewApiClient()

pcClient.Host = credentials.Endpoint
pcClient.Password = credentials.Password
pcClient.Username = credentials.Username
pcClient.Port = 9440
pcClient.VerifySSL = false

baseClient = pcClient
}

f := &NetworkingClient{
SubnetApiInstance: api.NewSubnetApi(baseClient),
VpcApiInstance: api.NewVpcApi(baseClient),
FloatingIpApiInstance: api.NewFloatingIpApi(baseClient),
}

return f, nil
}
Loading

0 comments on commit 25562e0

Please sign in to comment.