Skip to content

Commit f64f99e

Browse files
committed
refactor: adjust terraform v1.5.7
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent 07eb4cb commit f64f99e

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

staging/terraform/configs/module_merge_body.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616
// replace _all_ of the blocks of the same type in "base" in the new
1717
// body.
1818
func MergeBodies(base, override hcl.Body) hcl.Body {
19-
return mergeBody{
19+
return MergeBody{
2020
Base: base,
2121
Override: override,
2222
}
2323
}
2424

25-
// mergeBody is a hcl.Body implementation that wraps a pair of other bodies
25+
// MergeBody is a hcl.Body implementation that wraps a pair of other bodies
2626
// and allows attributes and blocks within the override to take precedence
2727
// over those defined in the base body.
2828
//
@@ -34,14 +34,14 @@ func MergeBodies(base, override hcl.Body) hcl.Body {
3434
// This cannot possibly "do the right thing" in all cases, because we don't
3535
// have enough information about user intent. However, this behavior is intended
3636
// to be reasonable for simple overriding use-cases.
37-
type mergeBody struct {
37+
type MergeBody struct {
3838
Base hcl.Body
3939
Override hcl.Body
4040
}
4141

42-
var _ hcl.Body = mergeBody{}
42+
var _ hcl.Body = MergeBody{}
4343

44-
func (b mergeBody) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostics) {
44+
func (b MergeBody) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagnostics) {
4545
var diags hcl.Diagnostics
4646
baseSchema := schemaWithDynamic(schema)
4747
overrideSchema := schemaWithDynamic(schemaForOverrides(schema))
@@ -56,7 +56,7 @@ func (b mergeBody) Content(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Diagno
5656
return content, diags
5757
}
5858

59-
func (b mergeBody) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Body, hcl.Diagnostics) {
59+
func (b MergeBody) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl.Body, hcl.Diagnostics) {
6060
var diags hcl.Diagnostics
6161
baseSchema := schemaWithDynamic(schema)
6262
overrideSchema := schemaWithDynamic(schemaForOverrides(schema))
@@ -73,7 +73,7 @@ func (b mergeBody) PartialContent(schema *hcl.BodySchema) (*hcl.BodyContent, hcl
7373
return content, remain, diags
7474
}
7575

76-
func (b mergeBody) prepareContent(base *hcl.BodyContent, override *hcl.BodyContent) *hcl.BodyContent {
76+
func (b MergeBody) prepareContent(base *hcl.BodyContent, override *hcl.BodyContent) *hcl.BodyContent {
7777
content := &hcl.BodyContent{
7878
Attributes: make(hcl.Attributes),
7979
}
@@ -120,7 +120,7 @@ func (b mergeBody) prepareContent(base *hcl.BodyContent, override *hcl.BodyConte
120120
return content
121121
}
122122

123-
func (b mergeBody) JustAttributes() (hcl.Attributes, hcl.Diagnostics) {
123+
func (b MergeBody) JustAttributes() (hcl.Attributes, hcl.Diagnostics) {
124124
var diags hcl.Diagnostics
125125
ret := make(hcl.Attributes)
126126

@@ -139,6 +139,6 @@ func (b mergeBody) JustAttributes() (hcl.Attributes, hcl.Diagnostics) {
139139
return ret, diags
140140
}
141141

142-
func (b mergeBody) MissingItemRange() hcl.Range {
142+
func (b MergeBody) MissingItemRange() hcl.Range {
143143
return b.Base.MissingItemRange()
144144
}

staging/terraform/configs/named_values.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ package configs
66
import (
77
"fmt"
88

9+
"github.com/zclconf/go-cty/cty"
10+
"github.com/zclconf/go-cty/cty/convert"
11+
912
"github.com/hashicorp/hcl/v2"
1013
"github.com/hashicorp/hcl/v2/ext/typeexpr"
1114
"github.com/hashicorp/hcl/v2/gohcl"
1215
"github.com/hashicorp/hcl/v2/hclsyntax"
13-
"github.com/zclconf/go-cty/cty"
14-
"github.com/zclconf/go-cty/cty/convert"
1516

1617
"github.com/hashicorp/terraform/addrs"
1718
)
@@ -46,12 +47,14 @@ type Variable struct {
4647
NullableSet bool
4748

4849
DeclRange hcl.Range
50+
Tokens hcl.Tokens
4951
}
5052

5153
func decodeVariableBlock(block *hcl.Block, override bool) (*Variable, hcl.Diagnostics) {
5254
v := &Variable{
5355
Name: block.Labels[0],
5456
DeclRange: block.DefRange,
57+
Tokens: block.Tokens,
5558
}
5659

5760
// Unless we're building an override, we'll set some defaults
@@ -404,6 +407,7 @@ type Output struct {
404407
SensitiveSet bool
405408

406409
DeclRange hcl.Range
410+
Tokens hcl.Tokens
407411
}
408412

409413
func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostics) {
@@ -412,6 +416,7 @@ func decodeOutputBlock(block *hcl.Block, override bool) (*Output, hcl.Diagnostic
412416
o := &Output{
413417
Name: block.Labels[0],
414418
DeclRange: block.DefRange,
419+
Tokens: block.Tokens,
415420
}
416421

417422
schema := outputBlockSchema
@@ -488,6 +493,7 @@ type Local struct {
488493
Expr hcl.Expression
489494

490495
DeclRange hcl.Range
496+
Tokens hcl.Tokens
491497
}
492498

493499
func decodeLocalsBlock(block *hcl.Block) ([]*Local, hcl.Diagnostics) {
@@ -511,6 +517,7 @@ func decodeLocalsBlock(block *hcl.Block) ([]*Local, hcl.Diagnostics) {
511517
Name: name,
512518
Expr: attr.Expr,
513519
DeclRange: attr.Range,
520+
Tokens: attr.Tokens,
514521
})
515522
}
516523
return locals, diags

staging/terraform/doc.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
// Package terraform borrows from the https://github.com/hashicorp/terraform/tree/v1.5.7.
66
//
77
// Since the default Terraform hasn't exposed its internal packages,
8-
// this package shifts up the internal packages to be public,
9-
// and exposes the configs.MergeBody type,
10-
// which is used to merge the HCL bodies in the Terraform module.
8+
// this package shifts up the internal packages to be public.
9+
//
10+
// Secondary, this package exposes the configs.MergeBody type,
11+
// which is used to merge the HCL bodies in the Terraform module,
12+
// and exposes the AST tokens of some Terraform blocks.
1113
//
1214
// This package is not exactly the same with the original implementation but works well for us.
1315
package terraform

0 commit comments

Comments
 (0)