in tflint-ruleset-aws-serverless/rules/aws_lambda_event_source_mapping_failure_destination.go [53:137]
func (r *AwsLambdaEventSourceMappingFailureDestinationRule) Check(runner tflint.Runner) error {
return runner.WalkResources(r.resourceType, func(resource *configs.Resource) error {
// Block 1 - destination_config
body, _, diags := resource.Config.PartialContent(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
Type: r.block1Name,
},
},
})
if diags.HasErrors() {
return diags
}
blocks := body.Blocks.OfType(r.block1Name)
if len(blocks) != 1 {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.block1Name),
body.MissingItemRange,
)
return nil
}
// Block 2 - on_failure
body, _, diags = blocks[0].Body.PartialContent(&hcl.BodySchema{
Blocks: []hcl.BlockHeaderSchema{
{
Type: r.block2Name,
},
},
})
if diags.HasErrors() {
return diags
}
blocks = body.Blocks.OfType(r.block2Name)
if len(blocks) != 1 {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.block2Name),
body.MissingItemRange,
)
return nil
}
// Attribute - destination_arn
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
}
}
return nil
})
}