|
4 | 4 | "fmt" |
5 | 5 |
|
6 | 6 | hcl "github.com/hashicorp/hcl/v2" |
| 7 | + "github.com/terraform-linters/tflint-plugin-sdk/terraform/configs" |
7 | 8 | "github.com/terraform-linters/tflint-plugin-sdk/tflint" |
8 | 9 | "github.com/terraform-linters/tflint-ruleset-google/project" |
9 | 10 | ) |
@@ -45,32 +46,44 @@ func (r *GoogleProjectIamAuditConfigInvalidMemberRule) Link() string { |
45 | 46 |
|
46 | 47 | // Check checks whether member format is invalid |
47 | 48 | func (r *GoogleProjectIamAuditConfigInvalidMemberRule) Check(runner tflint.Runner) error { |
48 | | - return runner.WalkResourceBlocks(r.resourceType, r.blockName, func(block *hcl.Block) error { |
49 | | - content, _, diags := block.Body.PartialContent(&hcl.BodySchema{ |
50 | | - Attributes: []hcl.AttributeSchema{ |
51 | | - {Name: r.attributeName}, |
52 | | - }, |
| 49 | + return runner.WalkResources(r.resourceType, func(resource *configs.Resource) error { |
| 50 | + content, _, diags := resource.Config.PartialContent(&hcl.BodySchema{ |
| 51 | + Blocks: []hcl.BlockHeaderSchema{{Type: r.blockName}}, |
53 | 52 | }) |
54 | 53 | if diags.HasErrors() { |
55 | 54 | return diags |
56 | 55 | } |
57 | 56 |
|
58 | | - if attribute, exists := content.Attributes[r.attributeName]; exists { |
59 | | - var members []string |
60 | | - err := runner.EvaluateExpr(attribute.Expr, &members, nil) |
| 57 | + for _, block := range content.Blocks { |
| 58 | + content, _, diags := block.Body.PartialContent(&hcl.BodySchema{ |
| 59 | + Attributes: []hcl.AttributeSchema{ |
| 60 | + {Name: r.attributeName}, |
| 61 | + }, |
| 62 | + }) |
| 63 | + if diags.HasErrors() { |
| 64 | + return diags |
| 65 | + } |
| 66 | + |
| 67 | + if attribute, exists := content.Attributes[r.attributeName]; exists { |
| 68 | + var members []string |
| 69 | + err := runner.EvaluateExpr(attribute.Expr, &members, nil) |
61 | 70 |
|
62 | | - return runner.EnsureNoError(err, func() error { |
63 | | - for _, member := range members { |
64 | | - if !isValidIAMMemberFormat(member) { |
65 | | - return runner.EmitIssueOnExpr( |
66 | | - r, |
67 | | - fmt.Sprintf("%s is an invalid member format", member), |
68 | | - attribute.Expr, |
69 | | - ) |
| 71 | + err = runner.EnsureNoError(err, func() error { |
| 72 | + for _, member := range members { |
| 73 | + if !isValidIAMMemberFormat(member) { |
| 74 | + return runner.EmitIssueOnExpr( |
| 75 | + r, |
| 76 | + fmt.Sprintf("%s is an invalid member format", member), |
| 77 | + attribute.Expr, |
| 78 | + ) |
| 79 | + } |
70 | 80 | } |
| 81 | + return nil |
| 82 | + }) |
| 83 | + if err != nil { |
| 84 | + return err |
71 | 85 | } |
72 | | - return nil |
73 | | - }) |
| 86 | + } |
74 | 87 | } |
75 | 88 |
|
76 | 89 | return nil |
|
0 commit comments