Skip to content

Commit

Permalink
fix(json): plan's variables parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Aug 30, 2021
1 parent 35d73c0 commit eddde3d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions types/db.go
Expand Up @@ -109,7 +109,7 @@ type PlanModel struct {
PlanStateValueID sql.NullInt64 `gorm:"index" json:"-"`

// The variables set in the root module when creating the plan.
Variables []PlanModelVariable `json:"variables,omitempty"`
Variables planVariableList `json:"variables,omitempty"`

// The change operations for resources and data sources within this
// plan.
Expand Down Expand Up @@ -204,7 +204,7 @@ type PlanStateResource struct {
// empty.
//
// This value can be either an integer (int) or a string.
Index string `json:"index,omitempty"`
Index rawJSON `json:"index,omitempty"`

// The name of the provider this resource belongs to. This allows
// the provider to be interpreted unambiguously in the unusual
Expand Down Expand Up @@ -270,7 +270,7 @@ type PlanResourceChange struct {
// empty.
//
// This value can be either an integer (int) or a string.
Index string `json:"index,omitempty"`
Index rawJSON `json:"index,omitempty"`

// The name of the provider this resource belongs to. This allows
// the provider to be interpreted unambiguously in the unusual
Expand Down
20 changes: 20 additions & 0 deletions types/json.go
Expand Up @@ -11,6 +11,7 @@ import (
*********************************************/

type planOutputList []PlanOutput
type planVariableList []PlanModelVariable
type planStateOutputList []PlanStateOutput
type planStateResourceAttributeList []PlanStateResourceAttribute
type rawJSON string
Expand All @@ -35,6 +36,25 @@ func (p *planOutputList) UnmarshalJSON(b []byte) error {
return nil
}

func (p *planVariableList) UnmarshalJSON(b []byte) error {
var tmp map[string]interface{}
err := json.Unmarshal(b, &tmp)
if err != nil {
return err
}

var list planVariableList
for key, value := range tmp {
list = append(list, PlanModelVariable{
Key: key,
Value: fmt.Sprintf("%v", value),
})
}

*p = list
return nil
}

func (p *planStateOutputList) UnmarshalJSON(b []byte) error {
tmp := map[string]PlanStateOutput{}
err := json.Unmarshal(b, &tmp)
Expand Down

0 comments on commit eddde3d

Please sign in to comment.