Skip to content

Commit

Permalink
fix issue in import and add new tests for data and import
Browse files Browse the repository at this point in the history
Signed-off-by: rafsaf <[email protected]>
  • Loading branch information
rafsaf committed Jan 19, 2025
1 parent 462c77e commit 9694059
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
4 changes: 1 addition & 3 deletions fwprovider/cluster/metrics/resource_metrics_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)...)
}
41 changes: 41 additions & 0 deletions fwprovider/test/resource_metrics_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9694059

Please sign in to comment.