Skip to content

Commit

Permalink
Revert "Define capacity fields to string expressions"
Browse files Browse the repository at this point in the history
This reverts commit 8c3b4b9.
  • Loading branch information
voiski authored and jgramoll committed Nov 30, 2020
1 parent ba08265 commit 551569a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 150 deletions.
9 changes: 3 additions & 6 deletions provider/capacity.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package provider

type capacity struct {
Desired int `mapstructure:"desired"`
DesiredExpression string `mapstructure:"desired_expression"`
Max int `mapstructure:"max"`
MaxExpression string `mapstructure:"max_expression"`
Min int `mapstructure:"min"`
MinExpression string `mapstructure:"min_expression"`
Desired string `mapstructure:"desired"`
Max string `mapstructure:"max"`
Min string `mapstructure:"min"`
}
12 changes: 0 additions & 12 deletions provider/capacity_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,14 @@ func capacityResource() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"desired": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"desired_expression": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"max": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"max_expression": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"min": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"min_expression": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
Expand Down
36 changes: 2 additions & 34 deletions provider/deploy_stage_cluster_capacity.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,21 @@
package provider

import (
"strconv"

"github.com/jgramoll/terraform-provider-spinnaker/client"
)

func fromClientCapacity(clientCapacity *client.Capacity) *[]*capacity {
if clientCapacity == nil {
return nil
}
newCapacity := capacity{}
if n, err := strconv.Atoi(clientCapacity.Max); err == nil {
newCapacity.Max = n
} else {
newCapacity.MaxExpression = clientCapacity.Max
}
if n, err := strconv.Atoi(clientCapacity.Min); err == nil {
newCapacity.Min = n
} else {
newCapacity.MinExpression = clientCapacity.Min
}
if n, err := strconv.Atoi(clientCapacity.Desired); err == nil {
newCapacity.Desired = n
} else {
newCapacity.DesiredExpression = clientCapacity.Desired
}
newCapacity := capacity(*clientCapacity)
return &[]*capacity{&newCapacity}
}

func toClientCapacity(c *[]*capacity) *client.Capacity {
if c != nil {
for _, c := range *c {
newCapacity := client.Capacity{}
if c.MaxExpression != "" {
newCapacity.Max = c.MaxExpression
} else {
newCapacity.Max = strconv.Itoa(c.Max)
}
if c.MinExpression != "" {
newCapacity.Min = c.MinExpression
} else {
newCapacity.Min = strconv.Itoa(c.Min)
}
if c.DesiredExpression != "" {
newCapacity.Desired = c.DesiredExpression
} else {
newCapacity.Desired = strconv.Itoa(c.Desired)
}
newCapacity := client.Capacity(*c)
return &newCapacity
}
}
Expand Down
98 changes: 0 additions & 98 deletions provider/deploy_stage_cluster_capacity_test.go

This file was deleted.

0 comments on commit 551569a

Please sign in to comment.