Skip to content

Commit

Permalink
adding resources import function
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Aug 21, 2024
1 parent 67a3179 commit f22a283
Show file tree
Hide file tree
Showing 31 changed files with 585 additions and 66 deletions.
22 changes: 19 additions & 3 deletions internal/provider/device_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/device_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/device_gateway_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/device_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_deviceprofile_ap_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_deviceprofile_assign_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ 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"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

var (
_ resource.Resource = &orgDeviceprofileAssignResource{}
_ resource.ResourceWithConfigure = &orgDeviceprofileAssignResource{}
_ resource.Resource = &orgDeviceprofileAssignResource{}
_ resource.ResourceWithConfigure = &orgDeviceprofileAssignResource{}
_ resource.ResourceWithImportState = &orgDeviceprofileAssignResource{}
)

func NewOrgDeviceprofileAssign() resource.Resource {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_deviceprofile_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_gatewaytemplate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_idpprofile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
20 changes: 18 additions & 2 deletions internal/provider/org_inventory_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)...)
}
Loading

0 comments on commit f22a283

Please sign in to comment.