@@ -23,6 +23,7 @@ type VisualizationEntity struct {
2323 Name string `json:"name"`
2424 Description string `json:"description,omitempty"`
2525 Options string `json:"options"`
26+ QueryPlan string `json:"query_plan,omitempty"`
2627}
2728
2829func (v * VisualizationEntity ) toAPIObject (schema map [string ]* schema.Schema , data * schema.ResourceData ) (* api.Visualization , error ) {
@@ -37,6 +38,9 @@ func (v *VisualizationEntity) toAPIObject(schema map[string]*schema.Schema, data
3738 av .Name = v .Name
3839 av .Description = v .Description
3940 av .Options = json .RawMessage (v .Options )
41+ if v .QueryPlan != "" {
42+ av .QueryPlan = json .RawMessage (v .QueryPlan )
43+ }
4044 return & av , nil
4145}
4246
@@ -49,6 +53,11 @@ func (v *VisualizationEntity) fromAPIObject(av *api.Visualization, schema map[st
4953 v .Description = av .Description
5054 v .Options = string (av .Options )
5155
56+ // If the query plan attribute is not set; it may come back as `null` from the API.
57+ if av .QueryPlan != nil && ! bytes .Equal (av .QueryPlan , []byte ("null" )) {
58+ v .QueryPlan = string (av .QueryPlan )
59+ }
60+
5261 // Transform to ResourceData.
5362 return common .StructToData (* v , schema , data )
5463}
@@ -125,26 +134,28 @@ func jsonRemarshal(in []byte) ([]byte, error) {
125134 return out , nil
126135}
127136
137+ func suppressWhitespaceChangesInJSON (_ , old , new string , d * schema.ResourceData ) bool {
138+ oldp , err := jsonRemarshal ([]byte (old ))
139+ if err != nil {
140+ log .Printf ("[WARN] Unable to remarshal value %#v" , old )
141+ return false
142+ }
143+ newp , err := jsonRemarshal ([]byte (new ))
144+ if err != nil {
145+ log .Printf ("[WARN] Unable to remarshal value %#v" , new )
146+ return false
147+ }
148+ return bytes .Equal (oldp , newp )
149+ }
150+
128151func ResourceSqlVisualization () * schema.Resource {
129152 p := common .NewPairSeparatedID ("query_id" , "visualization_id" , "/" )
130153 s := common .StructToSchema (
131154 VisualizationEntity {},
132155 func (m map [string ]* schema.Schema ) map [string ]* schema.Schema {
133- // We care only about logical changes to the JSON payload in `options`.
134- m ["options" ].DiffSuppressFunc = func (_ , old , new string , d * schema.ResourceData ) bool {
135- oldp , err := jsonRemarshal ([]byte (old ))
136- if err != nil {
137- log .Printf ("[WARN] Unable to remarshal value %#v" , old )
138- return false
139- }
140- newp , err := jsonRemarshal ([]byte (new ))
141- if err != nil {
142- log .Printf ("[WARN] Unable to remarshal value %#v" , new )
143- return false
144- }
145- return bytes .Equal (oldp , newp )
146- }
147-
156+ // We care only about logical changes to the JSON payload in `options` and `query_plan`.
157+ m ["options" ].DiffSuppressFunc = suppressWhitespaceChangesInJSON
158+ m ["query_plan" ].DiffSuppressFunc = suppressWhitespaceChangesInJSON
148159 return m
149160 })
150161
0 commit comments