Skip to content

Commit c732098

Browse files
committed
Changing instance_values to map string to handle key-value pairs in shuffled payload.
1 parent 9199dde commit c732098

File tree

14 files changed

+249
-111
lines changed

14 files changed

+249
-111
lines changed

docs/data-sources/networks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Read-Only:
7878
- `attached` (Boolean) The state of the attachment
7979
- `display_name` (String) The name of the switch
8080
- `freeform_config` (String) This field covers any configuration not included in overlay templates which is needed as part of this VRF attachment
81-
- `instance_values` (String) Instance values
81+
- `instance_values` (Map of String) Instance values
8282
- `serial_number` (String) Serial number of a switch
8383
- `switch_name` (String) The name of the switch
8484
- `switch_ports` (Set of String) List of switch ports

docs/resources/networks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Optional:
130130
- `deploy_this_attachment` (Boolean) If set to `true`, deploys this attachment. This cannot be set to `true` if `deploy_all_attachments` at resource level is set to `true` or `deploy_attachments` in the corresponding `network` is set to `true`
131131
- `display_name` (String) The name of the switch
132132
- `freeform_config` (String) This field covers any configuration not included in overlay templates which is needed as part of this VRF attachment
133-
- `instance_values` (String) Instance values
133+
- `instance_values` (Map of String) Instance values
134134
- `switch_ports` (Set of String) List of switch ports
135135
- `tor_ports` (Set of String) List of TOR ports
136136
- `vlan` (Number) VLAN ID

examples/resources/ndfc_vrf_bulk/import.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

generator/defs/network-attachments.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ resource:
161161
ndfc_type: csv
162162
- model_name: instanceValues
163163
tf_name: instance_values
164-
type: String
164+
type: Map:String
165+
ndfc_type: customMap
165166
optional: true
166167
computed: true
167168
description: Instance values

generator/defs/networks.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ datasource:
551551
example: "[Ethernet1/1, Ethernet1/2]"
552552
- model_name: instanceValues
553553
tf_name: instance_values
554-
type: String
554+
type: Map:String
555+
ndfc_type: customMap
555556
optional: false
556557
computed: true
557558
description: Instance values

internal/provider/datasources/datasource_networks/datasource_codec_gen.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ type NDFCNetworksValue struct {
4646
type NDFCAttachmentsValues []NDFCAttachmentsValue
4747

4848
type NDFCAttachmentsValue struct {
49-
SerialNumber string `json:"serialNumber,omitempty"`
50-
SwitchSerialNo string `json:"switchSerialNo,omitempty"`
51-
SwitchName string `json:"switchName,omitempty"`
52-
DisplayName string `json:"displayName,omitempty"`
53-
Vlan *Int64Custom `json:"vlan,omitempty"`
54-
VlanId *Int64Custom `json:"vlanId,omitempty"`
55-
AttachState string `json:"lanAttachState,omitempty"`
56-
Attached *bool `json:"isLanAttached,omitempty"`
57-
FreeformConfig string `json:"freeformconfig,omitempty"`
58-
SwitchPorts CSVString `json:"switchPorts,omitempty"`
59-
PortNames string `json:"portNames,omitempty"`
60-
TorPorts CSVString `json:"torPorts,omitempty"`
61-
InstanceValues string `json:"instanceValues,omitempty"`
49+
SerialNumber string `json:"serialNumber,omitempty"`
50+
SwitchSerialNo string `json:"switchSerialNo,omitempty"`
51+
SwitchName string `json:"switchName,omitempty"`
52+
DisplayName string `json:"displayName,omitempty"`
53+
Vlan *Int64Custom `json:"vlan,omitempty"`
54+
VlanId *Int64Custom `json:"vlanId,omitempty"`
55+
AttachState string `json:"lanAttachState,omitempty"`
56+
Attached *bool `json:"isLanAttached,omitempty"`
57+
FreeformConfig string `json:"freeformconfig,omitempty"`
58+
SwitchPorts CSVString `json:"switchPorts,omitempty"`
59+
PortNames string `json:"portNames,omitempty"`
60+
TorPorts CSVString `json:"torPorts,omitempty"`
61+
InstanceValues CustomMapString `json:"instanceValues,omitempty"`
6262
}
6363

6464
type NDFCNetworkTemplateConfigValue struct {
@@ -522,10 +522,20 @@ func (v *AttachmentsValue) SetValue(jsonData *NDFCAttachmentsValue) diag.Diagnos
522522
return err
523523
}
524524
}
525-
if jsonData.InstanceValues != "" {
526-
v.InstanceValues = types.StringValue(jsonData.InstanceValues)
525+
526+
if len(jsonData.InstanceValues) == 0 {
527+
log.Printf("v.InstanceValues is empty")
528+
v.InstanceValues = types.MapNull(types.StringType)
527529
} else {
528-
v.InstanceValues = types.StringNull()
530+
mapData := make(map[string]attr.Value)
531+
for key, item := range jsonData.InstanceValues {
532+
mapData[key] = types.StringValue(item)
533+
}
534+
v.InstanceValues, err = types.MapValue(types.StringType, mapData)
535+
if err != nil {
536+
log.Printf("Error in converting map[string]string to Map")
537+
return err
538+
}
529539
}
530540

531541
return err

internal/provider/datasources/datasource_networks/networks_data_source_gen.go

Lines changed: 64 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/provider/ndfc/network_attachments.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (c *NDFC) RscGetNetworkAttachments(ctx context.Context, nw *resource_networ
2828
tflog.Error(ctx, "RscGetNetworkAttachments: Error getting network attachments", map[string]interface{}{"Err": err})
2929
return err
3030
}
31-
c.createVpcPairMap(ctx, nw.FabricName)
3231
nw.FillAttachmentsFromPayload(nwAttachPayload)
3332

3433
for netName, nwEntry := range nw.Networks {

internal/provider/resources/resource_network_attachments/resource_codec_gen.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ type NDFCNetworkAttachmentsValue struct {
2424
}
2525

2626
type NDFCAttachmentsValue struct {
27-
FilterThisValue bool `json:"-"`
28-
Id *int64 `json:"-"`
29-
FabricName string `json:"fabric,omitempty"`
30-
NetworkName string `json:"networkName,omitempty"`
31-
SerialNumber string `json:"serialNumber,omitempty"`
32-
SwitchSerialNo string `json:"switchSerialNo,omitempty"`
33-
SwitchName string `json:"switchName,omitempty"`
34-
DisplayName string `json:"displayName,omitempty"`
35-
Vlan *Int64Custom `json:"vlan,omitempty"`
36-
VlanId *Int64Custom `json:"vlanId,omitempty"`
37-
Deployment string `json:"deployment,omitempty"`
38-
AttachState string `json:"lanAttachState,omitempty"`
39-
Attached *bool `json:"isLanAttached,omitempty"`
40-
FreeformConfig string `json:"freeformconfig,omitempty"`
41-
DeployThisAttachment bool `json:"-"`
42-
SwitchPorts CSVString `json:"switchPorts,omitempty"`
43-
DetachSwitchPorts CSVString `json:"detachSwitchPorts,omitempty"`
44-
PortNames string `json:"portNames,omitempty"`
45-
TorPorts CSVString `json:"torPorts,omitempty"`
46-
InstanceValues string `json:"instanceValues,omitempty"`
47-
UpdateAction uint16 `json:"-"`
27+
FilterThisValue bool `json:"-"`
28+
Id *int64 `json:"-"`
29+
FabricName string `json:"fabric,omitempty"`
30+
NetworkName string `json:"networkName,omitempty"`
31+
SerialNumber string `json:"serialNumber,omitempty"`
32+
SwitchSerialNo string `json:"switchSerialNo,omitempty"`
33+
SwitchName string `json:"switchName,omitempty"`
34+
DisplayName string `json:"displayName,omitempty"`
35+
Vlan *Int64Custom `json:"vlan,omitempty"`
36+
VlanId *Int64Custom `json:"vlanId,omitempty"`
37+
Deployment string `json:"deployment,omitempty"`
38+
AttachState string `json:"lanAttachState,omitempty"`
39+
Attached *bool `json:"isLanAttached,omitempty"`
40+
FreeformConfig string `json:"freeformconfig,omitempty"`
41+
DeployThisAttachment bool `json:"-"`
42+
SwitchPorts CSVString `json:"switchPorts,omitempty"`
43+
DetachSwitchPorts CSVString `json:"detachSwitchPorts,omitempty"`
44+
PortNames string `json:"portNames,omitempty"`
45+
TorPorts CSVString `json:"torPorts,omitempty"`
46+
InstanceValues CustomMapString `json:"instanceValues,omitempty"`
47+
UpdateAction uint16 `json:"-"`
4848
}

internal/provider/resources/resource_network_attachments/resource_compare_gen.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ func (v NDFCAttachmentsValue) DeepEqual(c NDFCAttachmentsValue) int {
6666
return PortListUpdate
6767
}
6868
}
69-
if v.InstanceValues != c.InstanceValues {
70-
log.Printf("v.InstanceValues=%v, c.InstanceValues=%v", v.InstanceValues, c.InstanceValues)
71-
return RequiresUpdate
72-
}
7369

7470
if cf {
7571
return ControlFlagUpdate
@@ -169,19 +165,20 @@ func (v *NDFCAttachmentsValue) CreatePlan(c NDFCAttachmentsValue, cf *bool) int
169165
}
170166
}
171167

172-
if v.InstanceValues != "" {
173-
174-
if v.InstanceValues != c.InstanceValues {
175-
log.Printf("Update: v.InstanceValues=%v, c.InstanceValues=%v", v.InstanceValues, c.InstanceValues)
176-
if action == ActionNone || action == RequiresUpdate {
177-
action = RequiresUpdate
178-
}
168+
if len(v.InstanceValues) != len(c.InstanceValues) {
169+
log.Printf("Update: len(v.InstanceValues)=%d, len(c.InstanceValues)=%d", len(v.InstanceValues), len(c.InstanceValues))
170+
return RequiresUpdate
171+
}
172+
for kk, vv := range v.InstanceValues {
173+
cc, ok := c.InstanceValues[kk]
174+
if !ok {
175+
log.Printf("Update: v.InstanceValues[%s]=%s, c.InstanceValues[%s]=nil", kk, vv, kk)
176+
return RequiresUpdate
177+
}
178+
if vv != cc {
179+
log.Printf("Update: v.InstanceValues[%s]=%s, c.InstanceValues[%s]=%s", kk, vv, kk, cc)
180+
return RequiresUpdate
179181
}
180-
181-
} else {
182-
//v empty, fill with c
183-
log.Printf("Copy from state: v.InstanceValues=%v, c.InstanceValues=%v", v.InstanceValues, c.InstanceValues)
184-
v.InstanceValues = c.InstanceValues
185182
}
186183

187184
return action

0 commit comments

Comments
 (0)