-
Notifications
You must be signed in to change notification settings - Fork 47
Add cloudstack_limits
data source and resource
#197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Implemented data source for retrieving CloudStack resource limits. - Added resource management for setting and updating resource limits for accounts, domains, and projects. - Updated documentation for cloudstack_limits with usage examples and argument references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds CloudStack resource limits management by introducing a new cloudstack_limits
resource and data source. These allow Terraform to manage CloudStack resource limits for different entities (accounts, domains, projects) using the CloudStack updateResourceLimit
API.
Key changes:
- Implements CRUD operations for CloudStack resource limits with support for all limit types
- Adds data source to query existing resource limits with filtering capabilities
- Provides comprehensive test coverage for various limit types and entity scopes
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
cloudstack/resource_cloudstack_limits.go |
Core resource implementation with CRUD operations and resource type mapping |
cloudstack/data_source_cloudstack_limits.go |
Data source for querying resource limits with filtering options |
cloudstack/resource_cloudstack_limits_test.go |
Comprehensive test suite covering different limit types and scenarios |
cloudstack/provider.go |
Provider registration for the new resource and data source |
website/docs/r/limits.html.markdown |
Resource documentation with examples and argument reference |
website/docs/d/limits.html.markdown |
Data source documentation with usage examples |
"instance": 0, | ||
"ip": 1, | ||
"volume": 2, | ||
"snapshot": 3, | ||
"template": 4, | ||
"project": 5, | ||
"network": 6, | ||
"vpc": 7, | ||
"cpu": 8, | ||
"memory": 9, | ||
"primarystorage": 10, | ||
"secondarystorage": 11, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resourceTypeMap is missing some resource types that are documented in the data source (publicip, eip, autoscalevmgroup). This inconsistency could cause confusion and limit functionality.
"instance": 0, | |
"ip": 1, | |
"volume": 2, | |
"snapshot": 3, | |
"template": 4, | |
"project": 5, | |
"network": 6, | |
"vpc": 7, | |
"cpu": 8, | |
"memory": 9, | |
"primarystorage": 10, | |
"secondarystorage": 11, | |
"instance": 0, | |
"ip": 1, | |
"volume": 2, | |
"snapshot": 3, | |
"template": 4, | |
"project": 5, | |
"network": 6, | |
"vpc": 7, | |
"cpu": 8, | |
"memory": 9, | |
"primarystorage": 10, | |
"secondarystorage": 11, | |
"publicip": 12, | |
"eip": 13, | |
"autoscalevmgroup": 14, |
Copilot uses AI. Check for mistakes.
ResourceName: "cloudstack_limits.foo", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"domainid", "type", "type", "max"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "type" field is duplicated in the ImportStateVerifyIgnore slice. This should only appear once.
ImportStateVerifyIgnore: []string{"domainid", "type", "type", "max"}, | |
ImportStateVerifyIgnore: []string{"domainid", "type", "max"}, |
Copilot uses AI. Check for mistakes.
if max != 0 { | ||
p.SetMax(int64(max)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition prevents setting a limit to 0, which might be a valid limit value. Consider using d.HasChange("max") or checking if the value was explicitly set instead.
if max != 0 { | |
p.SetMax(int64(max)) | |
if v, ok := d.GetOk("max"); ok { | |
p.SetMax(int64(v.(int))) |
Copilot uses AI. Check for mistakes.
if max != 0 { | ||
p.SetMax(int64(max)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition prevents setting a limit to 0, which might be a valid limit value. Consider using d.HasChange("max") or checking if the value was explicitly set instead.
if max != 0 { | |
p.SetMax(int64(max)) | |
if maxVal, ok := d.GetOk("max"); ok { | |
p.SetMax(int64(maxVal.(int))) |
Copilot uses AI. Check for mistakes.
|
||
const testAccCloudStackLimits_domain_limit = ` | ||
resource "cloudstack_limits" "domain_limit" { | ||
type = "volume" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation with excessive whitespace. Should align with the other fields using consistent spacing.
type = "volume" | |
type = "volume" |
Copilot uses AI. Check for mistakes.
Adding limits as a terraform managed resource option -> https://cloudstack.apache.org/api/apidocs-4.20/apis/updateResourceLimit.html
Contributes to #82
Using this code for example: