From 9694059020386de1464070a41be65c1fc60a12fd Mon Sep 17 00:00:00 2001 From: rafsaf Date: Sun, 19 Jan 2025 13:57:39 +0100 Subject: [PATCH] fix issue in import and add new tests for data and import Signed-off-by: rafsaf --- .../metrics/resource_metrics_server.go | 4 +- .../test/resource_metrics_server_test.go | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/fwprovider/cluster/metrics/resource_metrics_server.go b/fwprovider/cluster/metrics/resource_metrics_server.go index 4949643e..4555006d 100644 --- a/fwprovider/cluster/metrics/resource_metrics_server.go +++ b/fwprovider/cluster/metrics/resource_metrics_server.go @@ -345,8 +345,6 @@ func (r *metricsServerResource) ImportState( req resource.ImportStateRequest, resp *resource.ImportStateResponse, ) { - var state metricsServerModel - data, err := r.client.GetServer(ctx, req.ID) if err != nil { if errors.Is(err, api.ErrResourceDoesNotExist) { @@ -369,7 +367,7 @@ func (r *metricsServerResource) ImportState( } readModel := &metricsServerModel{} - readModel.importFromAPI(state.ID.ValueString(), data) + readModel.importFromAPI(req.ID, data) resp.Diagnostics.Append(resp.State.Set(ctx, readModel)...) } diff --git a/fwprovider/test/resource_metrics_server_test.go b/fwprovider/test/resource_metrics_server_test.go index 1c563e08..ec3290a0 100644 --- a/fwprovider/test/resource_metrics_server_test.go +++ b/fwprovider/test/resource_metrics_server_test.go @@ -123,6 +123,47 @@ func TestAccResourceMetricsServer(t *testing.T) { ), }, }}, + {"create graphite udp metrics server & import it", []resource.TestStep{ + { + ResourceName: "proxmox_virtual_environment_metrics_server.acc_graphite_server", + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_metrics_server" "acc_graphite_server" { + name = "acc_example_graphite_server" + server = "192.168.3.2" + port = 18089 + type = "graphite" + }`), + }, + { + ResourceName: "proxmox_virtual_environment_metrics_server.acc_graphite_server", + ImportState: true, + ImportStateVerify: true, + }, + }}, + {"create graphite udp metrics server & test datasource", []resource.TestStep{ + { + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_metrics_server" "acc_graphite_server2" { + name = "acc_example_graphite_server2" + server = "192.168.3.2" + port = 18089 + type = "graphite" + } + data "proxmox_virtual_environment_metrics_server" "acc_graphite_server2" { + name = proxmox_virtual_environment_metrics_server.acc_graphite_server2.name + }`), + Check: resource.ComposeTestCheckFunc( + ResourceAttributes("data.proxmox_virtual_environment_metrics_server.acc_graphite_server2", map[string]string{ + "id": "acc_example_graphite_server2", + "name": "acc_example_graphite_server2", + "port": "18089", + "server": "192.168.3.2", + "type": "graphite", + }), + ), + PreventPostDestroyRefresh: true, + }, + }}, } for _, tt := range tests {