costmanagement: convert export resources to use typed models with Decode/Encode#32178
costmanagement: convert export resources to use typed models with Decode/Encode#32178
Conversation
sreallymatt
left a comment
There was a problem hiding this comment.
Thanks @katbyte - I've left some comments inline
|
|
||
| format := exports.FormatType(config.FileFormat) | ||
| recurrenceType := exports.RecurrenceType(config.RecurrenceType) | ||
|
|
There was a problem hiding this comment.
These can be inlined into the exports.Export struct instantiation using pointer.ToEnum
| props := exports.Export{ | ||
| Properties: &exports.ExportProperties{ | ||
| Schedule: &exports.ExportSchedule{ | ||
| Recurrence: &recurrenceType, |
There was a problem hiding this comment.
| Recurrence: &recurrenceType, | |
| Recurrence: pointer.ToEnum[exports.RecurrenceType](config.RecurrenceType), |
| }, | ||
| Status: &status, | ||
| }, | ||
| DeliveryInfo: *deliveryInfo, |
There was a problem hiding this comment.
expandExportDataStorageLocationFromModel returns nil without an error when the input length is 0, while the block is currently marked as Required and this should always be > 1, we may want to guard against nil pointer dereferences in case this changes to Optional in the future.
| Status: &status, | ||
| }, | ||
| DeliveryInfo: *deliveryInfo, | ||
| Format: &format, |
There was a problem hiding this comment.
| Format: &format, | |
| Format: pointer.ToEnum[exports.FormatType](config.FileFormat), |
| }, | ||
| DeliveryInfo: *deliveryInfo, | ||
| Format: &format, | ||
| Definition: *expandExportDataOptionsFromModel(config.ExportDataOptions), |
There was a problem hiding this comment.
Similar concern as above with DeliveryInfo
| var opts exports.GetOperationOptions | ||
| resp, err := client.Get(ctx, *id, opts) | ||
| if err != nil { | ||
| return fmt.Errorf("reading %s: %+v", *id, err) |
There was a problem hiding this comment.
| return fmt.Errorf("reading %s: %+v", *id, err) | |
| return fmt.Errorf("retrieving %s: %+v", *id, err) |
| format := exports.FormatType(config.FileFormat) | ||
| recurrenceType := exports.RecurrenceType(config.RecurrenceType) | ||
|
|
||
| props := exports.Export{ |
There was a problem hiding this comment.
Could we use d.HasChanges to conditionally update the returned model instead of rebuilding from scratch?
| recurrenceType := exports.RecurrenceType(config.RecurrenceType) | ||
|
|
||
| props := exports.Export{ | ||
| ETag: resp.Model.ETag, |
There was a problem hiding this comment.
Potential panic given the error on ln218 only happens when resp.Model is non-nil but eTag is nil
|
Build failure: GoLang Linting This pull request contains a build failure in the GoLang Linting check which needs to be addressed here. How to fix: Run the Go linter locally with For more information, please refer to our Contributing Guide. |
Community Note
Description
Convert the three cost management export resources (
azurerm_billing_account_cost_management_export,azurerm_resource_group_cost_management_export,azurerm_subscription_cost_management_export) from returningnilinModelObject()with rawmetadata.ResourceData.Get()/Set()calls to using proper typed model structs withmetadata.Decode()/metadata.Encode().This follows the same pattern applied to the consumption budget resources in #31929.
PR Checklist
Changes to existing Resource / Data Source
Testing
go build ./internal/services/costmanagement/...— passesgo vet ./internal/services/costmanagement/...— passesmake static-analysis— passesgo test -short) — all cost management export tests discover and register withoutValidateModelObjectpanicsNo behavioral changes were made; existing acceptance tests cover the Create/Read/Update/Delete flows and will validate correctness when run with
TF_ACC.Change Log
azurerm_billing_account_cost_management_export- refactor to use typed model with Decode/Encodeazurerm_resource_group_cost_management_export- refactor to use typed model with Decode/Encodeazurerm_subscription_cost_management_export- refactor to use typed model with Decode/EncodeThis is a (please select all that apply):
Related Issue(s)
N/A — internal tech debt cleanup
AI Assistance Disclosure
AI was used for code generation of the typed model structs, expand/flatten helpers, and inlined CRUD methods. All changes were reviewed and validated manually.
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the provider.
Changes to Security Controls
No changes to security controls.