weizhouapache opened a new issue, #358:
URL: https://github.com/apache/cloudstack-terraform-provider/issues/358

   The new Plugin Framework resources `cloudstack_service_offering_fixed`, 
`cloudstack_service_offering_constrained` and 
`cloudstack_service_offering_unconstrained` do not implement `ImportState`. 
Existing service offerings cannot be imported into them. The only importable 
resource is the deprecated `cloudstack_service_offering`, which prints a 
deprecation warning telling users to move to the new resources.
   
   Users cannot follow that guidance for offerings that already exist, so 
migrating to the new resources means destroying and recreating the offerings.
   
   ### Steps to reproduce
   
   1. Use provider `cloudstack/cloudstack` version `0.7.0`, with Terraform 
1.16.7.
   2. Create a fixed service offering in CloudStack (for example `test-fixed`, 
1 CPU, 500 MHz, 512 MB).
   3. Add the resource:
      ```hcl
      resource "cloudstack_service_offering_fixed" "test_fixed" {
        name         = "test-fixed"
        display_text = "test-fixed"
        cpu_number   = 1
        cpu_speed    = 500
        memory       = 512
      }
      ```
   4. Run:
      ```
      terraform import cloudstack_service_offering_fixed.test_fixed 
<offering-uuid>
      ```
      Importing inside a module with `for_each` gives the same result:
      ```
      terraform import 
'module.compute_offerings["test-fixed"].cloudstack_service_offering_fixed.compute_offering'
 <offering-uuid>
      ```
      An `import {}` block behaves the same way.
   
   ### Actual result
   
   ```
   Error: Resource Import Not Implemented
   This resource does not support import. Please contact the provider developer
   for additional information.
   ```
   
   ### Expected result
   
   The import succeeds, as it does for `cloudstack_service_offering`, and 
`terraform plan` shows no changes once the config matches the offering.
   
   ### Analysis
   
   In v0.7.0, `cloudstack/resource_cloudstack_service_offering.go` (SDKv2) sets 
`Importer: &schema.ResourceImporter{...}`. The new resources 
(`service_offering_fixed_resource.go` and the `_constrained` and 
`_unconstrained` equivalents) implement `Schema`, `Create`, `Read`, `Update`, 
`Delete`, `Configure` and `Metadata`, but not 
`resource.ResourceWithImportState`. A minimal fix would be to add 
`ImportState`, passing the ID through to `id`, to all three resources. `Read` 
is already implemented and works once the ID is in state.
   
   ### Workaround
   
   Import with the deprecated `cloudstack_service_offering`, then retype the 
state entry to the new resource type by editing the state JSON. The entry must 
keep only attributes that exist in the new schema. After that, `terraform plan` 
shows no changes, with one gotcha: if the offering has `dynamic_scaling_enabled 
= true`, it must be set in config, because the new resource defaults it to 
`false` and plans a replacement otherwise. This is a fragile workaround and not 
a real fix.
   
   ### Environment
   
   - Provider: `cloudstack/cloudstack` 0.7.0
   - Terraform: 1.16.7
   - CloudStack: 4.22
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to