Skip to content

costmanagement: convert view resources to use typed models with Decode/Encode#32191

Open
katbyte wants to merge 1 commit intomainfrom
kt/bad-typed-cost-views
Open

costmanagement: convert view resources to use typed models with Decode/Encode#32191
katbyte wants to merge 1 commit intomainfrom
kt/bad-typed-cost-views

Conversation

@katbyte
Copy link
Copy Markdown
Collaborator

@katbyte katbyte commented Apr 16, 2026

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

Convert azurerm_subscription_cost_management_view and azurerm_resource_group_cost_management_view from returning nil in ModelObject() with raw metadata.ResourceData.Get()/Set() calls to using proper typed model structs with metadata.Decode()/metadata.Encode().

The Update() methods preserve the existing read-modify-write pattern with HasChange guards to ensure lifecycle { ignore_changes } continues to work correctly.

This follows the same pattern applied to the consumption budget resources in #31929, the cost management export resources in #31930, and the scheduled action/anomaly alert resources in #31931.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.

Testing

  • go build ./internal/services/costmanagement/... — passes
  • go vet ./internal/services/costmanagement/... — passes
  • make static-analysis — passes
  • Test registration (go test -short) — all cost management view tests discover and register without ValidateModelObject panics

No 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_subscription_cost_management_view - refactor to use typed model with Decode/Encode
  • azurerm_resource_group_cost_management_view - refactor to use typed model with Decode/Encode

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

N/A — internal tech debt cleanup

AI Assistance Disclosure

  • AI Assisted - This contribution was made by, or with the assistance of, AI/LLMs

AI was used for code generation of the typed model structs, expand/flatten helpers, and refactored 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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant