Skip to content

Commit

Permalink
resource-pools: Fix handling when default is unset [sc-116346] (#90)
Browse files Browse the repository at this point in the history
When `default_pool` is unset, the conversion from tf schema to model
succeeds, and the config is applied, but when converting the server
model to intshema, it fails as a `nil` default pool is not handled.
  • Loading branch information
prashantv authored Nov 14, 2024
1 parent 58039c5 commit 92092a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

Fixed:
* Fix `chronosphere_resource_pools_config` error when default pool is not set.

## v1.6.0

Added:
Expand Down
25 changes: 19 additions & 6 deletions chronosphere/resource_resource_pools_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ func (resourcePoolsConfigConverter) fromModel(
if err != nil {
return nil, err
}
allocation, err := expandAllocation(m.DefaultPool.Allocation)

defaultPool, err := expandDefaultPool(m.DefaultPool)
if err != nil {
return nil, err
}

return &intschema.ResourcePoolsConfig{
DefaultPool: &intschema.ResourcePoolsConfigDefaultPool{
Allocation: allocation,
Priorities: expandPriorities(m.DefaultPool.Priorities),
},
Pool: pools,
DefaultPool: defaultPool,
Pool: pools,
}, nil
}

Expand Down Expand Up @@ -222,6 +221,20 @@ func expandPools(pools []*apimodels.ResourcePoolsPool) ([]intschema.ResourcePool
})
}

func expandDefaultPool(d *models.ResourcePoolsDefaultPool) (*intschema.ResourcePoolsConfigDefaultPool, error) {
if d == nil {
return nil, nil
}
allocation, err := expandAllocation(d.Allocation)
if err != nil {
return nil, err
}
return &intschema.ResourcePoolsConfigDefaultPool{
Allocation: allocation,
Priorities: expandPriorities(d.Priorities),
}, nil
}

func buildDefaultPool(defaultPool *intschema.ResourcePoolsConfigDefaultPool) (*apimodels.ResourcePoolsDefaultPool, error) {
if defaultPool == nil {
return nil, nil
Expand Down

0 comments on commit 92092a2

Please sign in to comment.