From f5f4027375e33b2b8e4441f5ecdf410899a470b4 Mon Sep 17 00:00:00 2001 From: chaitra-mylarappachar <65302544+chaitra-mylarappachar@users.noreply.github.com> Date: Thu, 2 Mar 2023 12:31:08 -0600 Subject: [PATCH] Included VLAN/VNI fields in available networks (#102) * Included VLAN/VNI fields in available networks * Addr review comments * addr lint --- go.mod | 2 +- go.sum | 4 +- .../datasource_available_resources.go | 4 +- .../datasource_available_resources_test.go | 48 +++++++++++++++++++ version | 2 +- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 internal/resources/datasource_available_resources_test.go diff --git a/go.mod b/go.mod index 3e8e74e..ed58349 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/golangci/golangci-lint v1.51.2 github.com/hashicorp/terraform-plugin-docs v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0 - github.com/hewlettpackard/hpegl-metal-client v1.4.14 + github.com/hewlettpackard/hpegl-metal-client v1.4.15 github.com/hewlettpackard/hpegl-provider-lib v0.0.14 github.com/stretchr/testify v1.8.2 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 3e946e7..5f8e730 100644 --- a/go.sum +++ b/go.sum @@ -374,8 +374,8 @@ github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKL github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= -github.com/hewlettpackard/hpegl-metal-client v1.4.14 h1:N77Vs6/iREfXj+UEiO75b6Hqm3ich8+Of2LZa77roBI= -github.com/hewlettpackard/hpegl-metal-client v1.4.14/go.mod h1:z8JEXcrqvD22jOofmU/3ZZOHBXk2yljfahDmquMRxas= +github.com/hewlettpackard/hpegl-metal-client v1.4.15 h1:0NEnlLJ0EoX+6plF5Xbkx5ttCcgqhPa3p8honAmKM+M= +github.com/hewlettpackard/hpegl-metal-client v1.4.15/go.mod h1:z8JEXcrqvD22jOofmU/3ZZOHBXk2yljfahDmquMRxas= github.com/hewlettpackard/hpegl-provider-lib v0.0.14 h1:fwIXQsdEdeYYvaJQr1vwfPgCGYKgZaP7kL0p8xbBQJ4= github.com/hewlettpackard/hpegl-provider-lib v0.0.14/go.mod h1:7StTTobQIl8pZCLcJnZm0/+N4lNE2MO6H/U0LhTfXog= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= diff --git a/internal/resources/datasource_available_resources.go b/internal/resources/datasource_available_resources.go index 9713164..46c6ba0 100644 --- a/internal/resources/datasource_available_resources.go +++ b/internal/resources/datasource_available_resources.go @@ -1,4 +1,4 @@ -// (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP +// (C) Copyright 2020-2023 Hewlett Packard Enterprise Development LP package resources @@ -344,6 +344,8 @@ func addNetworks(p *configuration.Config, d *schema.ResourceData, available rest nPurpose: net.Purpose, nLocationID: net.LocationID, nIPPoolID: net.IPPoolID, + nVLAN: net.VLAN, + nVNI: net.VNI, } l, _ := p.GetLocationName(net.LocationID) iData[nLocation] = l diff --git a/internal/resources/datasource_available_resources_test.go b/internal/resources/datasource_available_resources_test.go new file mode 100644 index 0000000..5c97cb8 --- /dev/null +++ b/internal/resources/datasource_available_resources_test.go @@ -0,0 +1,48 @@ +// (C) Copyright 2023 Hewlett Packard Enterprise Development LP + +package resources + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/stretchr/testify/assert" + + "github.com/hewlettpackard/hpegl-metal-client/v1/pkg/client" + "github.com/hewlettpackard/hpegl-metal-terraform-resources/pkg/configuration" +) + +func Test_addNetworks(t *testing.T) { + testVlan := 200 + testVni := 12006 + + availableNets := client.AvailableResources{ + Networks: []client.AvailableNetwork{ + { + ID: "testID", + VLAN: int32(testVlan), + VNI: int32(testVni), + }, + }, + } + + cfg := &configuration.Config{ + AvailableResources: client.AvailableResources{}, + } + + d := schema.TestResourceDataRaw(t, DataSourceAvailableResources().Schema, map[string]interface{}{}) + + // test + err := addNetworks(cfg, d, availableNets) + assert.Nil(t, err) + + networks, ok := d.Get(avNetworks).([]interface{}) + assert.True(t, ok, "type assertion failed for networks") + assert.Equal(t, 1, len(networks)) + + net, ok := networks[0].(map[string]interface{}) + assert.True(t, ok, "type assertion failed for a network") + + assert.Equal(t, testVlan, net["vlan"]) + assert.Equal(t, testVni, net["vni"]) +} diff --git a/version b/version index c34958a..e8e277f 100644 --- a/version +++ b/version @@ -1 +1 @@ -0.1.15 +0.1.16