in tflint-ruleset-aws-serverless/rules/aws_lambda_function_tracing.go [48:108]
func (r *AwsLambdaFunctionTracingRule) Check(runner tflint.Runner) error {
return runner.WalkResources(r.resourceType, func(resource *configs.Resource) error {
body, _, diags := resource.Config.PartialContent(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
Type: r.blockName,
},
},
})
if diags.HasErrors() {
return diags
}
// Check if the block exists
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
}
// Retrieve the block body
blockBody, _, diags := blocks[0].Body.PartialContent(&hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: r.attributeName,
Required: true,
},
},
})
if diags.HasErrors() {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s.%s\" is not present.", r.blockName, r.attributeName),
blockBody.MissingItemRange,
)
return nil
}
attribute := blockBody.Attributes[r.attributeName]
var xrayTracingEnabled string
err := runner.EvaluateExpr(attribute.Expr, &xrayTracingEnabled, nil)
return runner.EnsureNoError(err, func() error {
if xrayTracingEnabled != "Active" {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf("\"%s.%s\" should be set to Active.", r.blockName, r.attributeName),
attribute.Expr,
)
}
return nil
})
})
}