From c10fc9ac2c918e5de9aa6913b36a2d2b7f8c562b Mon Sep 17 00:00:00 2001 From: dheeraj12347 Date: Wed, 28 Oct 2026 12:34:36 +0000 Subject: [PATCH] Add import support for service offering resources --- .../service_offering_constrained_resource.go | 14 ++++++++++++-- .../service_offering_constrained_resource_test.go | 5 +++++ cloudstack/service_offering_fixed_resource.go | 14 ++++++++++++-- cloudstack/service_offering_fixed_resource_test.go | 5 +++++ .../service_offering_unconstrained_resource.go | 14 ++++++++++++-- ...service_offering_unconstrained_resource_test.go | 5 +++++ 6 files changed, 51 insertions(+), 6 deletions(-) diff --git a/cloudstack/service_offering_constrained_resource.go b/cloudstack/service_offering_constrained_resource.go index 92c80779..74bb9efc 100644 --- a/cloudstack/service_offering_constrained_resource.go +++ b/cloudstack/service_offering_constrained_resource.go @@ -25,6 +25,7 @@ import ( "strconv" "github.com/apache/cloudstack-go/v2/cloudstack" + "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/resource/schema/int32planmodifier" @@ -34,8 +35,9 @@ import ( ) var ( - _ resource.Resource = &serviceOfferingConstrainedResource{} - _ resource.ResourceWithConfigure = &serviceOfferingConstrainedResource{} + _ resource.Resource = &serviceOfferingConstrainedResource{} + _ resource.ResourceWithConfigure = &serviceOfferingConstrainedResource{} + _ resource.ResourceWithImportState = &serviceOfferingConstrainedResource{} ) func NewserviceOfferingConstrainedResource() resource.Resource { @@ -311,3 +313,11 @@ func (r *serviceOfferingConstrainedResource) Configure(_ context.Context, req re func (r *serviceOfferingConstrainedResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_service_offering_constrained" } + +func (r *serviceOfferingConstrainedResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/cloudstack/service_offering_constrained_resource_test.go b/cloudstack/service_offering_constrained_resource_test.go index 5368db7b..21055738 100644 --- a/cloudstack/service_offering_constrained_resource_test.go +++ b/cloudstack/service_offering_constrained_resource_test.go @@ -72,6 +72,11 @@ func TestAccServiceOfferingConstrained(t *testing.T) { resource.TestCheckResourceAttr("cloudstack_service_offering_constrained.disk_storage", "name", "disk_storage"), ), }, + { + ResourceName: "cloudstack_service_offering_constrained.disk_storage", + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/cloudstack/service_offering_fixed_resource.go b/cloudstack/service_offering_fixed_resource.go index 6b500fd2..0f69aa16 100644 --- a/cloudstack/service_offering_fixed_resource.go +++ b/cloudstack/service_offering_fixed_resource.go @@ -24,6 +24,7 @@ import ( "fmt" "github.com/apache/cloudstack-go/v2/cloudstack" + "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/resource/schema/int32planmodifier" @@ -33,8 +34,9 @@ import ( ) var ( - _ resource.Resource = &serviceOfferingFixedResource{} - _ resource.ResourceWithConfigure = &serviceOfferingFixedResource{} + _ resource.Resource = &serviceOfferingFixedResource{} + _ resource.ResourceWithConfigure = &serviceOfferingFixedResource{} + _ resource.ResourceWithImportState = &serviceOfferingFixedResource{} ) func NewserviceOfferingFixedResource() resource.Resource { @@ -249,3 +251,11 @@ func (r *serviceOfferingFixedResource) Configure(_ context.Context, req resource func (r *serviceOfferingFixedResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_service_offering_fixed" } + +func (r *serviceOfferingFixedResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/cloudstack/service_offering_fixed_resource_test.go b/cloudstack/service_offering_fixed_resource_test.go index 438740e0..d2c35899 100644 --- a/cloudstack/service_offering_fixed_resource_test.go +++ b/cloudstack/service_offering_fixed_resource_test.go @@ -66,6 +66,11 @@ func TestAccServiceOfferingFixed(t *testing.T) { resource.TestCheckResourceAttr("cloudstack_service_offering_fixed.disk_storage", "name", "disk_storage"), ), }, + { + ResourceName: "cloudstack_service_offering_fixed.disk_storage", + ImportState: true, + ImportStateVerify: true, + }, }, }) } diff --git a/cloudstack/service_offering_unconstrained_resource.go b/cloudstack/service_offering_unconstrained_resource.go index 98b937cd..e1768362 100644 --- a/cloudstack/service_offering_unconstrained_resource.go +++ b/cloudstack/service_offering_unconstrained_resource.go @@ -24,6 +24,7 @@ import ( "fmt" "github.com/apache/cloudstack-go/v2/cloudstack" + "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" @@ -31,8 +32,9 @@ import ( ) var ( - _ resource.Resource = &serviceOfferingUnconstrainedResource{} - _ resource.ResourceWithConfigure = &serviceOfferingUnconstrainedResource{} + _ resource.Resource = &serviceOfferingUnconstrainedResource{} + _ resource.ResourceWithConfigure = &serviceOfferingUnconstrainedResource{} + _ resource.ResourceWithImportState = &serviceOfferingUnconstrainedResource{} ) func NewserviceOfferingUnconstrainedResource() resource.Resource { @@ -202,3 +204,11 @@ func (r *serviceOfferingUnconstrainedResource) Configure(_ context.Context, req func (r *serviceOfferingUnconstrainedResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { resp.TypeName = req.ProviderTypeName + "_service_offering_unconstrained" } + +func (r *serviceOfferingUnconstrainedResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { + resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) +} diff --git a/cloudstack/service_offering_unconstrained_resource_test.go b/cloudstack/service_offering_unconstrained_resource_test.go index 5aba779f..2dafecf7 100644 --- a/cloudstack/service_offering_unconstrained_resource_test.go +++ b/cloudstack/service_offering_unconstrained_resource_test.go @@ -66,6 +66,11 @@ func TestAccServiceOfferingUnconstrained(t *testing.T) { resource.TestCheckResourceAttr("cloudstack_service_offering_unconstrained.disk_storage", "name", "disk_storage"), ), }, + { + ResourceName: "cloudstack_service_offering_unconstrained.disk_storage", + ImportState: true, + ImportStateVerify: true, + }, }, }) }