diff --git a/internal/provider/resources/agent.go b/internal/provider/resources/agent.go index 4c6641dd..fb7284fd 100644 --- a/internal/provider/resources/agent.go +++ b/internal/provider/resources/agent.go @@ -158,6 +158,7 @@ func (r *agentResource) Read( } sensor := sensorResponse.Items[0] + state.ID = types.StringValue(sensor.Id) state.Name = types.StringValue(sensor.Name) state.Notes = types.StringPointerValue(sensor.Notes.Get()) state.PCapMode = types.StringPointerValue(sensor.PcapMode.Get()) @@ -190,6 +191,7 @@ func (r *agentResource) Update( }) // Update resource state with updated items + plan.ID = types.StringValue(response.UID) plan.Name = types.StringValue(response.Name) plan.Notes = types.StringValue(response.Notes) plan.PCapMode = types.StringValue(response.PCapMode) diff --git a/internal/provider/resources/agent_group_assignment.go b/internal/provider/resources/agent_group_assignment.go index 1b31cad8..8930b286 100644 --- a/internal/provider/resources/agent_group_assignment.go +++ b/internal/provider/resources/agent_group_assignment.go @@ -168,6 +168,7 @@ func (r *agentGroupAssignmentResource) Read( agentGroupAssignment := agentGroupAssignmentResponse.Items[0] // Update state from client response + state.ID = types.StringValue(agentGroupAssignment.Id) state.GroupID = types.StringValue(agentGroupAssignment.Group.Id) state.AgentID = types.StringValue(agentGroupAssignment.Agent.Id) diff --git a/internal/provider/resources/group.go b/internal/provider/resources/group.go index 9a58ba4f..37f60cd3 100644 --- a/internal/provider/resources/group.go +++ b/internal/provider/resources/group.go @@ -172,6 +172,7 @@ func (r *groupResource) Read( } // Update state from client response + state.ID = types.StringValue(group.Id) state.Name = types.StringValue(group.Name) // only update parent if not attached to root node (else leave it as null) parentGroup, _ := r.getGroup(ctx, group.Parent.Get().Id) @@ -216,6 +217,7 @@ func (r *groupResource) Update( } // Update the state to match the plan (replace with response from client) + plan.ID = types.StringValue(group.Id) plan.Name = types.StringValue(group.Name) plan.ParentGroupId = types.StringValue(group.Parent.Id) diff --git a/internal/provider/resources/network_group_assignment.go b/internal/provider/resources/network_group_assignment.go index 0a07d0f3..5b35c0cb 100644 --- a/internal/provider/resources/network_group_assignment.go +++ b/internal/provider/resources/network_group_assignment.go @@ -169,6 +169,7 @@ func (r *networkGroupAssignmentResource) Read( networkGroupAssignment := networkGroupAssignmentResponse.Items[0] // Update state from client response + state.ID = types.StringValue(networkGroupAssignment.Id) state.GroupID = types.StringValue(networkGroupAssignment.Group.Id) state.NetworkID = types.StringValue(networkGroupAssignment.Network.Id) diff --git a/internal/provider/resources/sensor.go b/internal/provider/resources/sensor.go index 23cc5b2f..bc0a2a80 100644 --- a/internal/provider/resources/sensor.go +++ b/internal/provider/resources/sensor.go @@ -36,8 +36,8 @@ type SensorResponseModel struct { WifiMacAddress string EthernetMacAddress string AddressNote string - Longitude string - Latitude string + Longitude float32 + Latitude float32 Notes string PCapMode string } @@ -167,6 +167,7 @@ func (r *sensorResource) Read( sensor := sensorResponse.Items[0] // Update state from client response + state.ID = types.StringValue(sensor.Id) state.Name = types.StringValue(sensor.Name) state.AddressNote = types.StringPointerValue(sensor.AddressNote.Get()) state.Notes = types.StringPointerValue(sensor.Notes.Get()) @@ -202,6 +203,7 @@ func (r *sensorResource) Update( }) // Update resource state with updated items + plan.ID = types.StringValue(response.UID) plan.Name = types.StringValue(response.Name) plan.AddressNote = types.StringValue(response.AddressNote) plan.Notes = types.StringValue(response.Notes) @@ -250,8 +252,8 @@ var UpdateSensor = func(request SensorUpdateRequestModel) SensorResponseModel { WifiMacAddress: "mock_wifi_mac_address", EthernetMacAddress: "mock_ethernet_mac_address", AddressNote: request.AddressNote, - Longitude: "mock_longitude", - Latitude: "mock_latitude", + Longitude: 0.0, + Latitude: 0.0, Notes: request.Notes, PCapMode: request.PCapMode, } diff --git a/internal/provider/resources/sensor_group_assignment.go b/internal/provider/resources/sensor_group_assignment.go index 8f54da74..3db69c71 100644 --- a/internal/provider/resources/sensor_group_assignment.go +++ b/internal/provider/resources/sensor_group_assignment.go @@ -176,6 +176,7 @@ func (r *sensorGroupAssignmentResource) Read( sensorGroupAssignment := sensorGroupAssignmentResponse.Items[0] // Update state from client response + state.ID = types.StringValue(sensorGroupAssignment.Id) state.GroupID = types.StringValue(sensorGroupAssignment.Group.Id) state.SensorID = types.StringValue(sensorGroupAssignment.Sensor.Id) diff --git a/internal/provider/resources/service.go b/internal/provider/resources/service.go index 9942d32a..7da01377 100644 --- a/internal/provider/resources/service.go +++ b/internal/provider/resources/service.go @@ -132,6 +132,7 @@ func (r *serviceTestResource) Read( serviceTest := sensorResponse.Items[0] // Update state from client response + state.ID = types.StringValue(serviceTest.Id) state.Name = types.StringValue(serviceTest.Name) // Set refreshed state diff --git a/internal/provider/resources/service_group_assignment.go b/internal/provider/resources/service_group_assignment.go index 4fc2cb48..cde0af43 100644 --- a/internal/provider/resources/service_group_assignment.go +++ b/internal/provider/resources/service_group_assignment.go @@ -153,6 +153,7 @@ func (r *serviceTestGroupAssignmentResource) Read( serviceTestGroupAssignment := GetServiceTestGroupAssignment(state.ID.ValueString()) // Update state from client response + state.ID = types.StringValue(serviceTestGroupAssignment.Id) state.GroupID = types.StringValue(serviceTestGroupAssignment.Group.Id) state.ServiceTestID = types.StringValue(serviceTestGroupAssignment.ServiceTest.Id) diff --git a/internal/provider/resources/wired_network.go b/internal/provider/resources/wired_network.go index ce38c985..ab43df3b 100644 --- a/internal/provider/resources/wired_network.go +++ b/internal/provider/resources/wired_network.go @@ -133,6 +133,7 @@ func (r *wiredNetworkResource) Read( network := networkResponse.Items[0] // Update state from client response + state.ID = types.StringValue(network.Id) state.Name = types.StringValue(network.Name) // Set refreshed state diff --git a/internal/provider/resources/wireless_network.go b/internal/provider/resources/wireless_network.go index 2244f63a..572c0b49 100644 --- a/internal/provider/resources/wireless_network.go +++ b/internal/provider/resources/wireless_network.go @@ -133,6 +133,7 @@ func (r *wirelessNetworkResource) Read( network := networkResponse.Items[0] // Update state from client response + state.ID = types.StringValue(network.Id) state.Name = types.StringValue(network.Name) // Set refreshed state diff --git a/test/mocked/resources/agent_group_assignment_test.go b/test/mocked/resources/agent_group_assignment_test.go index 001b7b69..9438f272 100644 --- a/test/mocked/resources/agent_group_assignment_test.go +++ b/test/mocked/resources/agent_group_assignment_test.go @@ -22,9 +22,11 @@ func TestAgentGroupAssignmentResource(t *testing.T) { PreConfig: func() { // required for agent import util.MockGetAgent( - "uid", + "agent_uid", util.GeneratePaginatedResponse( - []map[string]interface{}{util.GenerateAgentResponseModel("uid", "")}, + []map[string]interface{}{ + util.GenerateAgentResponseModel("agent_uid", ""), + }, ), 2, ) diff --git a/test/mocked/resources/agent_test.go b/test/mocked/resources/agent_test.go index a4bf77f5..83e1cb3e 100644 --- a/test/mocked/resources/agent_test.go +++ b/test/mocked/resources/agent_test.go @@ -1,6 +1,10 @@ package resource_test import ( + "regexp" + "testing" + + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "github.com/h2non/gock" @@ -8,8 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-plugin-testing/tfversion" "github.com/nbio/st" - "regexp" - "testing" ) func TestAgentResource(t *testing.T) { @@ -88,6 +90,9 @@ func TestAgentResource(t *testing.T) { ), 1, ) + resources.UpdateAgent = func(request resources.AgentUpdateRequestModel) resources.AgentResponseModel { + return util.GenerateMockedAgentResponseModel("uid", "_2") + } // updated util.MockGetAgent( "uid", diff --git a/test/mocked/resources/sensor_test.go b/test/mocked/resources/sensor_test.go index fd70f8e3..ba90ae16 100644 --- a/test/mocked/resources/sensor_test.go +++ b/test/mocked/resources/sensor_test.go @@ -1,6 +1,7 @@ package resource_test import ( + "github.com/aruba-uxi/terraform-provider-configuration/internal/provider/resources" "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/provider" "github.com/aruba-uxi/terraform-provider-configuration/test/mocked/util" "regexp" @@ -91,6 +92,9 @@ func TestSensorResource(t *testing.T) { []map[string]interface{}{util.GenerateSensorResponseModel("uid", "")}), 1, ) + resources.UpdateSensor = func(request resources.SensorUpdateRequestModel) resources.SensorResponseModel { + return util.GenerateMockedSensorResponseModel("uid", "_2") + } // updated sensor util.MockGetSensor("uid", util.GeneratePaginatedResponse( []map[string]interface{}{util.GenerateSensorResponseModel("uid", "_2")}), diff --git a/test/mocked/util/utils.go b/test/mocked/util/utils.go index c691016a..6bcb7a2e 100644 --- a/test/mocked/util/utils.go +++ b/test/mocked/util/utils.go @@ -25,6 +25,22 @@ func GenerateSensorResponseModel(uid string, postfix string) map[string]interfac } } +func GenerateMockedSensorResponseModel(uid string, postfix string) resources.SensorResponseModel { + return resources.SensorResponseModel{ + UID: uid, + Serial: "serial" + postfix, + Name: "name" + postfix, + ModelNumber: "model_number" + postfix, + WifiMacAddress: "wifi_mac_address" + postfix, + EthernetMacAddress: "ethernet_mac_address" + postfix, + AddressNote: "address_note" + postfix, + Longitude: 0.0, + Latitude: 0.0, + Notes: "notes" + postfix, + PCapMode: "light" + postfix, + } +} + func GenerateAgentResponseModel(uid string, postfix string) map[string]interface{} { return map[string]interface{}{ "id": uid,