azurerm_mssql_managed_instance - support storage_iops#32250
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
/test |
|
|
Co-authored-by: Copilot <copilot@github.com>
|
Sry I'm keeping push my testing code since my testing sub has limited quota. |
| "storage_iops": { | ||
| Type: schema.TypeInt, | ||
| Optional: true, | ||
| // NOTE: O+C - Azure returns a calculated IOPS value for GPv2 instances when `storage_iops` is omitted. |
There was a problem hiding this comment.
I have to agree with this O+C despite our guidance in best-practices.md -> Setting Properties to Optional + Computed. I tested this iops setting in portal and the rule is quite complex, it's coupled to vcores and storage in gb.
Ideally there is a validation API we can call, or at least the error message is descriptive if user supplies invalid value?
See below my portal experiment:
mssql_managed_instance_iops.mp4
There was a problem hiding this comment.
I don't think there is a validation API, and the current sdk does not support that form.. possibly I can confirm with the svc team what's the rule, e.g.: 6400*vcore? but I'm a bit worried it may change with time
There was a problem hiding this comment.
After further tinkering on the update logic, we've decided to not do O+C in here because it over-complicates the meaning of empty / nil value in relation to SKU and other coupled field.
Instead we agree on making this an optional field with default value of 400 or whatever minimum is in portal, then do our best effort validating in CustomizeDiff, and let backend API return with error on other invalid inputs outside coverage.
There was a problem hiding this comment.
The final O+C logic after discussion:
When GPv2_enabled == true
- changed - read from config
- unchanged - read from exisiting
when GPv2_enabled == false
- never carried in payload
When changing from enabled from true to false
- set it to nil
when changing from false to true
- changed(specified in config): read from state
- unchanged (not specified in config): leave it as nil and let the service set default value
There was a problem hiding this comment.
👍 after further discussion, we have to go back to O+C design because storage_iops is only valid when general_purpose_v2_enabled is on. Cannot use optional + default.
|
|
||
| // when the MI is not GPv2, the storageIOps is not returned and will be 0 in state. That's not a valid value for the service. | ||
| if metadata.ResourceData.HasChange("storage_iops") && state.StorageIOps != 0 { | ||
| props.StorageIOps = pointer.To(state.StorageIOps) |
There was a problem hiding this comment.
This logic is wrong. If there is no changes, and API returns positive props.StorageIOps value, it will get nil-ed by line 753 above.
There was a problem hiding this comment.
I don't get the point. make it nil is on-purpose.
In this scenario: when change a GPv2 MI to non GPv2, the service might return a >0 value, but it's not a valid value in the update payload
There was a problem hiding this comment.
Discussed in DM, this scenario is a bug:
- resource has storage_iops = 400, user updated other field (eg: tag)
- Update method set props.StorageIOps = nil in line 753, but HasChange("storage_iops") evaluates to false
- The PUT request for update has props.StorageIOps set to nil instead of 400
There was a problem hiding this comment.
as discussed offline, the update loghic of storage_iops is as below, and it's only controled by general_purpose_v2_enabled not sku_name
When GPv2_enabled == true
- changed - read from config
- unchanged - read from exisiting
when GPv2_enabled == false
- never carried in payload
When changing from enabled from true to false
- set it to nil
when changing from false to true
- changed(specified in config): read from state
- unchanged (not specified in config): leave it as nil and let the service set default value

Community Note
Description
add storageIOps property for
azurerm_mssql_managed_instance.swagger: https://github.com/Azure/azure-rest-api-specs/blob/157952a94783054c539123d508f7e122ee784017/specification/sql/resource-manager/Microsoft.Sql/SQL/preview/2023-08-01-preview/ManagedInstances.json#L1107
limitation document: https://learn.microsoft.com/en-us/azure/azure-sql/managed-instance/resource-limits?view=azuresql#iops-and-throughput-in-the-next-gen-general-purpose-service-tier
per communication with svc team current min value is 300, max value is 8000
The
storage_iopsproperty is an O+C property, the service side behavior:so the behavior of terraform side, mainly for the update logic:
PR Checklist
For example: “
resource_name_here- description of change e.g. adding propertynew_property_name_here”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_mssql_managed_instance- supportstorage_iops[azurerm_mssql_managed_instance- supportstorage_iops#32250]This is a (please select all that apply):
Related Issue(s)
Fixes #0000
AI Assistance Disclosure
helped on test case composing and code review
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the provider.
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
Note
If this PR changes meaningfully during the course of review please update the title and description as required.