Skip to content

Conversation

@jeanvetorello
Copy link
Contributor

Overview

This PR completely updates the cloudstack_service_offering resource to support CloudStack API version 4.21, achieving 100% SDK coverage with all 54 parameters from CreateServiceOfferingParams fully implemented.

Motivation

I needed to update the Service Offering API to the latest CloudStack version (4.21) to support modern features like GPU configuration, advanced IOPS settings, and dynamic scaling. The existing implementation was missing critical parameters and had several drift issues.

What's New

1. Complete API v4.21 Coverage (54/54 Parameters)

All parameters from CloudStack Go SDK v2 CreateServiceOfferingParams are now implemented:

CPU & Memory:

  • cpu_number, cpu_speed, memory
  • customized, min_cpu_number, max_cpu_number
  • min_memory, max_memory

GPU Support (NEW):

  • gpu_card - GPU card name (maps to gpucardid)
  • gpu_type - vGPU profile UUID (maps to vgpuprofileid)
  • gpu_count - Number of GPUs

Storage:

  • storage_type, storage_tags, host_tags
  • root_disk_size, encrypt_root
  • provisioning_type, cache_mode

IOPS & Bandwidth (12 parameters):

  • bytes_read_rate, bytes_write_rate
  • bytes_read_rate_max, bytes_write_rate_max
  • bytes_read_rate_max_length, bytes_write_rate_max_length
  • iops_read_rate, iops_write_rate
  • iops_read_rate_max, iops_write_rate_max
  • iops_read_rate_max_length, iops_write_rate_max_length

Performance:

  • disk_iops_min, disk_iops_max
  • hypervisor_snapshot_reserve
  • offer_ha, limit_cpu_use
  • dynamic_scaling_enabled
  • customized_iops

System & Domain:

  • is_system, system_vm_type
  • zone_id, domain_id
  • is_volatile, deployment_planner

Advanced:

  • service_offering_details (map for custom settings)

2. Bug Fixes

Fixed service_offering_details Drift

  • Problem: CloudStack adds system keys (External:key, External:value, purge.db.entities) causing state drift
  • Solution: Implemented filtering in Read function (lines 847-863) to only track user-configured keys

Fixed customized Parameter Logic

  • Problem: Incorrect handling of Fixed vs Custom offerings
  • Solution: Smart conditional logic based on CPU/memory presence:
    • If cpu_number + memory provided → customized = false (Fixed Offering)
    • If customized = true + min/max → Custom Constrained
    • If customized = true + no limits → Custom Unconstrained

Identified ForceNew Parameters (47 of 54)

  • Problem: Most CloudStack Service Offering parameters are immutable after creation
  • Solution: Added ForceNew: true to 47 parameters based on CloudStack API limitations
  • Updateable: Only display_text, host_tags, and storage_tags can be updated in-place

3. Comprehensive Testing

Added 4 new tests covering all CloudStack UI offering types:

  • TestAccServiceOfferingTypeFixed - Fixed CPU/memory
  • TestAccServiceOfferingTypeCustomConstrained - Customizable with limits
  • TestAccServiceOfferingTypeCustomUnconstrained - Fully customizable
  • TestAccServiceOfferingAllUITypes - All types together

Total: 17 tests (13 existing + 4 new)

4. Complete Documentation

Created comprehensive documentation in website/docs/r/service_offering.html.markdown:

  • Detailed explanation of all 3 offering types with decision tree
  • GPU configuration examples (A6000, A100, H100, RTX 4090, Multi-GPU)
  • IOPS/bandwidth configuration examples
  • High-performance offerings
  • ForceNew behavior documentation
  • CloudStack API behavior notes

jean and others added 14 commits October 15, 2025 10:06
- Add service_offering_details attribute to cloudstack_service_offering resource
- Support for GPU configuration with pciDevice and vgpuType parameters
- Include comprehensive test coverage and documentation
- Add practical examples for GPU service offerings
- Addresses issue apache#246
- Update service offering documentation with GPU examples
- Add service_offering_details parameter documentation
- Update CHANGELOG with new feature entry
- Include practical examples for GPU configuration
- Fix code formatting to comply with Go standards
- Align map fields and remove trailing whitespace
- Required for CI/CD pipeline to pass
@CodeBleu
Copy link
Collaborator

CodeBleu commented Oct 17, 2025

@jeanvetorello There was already work done for service offerings around fixed, constrained and unconstrained.

Please see the following for discussions around this.
#138
#113
#77

@poddm can you review this and give your input on this as your commit a while back took a different aproach and I know we had this discussion about this before. (see links above)

@DaanHoogland Also, what is your opinion on this as we need to pick a path and stick to it. We shouldn't have multiple resource files out there for the same thing

We need to make sure we are using the most recent framework/sdk as well.

This is what was decided back then on method to split up the resources

image image

@CodeBleu CodeBleu requested a review from DaanHoogland October 17, 2025 23:33
Comment on lines 1 to 18
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license needs to be there

!command/test-fixtures/**/.terraform/
.terraform.lock.hcl
provider.tf
examples/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
examples/
examples/

@DaanHoogland
Copy link
Contributor

@DaanHoogland Also, what is your opinion on this as we need to pick a path and stick to it. We shouldn't have multiple resource files out there for the same thing

@CodeBleu , I completely agree with the blanket statement, but am sure I am missing some context. on first sight I thought you were talking about production code vs test code, but I see no issue there. Can you explain?

@CodeBleu
Copy link
Collaborator

CodeBleu commented Oct 21, 2025

@DaanHoogland Also, what is your opinion on this as we need to pick a path and stick to it. We shouldn't have multiple resource files out there for the same thing

@CodeBleu , I completely agree with the blanket statement, but am sure I am missing some context. on first sight I thought you were talking about production code vs test code, but I see no issue there. Can you explain?

@DaanHoogland There are both resource_cloudstack_service_offering.go and service_offering_*.go files in the code for service offerings. They both take a different approach and this PR is updating what I thought was the old way?
See
#138
#113
#77
for more context.

@poddm
Copy link
Contributor

poddm commented Oct 21, 2025

@CodeBleu, I think you're right. We should deprecated this resource.

I can open a PR if thats whats decided.

@DaanHoogland
Copy link
Contributor

There are both resource_cloudstack_service_offering.go and service_offering_*.go files in the code for service offerings.

makes sense, @CodeBleu .

I can open a PR if thats whats decided.

thanks @poddm .

it makes no sense to maintain two SDKs for the same API. Will we then defer merging this? or is this a parallel effort?

@jeanvetorello
Copy link
Contributor Author

I need to remove old duplicate service offering files to pass all tests. Should I proceed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants