in tflint-ruleset-aws-serverless/rules/aws_sfn_state_machine_tracing.go [49:114]
func (r *AwsSfnStateMachineTracingRule) Check(runner tflint.Runner) error {
return runner.WalkResources(r.resourceType, func(resource *configs.Resource) error {
// Block
body, _, diags := resource.Config.PartialContent(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
Type: r.blockName,
},
},
})
if diags.HasErrors() {
return diags
}
blocks := body.Blocks.OfType(r.blockName)
if len(blocks) != 1 {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.blockName),
body.MissingItemRange,
)
return nil
}
// Attribute
body, _, diags = blocks[0].Body.PartialContent(&hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: r.attributeName,
},
},
})
if diags.HasErrors() {
return diags
}
var attrValue string
attribute, ok := body.Attributes[r.attributeName]
if !ok {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.attributeName),
body.MissingItemRange,
)
} else {
err := runner.EvaluateExpr(attribute.Expr, &attrValue, nil)
if err != nil {
return err
}
if attrValue != "true" {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf("\"%s\" should be set to true.", r.attributeName),
attribute.Expr,
)
}
}
return nil
})
}