@@ -86,11 +86,11 @@ func fillFreeTier(resourceb *hclwrite.Body) error {
8686 if err := hcl .MoveAttr (resourceb , electableSpec .Body (), nInstanceSizeSrc , nInstanceSize , errFreeCluster ); err != nil {
8787 return err
8888 }
89- configb .SetAttributeRaw (nElectableSpecs , hcl .TokensObject (electableSpec ))
89+ configb .SetAttributeRaw (nElectableSpecs , hcl .TokensObject (electableSpec . Body () ))
9090
9191 repSpecs := hclwrite .NewEmptyFile ()
92- repSpecs .Body ().SetAttributeRaw (nConfig , hcl .TokensArraySingle (config ))
93- resourceb .SetAttributeRaw (nRepSpecs , hcl .TokensArraySingle (repSpecs ))
92+ repSpecs .Body ().SetAttributeRaw (nConfig , hcl .TokensArraySingle (configb ))
93+ resourceb .SetAttributeRaw (nRepSpecs , hcl .TokensArraySingle (repSpecs . Body () ))
9494 return nil
9595}
9696
@@ -115,21 +115,21 @@ func fillReplicationSpecs(resourceb *hclwrite.Body) error {
115115 }
116116 repSpecs := hclwrite .NewEmptyFile ()
117117 repSpecs .Body ().SetAttributeRaw (nConfig , configs )
118- resourceb .SetAttributeRaw (nRepSpecs , hcl .TokensArraySingle (repSpecs ))
118+ resourceb .SetAttributeRaw (nRepSpecs , hcl .TokensArraySingle (repSpecs . Body () ))
119119 tags , errTags := getTagsLabelsOpt (nTags , resourceb )
120120 if errTags != nil {
121121 return errTags
122122 }
123123 if tags != nil {
124124 resourceb .SetAttributeRaw (nTags , tags )
125125 }
126-
126+ fillTimeoutsOpt ( resourceb )
127127 resourceb .RemoveBlock (repSpecsSrc )
128128 return nil
129129}
130130
131131func getRegionConfigs (repSpecsSrc * hclwrite.Block , root attrVals ) (hclwrite.Tokens , error ) {
132- var configs []* hclwrite.File
132+ var configs []* hclwrite.Body
133133 for {
134134 configSrc := repSpecsSrc .Body ().FirstMatchingBlock (nConfigSrc , nil )
135135 if configSrc == nil {
@@ -139,15 +139,15 @@ func getRegionConfigs(repSpecsSrc *hclwrite.Block, root attrVals) (hclwrite.Toke
139139 if err != nil {
140140 return nil , err
141141 }
142- configs = append (configs , config )
142+ configs = append (configs , config . Body () )
143143 repSpecsSrc .Body ().RemoveBlock (configSrc )
144144 }
145145 if len (configs ) == 0 {
146146 return nil , fmt .Errorf ("%s: %s not found" , errRepSpecs , nConfigSrc )
147147 }
148148 sort .Slice (configs , func (i , j int ) bool {
149- pi , _ := hcl .GetAttrInt (configs [i ].Body (). GetAttribute (nPriority ), errPriority )
150- pj , _ := hcl .GetAttrInt (configs [j ].Body (). GetAttribute (nPriority ), errPriority )
149+ pi , _ := hcl .GetAttrInt (configs [i ].GetAttribute (nPriority ), errPriority )
150+ pj , _ := hcl .GetAttrInt (configs [j ].GetAttribute (nPriority ), errPriority )
151151 return pi > pj
152152 })
153153 return hcl .TokensArray (configs ), nil
@@ -203,7 +203,7 @@ func getSpecs(countName string, configSrc *hclwrite.Block, root attrVals) (hclwr
203203 if root .opt [nDiskIOPSSrc ] != nil {
204204 fileb .SetAttributeRaw (nDiskIOPS , root .opt [nDiskIOPSSrc ])
205205 }
206- return hcl .TokensObject (file ), nil
206+ return hcl .TokensObject (fileb ), nil
207207}
208208
209209func getAutoScalingOpt (opt map [string ]hclwrite.Tokens ) hclwrite.Tokens {
@@ -216,19 +216,20 @@ func getAutoScalingOpt(opt map[string]hclwrite.Tokens) hclwrite.Tokens {
216216 {nComputeScaleDownEnabledSrc , nComputeScaleDownEnabled },
217217 }
218218 file = hclwrite .NewEmptyFile ()
219+ fileb = file .Body ()
219220 found = false
220221 )
221222 for _ , tuple := range names {
222223 src , dst := tuple [0 ], tuple [1 ]
223224 if tokens := opt [src ]; tokens != nil {
224- file . Body () .SetAttributeRaw (dst , tokens )
225+ fileb .SetAttributeRaw (dst , tokens )
225226 found = true
226227 }
227228 }
228229 if ! found {
229230 return nil
230231 }
231- return hcl .TokensObject (file )
232+ return hcl .TokensObject (fileb )
232233}
233234
234235func getTagsLabelsOpt (attrName string , resourceb * hclwrite.Body ) (hclwrite.Tokens , error ) {
@@ -258,7 +259,16 @@ func getTagsLabelsOpt(attrName string, resourceb *hclwrite.Body) (hclwrite.Token
258259 if ! found {
259260 return nil , nil
260261 }
261- return hcl .TokensObject (file ), nil
262+ return hcl .TokensObject (fileb ), nil
263+ }
264+
265+ func fillTimeoutsOpt (resourceb * hclwrite.Body ) {
266+ block := resourceb .FirstMatchingBlock (nTimeouts , nil )
267+ if block == nil {
268+ return
269+ }
270+ resourceb .RemoveBlock (block )
271+ resourceb .SetAttributeRaw (nTimeouts , hcl .TokensObject (block .Body ()))
262272}
263273
264274func checkDynamicBlock (body * hclwrite.Body ) error {
0 commit comments