From f22a2833337fc6b6b63af35bc7ac919aa65e6eb0 Mon Sep 17 00:00:00 2001 From: Thomas Munzer Date: Wed, 21 Aug 2024 20:18:56 +0200 Subject: [PATCH] adding resources import function --- internal/provider/device_ap.go | 22 +++++++-- internal/provider/device_gateway.go | 20 +++++++- internal/provider/device_gateway_cluster.go | 20 +++++++- internal/provider/device_switch.go | 20 +++++++- .../provider/org_deviceprofile_ap_resource.go | 20 +++++++- .../org_deviceprofile_assign_resource.go | 20 +++++++- .../org_deviceprofile_gateway_resource.go | 20 +++++++- .../provider/org_gatewaytemplate_resource.go | 20 +++++++- internal/provider/org_idpprofile_resource.go | 20 +++++++- internal/provider/org_inventory_resource.go | 20 +++++++- internal/provider/org_nacrule_resource.go | 20 +++++++- internal/provider/org_nactag_resource.go | 20 +++++++- internal/provider/org_network_resource.go | 20 +++++++- .../provider/org_networktemplate_resource.go | 20 +++++++- internal/provider/org_resource.go | 49 +++++++++++++++++-- internal/provider/org_rftemplate_resource.go | 20 +++++++- internal/provider/org_service_resource.go | 20 +++++++- .../provider/org_servicepolicy_resource.go | 20 +++++++- internal/provider/org_setting_resource.go | 20 +++++++- internal/provider/org_sitegroup_resource.go | 20 +++++++- internal/provider/org_vpn_resource.go | 20 +++++++- internal/provider/org_wlan_resource.go | 20 +++++++- .../provider/org_wlantemplate_resource.go | 20 +++++++- internal/provider/org_wxrule_resource.go | 20 +++++++- internal/provider/org_wxtag_resource.go | 20 +++++++- .../provider/site_networktemplate_resource.go | 20 +++++++- internal/provider/site_resource.go | 20 +++++++- internal/provider/site_setting_resource.go | 20 +++++++- internal/provider/site_wlan_resource.go | 20 +++++++- internal/provider/site_wxrule_resource.go | 20 +++++++- internal/provider/site_wxtag_resource.go | 20 +++++++- 31 files changed, 585 insertions(+), 66 deletions(-) diff --git a/internal/provider/device_ap.go b/internal/provider/device_ap.go index a6814718..e12c9e68 100644 --- a/internal/provider/device_ap.go +++ b/internal/provider/device_ap.go @@ -13,14 +13,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi/models" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &deviceApResource{} - _ resource.ResourceWithConfigure = &deviceApResource{} + _ resource.Resource = &deviceApResource{} + _ resource.ResourceWithConfigure = &deviceApResource{} + _ resource.ResourceWithImportState = &deviceApResource{} ) func NewDeviceApResource() resource.Resource { @@ -32,7 +34,7 @@ type deviceApResource struct { } func (r *deviceApResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { - tflog.Info(ctx, "Configuring Mist DeviceAp client") + tflog.Info(ctx, "Configuring Mist DeviceAp Resource client") if req.ProviderData == nil { return } @@ -291,3 +293,17 @@ func (r *deviceApResource) Delete(ctx context.Context, req resource.DeleteReques return } } + +func (r *deviceApResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/device_gateway.go b/internal/provider/device_gateway.go index 96586479..a30326e5 100644 --- a/internal/provider/device_gateway.go +++ b/internal/provider/device_gateway.go @@ -13,14 +13,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi/models" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &deviceGatewayResource{} - _ resource.ResourceWithConfigure = &deviceGatewayResource{} + _ resource.Resource = &deviceGatewayResource{} + _ resource.ResourceWithConfigure = &deviceGatewayResource{} + _ resource.ResourceWithImportState = &deviceGatewayResource{} ) func NewDeviceGatewayResource() resource.Resource { @@ -292,3 +294,17 @@ func (r *deviceGatewayResource) Delete(ctx context.Context, req resource.DeleteR return } } + +func (r *deviceGatewayResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/device_gateway_cluster.go b/internal/provider/device_gateway_cluster.go index 8bc764f2..76074cbc 100644 --- a/internal/provider/device_gateway_cluster.go +++ b/internal/provider/device_gateway_cluster.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &deviceGatewayClusterResource{} - _ resource.ResourceWithConfigure = &deviceGatewayClusterResource{} + _ resource.Resource = &deviceGatewayClusterResource{} + _ resource.ResourceWithConfigure = &deviceGatewayClusterResource{} + _ resource.ResourceWithImportState = &deviceGatewayClusterResource{} ) func NewDeviceGatewayClusterResource() resource.Resource { @@ -300,3 +302,17 @@ func (r *deviceGatewayClusterResource) Delete(ctx context.Context, req resource. return } } + +func (r *deviceGatewayClusterResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/device_switch.go b/internal/provider/device_switch.go index 6b7866e6..8e4f995a 100644 --- a/internal/provider/device_switch.go +++ b/internal/provider/device_switch.go @@ -13,14 +13,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi/models" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &deviceSwitchResource{} - _ resource.ResourceWithConfigure = &deviceSwitchResource{} + _ resource.Resource = &deviceSwitchResource{} + _ resource.ResourceWithConfigure = &deviceSwitchResource{} + _ resource.ResourceWithImportState = &deviceSwitchResource{} ) func NewDeviceSwitchResource() resource.Resource { @@ -292,3 +294,17 @@ func (r *deviceSwitchResource) Delete(ctx context.Context, req resource.DeleteRe return } } + +func (r *deviceSwitchResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_deviceprofile_ap_resource.go b/internal/provider/org_deviceprofile_ap_resource.go index 4f60064d..632db7f5 100644 --- a/internal/provider/org_deviceprofile_ap_resource.go +++ b/internal/provider/org_deviceprofile_ap_resource.go @@ -12,14 +12,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_deviceprofile_ap" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgDeviceprofileApResource{} - _ resource.ResourceWithConfigure = &orgDeviceprofileApResource{} + _ resource.Resource = &orgDeviceprofileApResource{} + _ resource.ResourceWithConfigure = &orgDeviceprofileApResource{} + _ resource.ResourceWithImportState = &orgDeviceprofileApResource{} ) func NewOrgDeviceprofileAp() resource.Resource { @@ -281,3 +283,17 @@ func (r *orgDeviceprofileApResource) Delete(ctx context.Context, req resource.De return } } + +func (r *orgDeviceprofileApResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_deviceprofile_assign_resource.go b/internal/provider/org_deviceprofile_assign_resource.go index 29fba5a1..80806dd2 100644 --- a/internal/provider/org_deviceprofile_assign_resource.go +++ b/internal/provider/org_deviceprofile_assign_resource.go @@ -10,6 +10,7 @@ import ( "github.com/tmunzer/mistapi-go/mistapi/models" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -17,8 +18,9 @@ import ( ) var ( - _ resource.Resource = &orgDeviceprofileAssignResource{} - _ resource.ResourceWithConfigure = &orgDeviceprofileAssignResource{} + _ resource.Resource = &orgDeviceprofileAssignResource{} + _ resource.ResourceWithConfigure = &orgDeviceprofileAssignResource{} + _ resource.ResourceWithImportState = &orgDeviceprofileAssignResource{} ) func NewOrgDeviceprofileAssign() resource.Resource { @@ -285,3 +287,17 @@ func (r *orgDeviceprofileAssignResource) unassign(ctx context.Context, orgId uui return nil, nil } } + +func (r *orgDeviceprofileAssignResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_deviceprofile_gateway_resource.go b/internal/provider/org_deviceprofile_gateway_resource.go index a4017aa1..81a6187e 100644 --- a/internal/provider/org_deviceprofile_gateway_resource.go +++ b/internal/provider/org_deviceprofile_gateway_resource.go @@ -12,14 +12,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_deviceprofile_gateway" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgDeviceprofileGatewayResource{} - _ resource.ResourceWithConfigure = &orgDeviceprofileGatewayResource{} + _ resource.Resource = &orgDeviceprofileGatewayResource{} + _ resource.ResourceWithConfigure = &orgDeviceprofileGatewayResource{} + _ resource.ResourceWithImportState = &orgDeviceprofileGatewayResource{} ) func NewOrgDeviceprofileGateway() resource.Resource { @@ -280,3 +282,17 @@ func (r *orgDeviceprofileGatewayResource) Delete(ctx context.Context, req resour return } } + +func (r *orgDeviceprofileGatewayResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_gatewaytemplate_resource.go b/internal/provider/org_gatewaytemplate_resource.go index 6edaa4ed..1b31c58c 100644 --- a/internal/provider/org_gatewaytemplate_resource.go +++ b/internal/provider/org_gatewaytemplate_resource.go @@ -10,14 +10,16 @@ import ( "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgGatewaytemplateResource{} - _ resource.ResourceWithConfigure = &orgGatewaytemplateResource{} + _ resource.Resource = &orgGatewaytemplateResource{} + _ resource.ResourceWithConfigure = &orgGatewaytemplateResource{} + _ resource.ResourceWithImportState = &orgGatewaytemplateResource{} ) func NewOrgGatewayTemplate() resource.Resource { @@ -256,3 +258,17 @@ func (r *orgGatewaytemplateResource) Delete(ctx context.Context, req resource.De return } } + +func (r *orgGatewaytemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_idpprofile_resource.go b/internal/provider/org_idpprofile_resource.go index f96540f4..fa3ca953 100644 --- a/internal/provider/org_idpprofile_resource.go +++ b/internal/provider/org_idpprofile_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_idpprofile" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgOrgIdpprofileResource{} - _ resource.ResourceWithConfigure = &orgOrgIdpprofileResource{} + _ resource.Resource = &orgOrgIdpprofileResource{} + _ resource.ResourceWithConfigure = &orgOrgIdpprofileResource{} + _ resource.ResourceWithImportState = &orgOrgIdpprofileResource{} ) func NewOrgIdpprofileResource() resource.Resource { @@ -204,3 +206,17 @@ func (r *orgOrgIdpprofileResource) Delete(ctx context.Context, req resource.Dele return } } + +func (r *orgOrgIdpprofileResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_inventory_resource.go b/internal/provider/org_inventory_resource.go index 4944ac90..4ef0aac7 100644 --- a/internal/provider/org_inventory_resource.go +++ b/internal/provider/org_inventory_resource.go @@ -13,14 +13,16 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgInventoryResource{} - _ resource.ResourceWithConfigure = &orgInventoryResource{} + _ resource.Resource = &orgInventoryResource{} + _ resource.ResourceWithConfigure = &orgInventoryResource{} + _ resource.ResourceWithImportState = &orgInventoryResource{} ) func NewOrgInventory() resource.Resource { @@ -337,3 +339,17 @@ func (r *orgInventoryResource) refreshInventory(ctx context.Context, orgId *uuid return state, diags } + +func (r *orgInventoryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_nacrule_resource.go b/internal/provider/org_nacrule_resource.go index 2ce05200..223e2b25 100644 --- a/internal/provider/org_nacrule_resource.go +++ b/internal/provider/org_nacrule_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_nacrule" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgNacRuleResource{} - _ resource.ResourceWithConfigure = &orgNacRuleResource{} + _ resource.Resource = &orgNacRuleResource{} + _ resource.ResourceWithConfigure = &orgNacRuleResource{} + _ resource.ResourceWithImportState = &orgNacRuleResource{} ) func NewOrgNacRule() resource.Resource { @@ -253,3 +255,17 @@ func (r *orgNacRuleResource) Delete(ctx context.Context, req resource.DeleteRequ return } } + +func (r *orgNacRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_nactag_resource.go b/internal/provider/org_nactag_resource.go index f7691f5d..9b20c4a8 100644 --- a/internal/provider/org_nactag_resource.go +++ b/internal/provider/org_nactag_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_nactag" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgNacTagResource{} - _ resource.ResourceWithConfigure = &orgNacTagResource{} + _ resource.Resource = &orgNacTagResource{} + _ resource.ResourceWithConfigure = &orgNacTagResource{} + _ resource.ResourceWithImportState = &orgNacTagResource{} ) func NewOrgNacTag() resource.Resource { @@ -254,3 +256,17 @@ func (r *orgNacTagResource) Delete(ctx context.Context, req resource.DeleteReque return } } + +func (r *orgNacTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_network_resource.go b/internal/provider/org_network_resource.go index 822e327c..f5e34acf 100644 --- a/internal/provider/org_network_resource.go +++ b/internal/provider/org_network_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_network" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgNetworkResource{} - _ resource.ResourceWithConfigure = &orgNetworkResource{} + _ resource.Resource = &orgNetworkResource{} + _ resource.ResourceWithConfigure = &orgNetworkResource{} + _ resource.ResourceWithImportState = &orgNetworkResource{} ) func NewOrgNetworkResource() resource.Resource { @@ -256,3 +258,17 @@ func (r *orgNetworkResource) Delete(ctx context.Context, req resource.DeleteRequ return } } + +func (r *orgNetworkResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_networktemplate_resource.go b/internal/provider/org_networktemplate_resource.go index 7f91b729..9a2fb21d 100644 --- a/internal/provider/org_networktemplate_resource.go +++ b/internal/provider/org_networktemplate_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgNetworkTemplateResource{} - _ resource.ResourceWithConfigure = &orgNetworkTemplateResource{} + _ resource.Resource = &orgNetworkTemplateResource{} + _ resource.ResourceWithConfigure = &orgNetworkTemplateResource{} + _ resource.ResourceWithImportState = &orgNetworkTemplateResource{} ) func NewOrgNetworkTemplate() resource.Resource { @@ -245,3 +247,17 @@ func (r *orgNetworkTemplateResource) Delete(ctx context.Context, req resource.De return } } + +func (r *orgNetworkTemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_resource.go b/internal/provider/org_resource.go index 09b99478..9ac4e635 100644 --- a/internal/provider/org_resource.go +++ b/internal/provider/org_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgResource{} - _ resource.ResourceWithConfigure = &orgResource{} + _ resource.Resource = &orgResource{} + _ resource.ResourceWithConfigure = &orgResource{} + _ resource.ResourceWithImportState = &orgResource{} ) func NewOrgResource() resource.Resource { @@ -104,7 +106,15 @@ func (r *orgResource) Read(ctx context.Context, req resource.ReadRequest, resp * return } - orgId := uuid.MustParse(state.Id.ValueString()) + orgId, err := uuid.Parse(state.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from plan", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + tflog.Info(ctx, "Starting Org Read: org_id "+state.Id.ValueString()) httpr, err := r.client.Orgs().GetOrg(ctx, orgId) if httpr.Response.StatusCode == 404 { @@ -145,7 +155,15 @@ func (r *orgResource) Update(ctx context.Context, req resource.UpdateRequest, re return } - orgId := uuid.MustParse(state.Id.ValueString()) + orgId, err := uuid.Parse(state.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from plan", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + org, diags := resource_org.TerraformToSdk(&plan) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -186,7 +204,14 @@ func (r *orgResource) Delete(ctx context.Context, req resource.DeleteRequest, re return } - orgId := uuid.MustParse(state.Id.ValueString()) + orgId, err := uuid.Parse(state.Id.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from plan", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } tflog.Info(ctx, "Starting Org Delete: org_id "+state.Id.ValueString()) httpr, err := r.client.Orgs().DeleteOrg(ctx, orgId) @@ -198,3 +223,17 @@ func (r *orgResource) Delete(ctx context.Context, req resource.DeleteRequest, re return } } + +func (r *orgResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_rftemplate_resource.go b/internal/provider/org_rftemplate_resource.go index 11010f51..8bfa878d 100644 --- a/internal/provider/org_rftemplate_resource.go +++ b/internal/provider/org_rftemplate_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_rftemplate" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgRfTemplateResource{} - _ resource.ResourceWithConfigure = &orgRfTemplateResource{} + _ resource.Resource = &orgRfTemplateResource{} + _ resource.ResourceWithConfigure = &orgRfTemplateResource{} + _ resource.ResourceWithImportState = &orgRfTemplateResource{} ) func NewOrgRfTemplate() resource.Resource { @@ -202,3 +204,17 @@ func (r *orgRfTemplateResource) Delete(ctx context.Context, req resource.DeleteR return } } + +func (r *orgRfTemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_service_resource.go b/internal/provider/org_service_resource.go index f760f1d0..ebd9ac5c 100644 --- a/internal/provider/org_service_resource.go +++ b/internal/provider/org_service_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_service" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgOrgServiceResource{} - _ resource.ResourceWithConfigure = &orgOrgServiceResource{} + _ resource.Resource = &orgOrgServiceResource{} + _ resource.ResourceWithConfigure = &orgOrgServiceResource{} + _ resource.ResourceWithImportState = &orgOrgServiceResource{} ) func NewOrgServiceResource() resource.Resource { @@ -202,3 +204,17 @@ func (r *orgOrgServiceResource) Delete(ctx context.Context, req resource.DeleteR return } } + +func (r *orgOrgServiceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_servicepolicy_resource.go b/internal/provider/org_servicepolicy_resource.go index 9cb33496..16edc0fd 100644 --- a/internal/provider/org_servicepolicy_resource.go +++ b/internal/provider/org_servicepolicy_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_servicepolicy" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgOrgServicepolicyResource{} - _ resource.ResourceWithConfigure = &orgOrgServicepolicyResource{} + _ resource.Resource = &orgOrgServicepolicyResource{} + _ resource.ResourceWithConfigure = &orgOrgServicepolicyResource{} + _ resource.ResourceWithImportState = &orgOrgServicepolicyResource{} ) func NewOrgServicepolicyResource() resource.Resource { @@ -202,3 +204,17 @@ func (r *orgOrgServicepolicyResource) Delete(ctx context.Context, req resource.D return } } + +func (r *orgOrgServicepolicyResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_setting_resource.go b/internal/provider/org_setting_resource.go index bb3f66e9..730e8a2b 100644 --- a/internal/provider/org_setting_resource.go +++ b/internal/provider/org_setting_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgSettingResource{} - _ resource.ResourceWithConfigure = &orgSettingResource{} + _ resource.Resource = &orgSettingResource{} + _ resource.ResourceWithConfigure = &orgSettingResource{} + _ resource.ResourceWithImportState = &orgSettingResource{} ) func NewOrgSettingResource() resource.Resource { @@ -229,3 +231,17 @@ func (r *orgSettingResource) Delete(ctx context.Context, req resource.DeleteRequ return } } + +func (r *orgSettingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_sitegroup_resource.go b/internal/provider/org_sitegroup_resource.go index 47116cfb..7a721812 100644 --- a/internal/provider/org_sitegroup_resource.go +++ b/internal/provider/org_sitegroup_resource.go @@ -11,14 +11,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi/models" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgSiteGroupResource{} - _ resource.ResourceWithConfigure = &orgSiteGroupResource{} + _ resource.Resource = &orgSiteGroupResource{} + _ resource.ResourceWithConfigure = &orgSiteGroupResource{} + _ resource.ResourceWithImportState = &orgSiteGroupResource{} ) func NewOrgSiteGroupResource() resource.Resource { @@ -204,3 +206,17 @@ func (r *orgSiteGroupResource) Delete(ctx context.Context, req resource.DeleteRe return } } + +func (r *orgSiteGroupResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_vpn_resource.go b/internal/provider/org_vpn_resource.go index 58a1bb26..2d50f20c 100644 --- a/internal/provider/org_vpn_resource.go +++ b/internal/provider/org_vpn_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgVpnResource{} - _ resource.ResourceWithConfigure = &orgVpnResource{} + _ resource.Resource = &orgVpnResource{} + _ resource.ResourceWithConfigure = &orgVpnResource{} + _ resource.ResourceWithImportState = &orgVpnResource{} ) func NewOrgVpn() resource.Resource { @@ -201,3 +203,17 @@ func (r *orgVpnResource) Delete(ctx context.Context, req resource.DeleteRequest, return } } + +func (r *orgVpnResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_wlan_resource.go b/internal/provider/org_wlan_resource.go index 4dde8b43..9ed88843 100644 --- a/internal/provider/org_wlan_resource.go +++ b/internal/provider/org_wlan_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgWlanResource{} - _ resource.ResourceWithConfigure = &orgWlanResource{} + _ resource.Resource = &orgWlanResource{} + _ resource.ResourceWithConfigure = &orgWlanResource{} + _ resource.ResourceWithImportState = &orgWlanResource{} ) func NewOrgWlan() resource.Resource { @@ -202,3 +204,17 @@ func (r *orgWlanResource) Delete(ctx context.Context, req resource.DeleteRequest return } } + +func (r *orgWlanResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_wlantemplate_resource.go b/internal/provider/org_wlantemplate_resource.go index ecbfe81e..ff6d68dc 100644 --- a/internal/provider/org_wlantemplate_resource.go +++ b/internal/provider/org_wlantemplate_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgWlanTemplateResource{} - _ resource.ResourceWithConfigure = &orgWlanTemplateResource{} + _ resource.Resource = &orgWlanTemplateResource{} + _ resource.ResourceWithConfigure = &orgWlanTemplateResource{} + _ resource.ResourceWithImportState = &orgWlanTemplateResource{} ) func NewOrgWlanTemplate() resource.Resource { @@ -205,3 +207,17 @@ func (r *orgWlanTemplateResource) Delete(ctx context.Context, req resource.Delet return } } + +func (r *orgWlanTemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_wxrule_resource.go b/internal/provider/org_wxrule_resource.go index 57f8ca19..7fb9aadd 100644 --- a/internal/provider/org_wxrule_resource.go +++ b/internal/provider/org_wxrule_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_wxrule" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgWxRuleResource{} - _ resource.ResourceWithConfigure = &orgWxRuleResource{} + _ resource.Resource = &orgWxRuleResource{} + _ resource.ResourceWithConfigure = &orgWxRuleResource{} + _ resource.ResourceWithImportState = &orgWxRuleResource{} ) func NewOrgWxRule() resource.Resource { @@ -205,3 +207,17 @@ func (r *orgWxRuleResource) Delete(ctx context.Context, req resource.DeleteReque return } } + +func (r *orgWxRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/org_wxtag_resource.go b/internal/provider/org_wxtag_resource.go index a6e5629e..b23a2f76 100644 --- a/internal/provider/org_wxtag_resource.go +++ b/internal/provider/org_wxtag_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_org_wxtag" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &orgWxTagResource{} - _ resource.ResourceWithConfigure = &orgWxTagResource{} + _ resource.Resource = &orgWxTagResource{} + _ resource.ResourceWithConfigure = &orgWxTagResource{} + _ resource.ResourceWithImportState = &orgWxTagResource{} ) func NewOrgWxTag() resource.Resource { @@ -207,3 +209,17 @@ func (r *orgWxTagResource) Delete(ctx context.Context, req resource.DeleteReques return } } + +func (r *orgWxTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_networktemplate_resource.go b/internal/provider/site_networktemplate_resource.go index bd89d0ab..b1123db2 100644 --- a/internal/provider/site_networktemplate_resource.go +++ b/internal/provider/site_networktemplate_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteNetworkTemplateResource{} - _ resource.ResourceWithConfigure = &siteNetworkTemplateResource{} + _ resource.Resource = &siteNetworkTemplateResource{} + _ resource.ResourceWithConfigure = &siteNetworkTemplateResource{} + _ resource.ResourceWithImportState = &siteNetworkTemplateResource{} ) func NewSiteNetworkTemplate() resource.Resource { @@ -201,3 +203,17 @@ func (r *siteNetworkTemplateResource) Delete(ctx context.Context, req resource.D return } } + +func (r *siteNetworkTemplateResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_resource.go b/internal/provider/site_resource.go index a193139c..bd073912 100644 --- a/internal/provider/site_resource.go +++ b/internal/provider/site_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteResource{} - _ resource.ResourceWithConfigure = &siteResource{} + _ resource.Resource = &siteResource{} + _ resource.ResourceWithConfigure = &siteResource{} + _ resource.ResourceWithImportState = &siteResource{} ) func NewSiteResource() resource.Resource { @@ -199,3 +201,17 @@ func (r *siteResource) Delete(ctx context.Context, req resource.DeleteRequest, r return } } + +func (r *siteResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_setting_resource.go b/internal/provider/site_setting_resource.go index 6fe69d1c..df1eef6f 100644 --- a/internal/provider/site_setting_resource.go +++ b/internal/provider/site_setting_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteSettingResource{} - _ resource.ResourceWithConfigure = &siteSettingResource{} + _ resource.Resource = &siteSettingResource{} + _ resource.ResourceWithConfigure = &siteSettingResource{} + _ resource.ResourceWithImportState = &siteSettingResource{} ) func NewSiteSettingResource() resource.Resource { @@ -201,3 +203,17 @@ func (r *siteSettingResource) Delete(ctx context.Context, req resource.DeleteReq return } } + +func (r *siteSettingResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_wlan_resource.go b/internal/provider/site_wlan_resource.go index 61b3f978..c4cdad63 100644 --- a/internal/provider/site_wlan_resource.go +++ b/internal/provider/site_wlan_resource.go @@ -9,14 +9,16 @@ import ( "github.com/tmunzer/mistapi-go/mistapi" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteWlanResource{} - _ resource.ResourceWithConfigure = &siteWlanResource{} + _ resource.Resource = &siteWlanResource{} + _ resource.ResourceWithConfigure = &siteWlanResource{} + _ resource.ResourceWithImportState = &siteWlanResource{} ) func NewSiteWlan() resource.Resource { @@ -201,3 +203,17 @@ func (r *siteWlanResource) Delete(ctx context.Context, req resource.DeleteReques return } } + +func (r *siteWlanResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_wxrule_resource.go b/internal/provider/site_wxrule_resource.go index 77e777e0..28a11fd2 100644 --- a/internal/provider/site_wxrule_resource.go +++ b/internal/provider/site_wxrule_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_site_wxrule" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteWxRuleResource{} - _ resource.ResourceWithConfigure = &siteWxRuleResource{} + _ resource.Resource = &siteWxRuleResource{} + _ resource.ResourceWithConfigure = &siteWxRuleResource{} + _ resource.ResourceWithImportState = &siteWxRuleResource{} ) func NewSiteWxRule() resource.Resource { @@ -205,3 +207,17 @@ func (r *siteWxRuleResource) Delete(ctx context.Context, req resource.DeleteRequ return } } + +func (r *siteWxRuleResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +} diff --git a/internal/provider/site_wxtag_resource.go b/internal/provider/site_wxtag_resource.go index 48de703b..4d4fca69 100644 --- a/internal/provider/site_wxtag_resource.go +++ b/internal/provider/site_wxtag_resource.go @@ -9,14 +9,16 @@ import ( "github.com/Juniper/terraform-provider-mist/internal/resource_site_wxtag" "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-log/tflog" ) var ( - _ resource.Resource = &siteWxTagResource{} - _ resource.ResourceWithConfigure = &siteWxTagResource{} + _ resource.Resource = &siteWxTagResource{} + _ resource.ResourceWithConfigure = &siteWxTagResource{} + _ resource.ResourceWithImportState = &siteWxTagResource{} ) func NewSiteWxTag() resource.Resource { @@ -210,3 +212,17 @@ func (r *siteWxTagResource) Delete(ctx context.Context, req resource.DeleteReque return } } + +func (r *siteWxTagResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + + _, err := uuid.Parse(req.ID) + if err != nil { + resp.Diagnostics.AddError( + "Error getting org id from import", + "Could not get org id, unexpected error: "+err.Error(), + ) + return + } + + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), req.ID)...) +}