@@ -108,7 +108,7 @@ func convertRepSpecsWithDynamicBlock(resourceb *hclwrite.Body, diskSizeGB hclwri
108
108
if err != nil || ! dSpec .IsPresent () {
109
109
return dynamicBlock {}, err
110
110
}
111
- transformDynamicBlockReferences (dSpec .content .Body (), nRepSpecs , nSpec )
111
+ transformReferences (dSpec .content .Body (), nRepSpecs , nSpec )
112
112
dConfig , err := convertConfigsWithDynamicBlock (dSpec .content .Body (), diskSizeGB )
113
113
if err != nil {
114
114
return dynamicBlock {}, err
@@ -123,32 +123,33 @@ func convertConfigsWithDynamicBlock(specbSrc *hclwrite.Body, diskSizeGB hclwrite
123
123
if err != nil {
124
124
return dynamicBlock {}, err
125
125
}
126
+ configBody := d .content .Body ()
126
127
repSpec := hclwrite .NewEmptyFile ()
127
128
repSpecb := repSpec .Body ()
128
129
if zoneNameAttr := specbSrc .GetAttribute (nZoneName ); zoneNameAttr != nil {
129
- expr := replaceDynamicBlockReferences (hcl .GetAttrExpr (zoneNameAttr ), nRepSpecs , nSpec )
130
+ expr := transformReference (hcl .GetAttrExpr (zoneNameAttr ), nRepSpecs , nSpec )
130
131
repSpecb .SetAttributeRaw (nZoneName , hcl .TokensFromExpr (expr ))
131
132
}
132
133
configForEach := fmt .Sprintf ("%s.%s" , nSpec , nConfig )
133
134
configBlockName := getResourceName (d .block )
134
- transformDynamicBlockReferences ( d . content . Body () , configBlockName , nRegion )
135
- for _ , block := range d . content . Body () .Blocks () {
136
- transformDynamicBlockReferences (block .Body (), configBlockName , nRegion )
135
+ transformReferences ( configBody , configBlockName , nRegion )
136
+ for _ , block := range configBody .Blocks () {
137
+ transformReferences (block .Body (), configBlockName , nRegion )
137
138
}
138
- for name , attr := range d . content . Body () .Attributes () {
139
- expr := replaceDynamicBlockReferences (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
140
- d . content . Body () .SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
139
+ for name , attr := range configBody .Attributes () {
140
+ expr := transformReference (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
141
+ configBody .SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
141
142
}
142
- for _ , block := range d . content . Body () .Blocks () {
143
+ for _ , block := range configBody .Blocks () {
143
144
for name , attr := range block .Body ().Attributes () {
144
- expr := replaceDynamicBlockReferences (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
145
+ expr := transformReference (hcl .GetAttrExpr (attr ), nRepSpecs , nSpec )
145
146
block .Body ().SetAttributeRaw (name , hcl .TokensFromExpr (expr ))
146
147
}
147
148
}
148
149
regionConfigFile := hclwrite .NewEmptyFile ()
149
150
regionConfigBody := regionConfigFile .Body ()
150
- copyAttributesSorted (regionConfigBody , d . content . Body () .Attributes ())
151
- for _ , block := range d . content . Body () .Blocks () {
151
+ copyAttributesSorted (regionConfigBody , configBody .Attributes ())
152
+ for _ , block := range configBody .Blocks () {
152
153
blockType := block .Type ()
153
154
blockFile := hclwrite .NewEmptyFile ()
154
155
blockBody := blockFile .Body ()
@@ -165,7 +166,7 @@ func convertConfigsWithDynamicBlock(specbSrc *hclwrite.Body, diskSizeGB hclwrite
165
166
repSpecb .SetAttributeRaw (nConfig , regionConfig )
166
167
numShardsAttr := specbSrc .GetAttribute (nNumShards )
167
168
if numShardsAttr != nil {
168
- numShardsExpr := replaceDynamicBlockReferences (hcl .GetAttrExpr (numShardsAttr ), nRepSpecs , nSpec )
169
+ numShardsExpr := transformReference (hcl .GetAttrExpr (numShardsAttr ), nRepSpecs , nSpec )
169
170
tokens := hcl .TokensFromExpr (buildForExpr ("i" , fmt .Sprintf ("range(%s)" , numShardsExpr ), false ))
170
171
tokens = append (tokens , hcl .TokensObject (repSpecb )... )
171
172
return dynamicBlock {tokens : hcl .EncloseBracketsNewLines (tokens )}, nil
@@ -181,7 +182,7 @@ func convertConfig(repSpecs *hclwrite.Body, diskSizeGB hclwrite.Tokens) error {
181
182
if dConfig .IsPresent () {
182
183
blockName := getResourceName (dConfig .block )
183
184
transform := func (expr string ) string {
184
- return replaceDynamicBlockReferences (expr , blockName , nRegion )
185
+ return transformReference (expr , blockName , nRegion )
185
186
}
186
187
copyAttributesSorted (dConfig .content .Body (), dConfig .content .Body ().Attributes (), transform )
187
188
for _ , block := range dConfig .content .Body ().Blocks () {
0 commit comments