Skip to content

Commit

Permalink
fix(json): plan's variables parsing error (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Aug 30, 2021
1 parent d9e29ff commit 91b3dab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 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 All @@ -224,7 +224,7 @@ type PlanStateResource struct {
PlanStateResourceAttributes planStateResourceAttributeList `json:"values,omitempty"`

// The addresses of the resources that this resource depends on.
DependsOn string `json:"depends_on,omitempty"`
DependsOn rawJSON `json:"depends_on,omitempty"`

// If true, the resource has been marked as tainted and will be
// re-created on the next update.
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 91b3dab

Please sign in to comment.