Skip to content

Commit a26fa34

Browse files
authored
Add ExpandMode to GetModuleContentOption (#208)
1 parent 4476483 commit a26fa34

File tree

7 files changed

+572
-422
lines changed

7 files changed

+572
-422
lines changed

plugin/fromproto/fromproto.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func GetModuleContentOption(opts *proto.GetModuleContent_Option) tflint.GetModul
236236
return tflint.GetModuleContentOption{
237237
ModuleCtx: ModuleCtxType(opts.ModuleCtx),
238238
IncludeNotCreated: opts.IncludeNotCreated,
239+
ExpandMode: ExpandMode(opts.ExpandMode),
239240
Hint: GetModuleContentHint(opts.Hint),
240241
}
241242
}
@@ -254,6 +255,20 @@ func ModuleCtxType(ty proto.ModuleCtxType) tflint.ModuleCtxType {
254255
}
255256
}
256257

258+
// ExpandMode converts proto.GetModuleContent_ExpandMode to tflint.ExpandMode
259+
func ExpandMode(mode proto.GetModuleContent_ExpandMode) tflint.ExpandMode {
260+
switch mode {
261+
case proto.GetModuleContent_EXPAND_MODE_UNSPECIFIED:
262+
return tflint.ExpandModeExpand
263+
case proto.GetModuleContent_EXPAND_MODE_EXPAND:
264+
return tflint.ExpandModeExpand
265+
case proto.GetModuleContent_EXPAND_MODE_NONE:
266+
return tflint.ExpandModeNone
267+
default:
268+
panic(fmt.Sprintf("invalid ExpandMode: %s", mode))
269+
}
270+
}
271+
257272
// GetModuleContentHint converts proto.GetModuleContent_Hint to tflint.GetModuleContentHint
258273
func GetModuleContentHint(hint *proto.GetModuleContent_Hint) tflint.GetModuleContentHint {
259274
if hint == nil {

plugin/plugin2host/plugin2host_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ volume_size = 10`)
601601
return &hclext.BodySchema{}, &tflint.GetModuleContentOption{
602602
ModuleCtx: tflint.RootModuleCtxType,
603603
IncludeNotCreated: true,
604+
ExpandMode: tflint.ExpandModeNone,
604605
Hint: tflint.GetModuleContentHint{ResourceType: "aws_instance"},
605606
}
606607
},
@@ -615,6 +616,11 @@ volume_size = 10`)
615616
&hcl.Diagnostic{Severity: hcl.DiagError, Summary: "unexpected includeNotCreatedResources options"},
616617
}
617618
}
619+
if opts.ExpandMode != tflint.ExpandModeNone {
620+
return &hclext.BodyContent{}, hcl.Diagnostics{
621+
&hcl.Diagnostic{Severity: hcl.DiagError, Summary: "unexpected expand mode options"},
622+
}
623+
}
618624
if opts.Hint.ResourceType != "aws_instance" {
619625
return &hclext.BodyContent{}, hcl.Diagnostics{
620626
&hcl.Diagnostic{Severity: hcl.DiagError, Summary: "unexpected hint options"},

plugin/proto/tflint.pb.go

Lines changed: 489 additions & 418 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin/proto/tflint.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ message GetModuleContent {
115115
message Hint {
116116
string resource_type = 1;
117117
}
118+
enum ExpandMode {
119+
EXPAND_MODE_UNSPECIFIED = 0;
120+
EXPAND_MODE_NONE = 1;
121+
EXPAND_MODE_EXPAND = 2;
122+
}
118123
message Option {
119124
ModuleCtxType module_ctx = 1;
120125
Hint hint = 2;
121-
bool include_not_created = 3;
126+
bool include_not_created = 3 [deprecated = true];
127+
ExpandMode expand_mode = 4;
122128
}
123129

124130
message Request {

plugin/toproto/toproto.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ func GetModuleContentOption(opts *tflint.GetModuleContentOption) *proto.GetModul
186186

187187
return &proto.GetModuleContent_Option{
188188
ModuleCtx: ModuleCtxType(opts.ModuleCtx),
189-
IncludeNotCreated: opts.IncludeNotCreated,
189+
IncludeNotCreated: opts.IncludeNotCreated || opts.ExpandMode == tflint.ExpandModeNone,
190+
ExpandMode: ExpandMode(opts.ExpandMode),
190191
Hint: GetModuleContentHint(opts.Hint),
191192
}
192193
}
@@ -203,6 +204,18 @@ func ModuleCtxType(ty tflint.ModuleCtxType) proto.ModuleCtxType {
203204
}
204205
}
205206

207+
// ExpandMode converts tflint.ExpandMode to proto.GetModuleContent_ExpandMode
208+
func ExpandMode(mode tflint.ExpandMode) proto.GetModuleContent_ExpandMode {
209+
switch mode {
210+
case tflint.ExpandModeExpand:
211+
return proto.GetModuleContent_EXPAND_MODE_EXPAND
212+
case tflint.ExpandModeNone:
213+
return proto.GetModuleContent_EXPAND_MODE_NONE
214+
default:
215+
panic(fmt.Sprintf("invalid ExpandMode: %s", mode))
216+
}
217+
}
218+
206219
// GetModuleContentHint converts tflint.GetModuleContentHint to proto.GetModuleContentHint
207220
func GetModuleContentHint(hint tflint.GetModuleContentHint) *proto.GetModuleContent_Hint {
208221
return &proto.GetModuleContent_Hint{

tflint/expandmode_string.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tflint/option.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,29 @@ const (
1414
RootModuleCtxType
1515
)
1616

17+
// ExpandMode represents whether the block retrieved by GetModuleContent is expanded by the meta-arguments.
18+
//
19+
//go:generate stringer -type=ExpandMode
20+
type ExpandMode int32
21+
22+
const (
23+
// ExpandModeExpand is the mode for expanding blocks based on the meta-arguments. The default is this behavior.
24+
ExpandModeExpand ExpandMode = iota
25+
// ExpandModeNone is the mode that does not expand blocks.
26+
ExpandModeNone
27+
)
28+
1729
// GetModuleContentOption is an option that controls the behavior when getting a module content.
1830
type GetModuleContentOption struct {
1931
// Specify the module to be acquired.
2032
ModuleCtx ModuleCtxType
21-
// Whether it includes resources that are not created, for example because count is 0 or unknown.
22-
IncludeNotCreated bool
33+
// Whether resources and modules are expanded by the count/for_each meta-arguments.
34+
ExpandMode ExpandMode
2335
// Hint is info for optimizing a query. This is an advanced option and it is not intended to be used directly from plugins.
2436
Hint GetModuleContentHint
37+
38+
// Deprecated: Use ExpandMode instead.
39+
IncludeNotCreated bool
2540
}
2641

2742
// GetModuleContentHint is info for optimizing a query. This is an advanced option and it is not intended to be used directly from plugins.

0 commit comments

Comments
 (0)