in tflint-ruleset-aws-serverless/rules/aws_apigatewayv2_stage_throttling.go [50:123]
func (r *AwsApigatewayV2StageThrottlingRule) 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
}
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
}
blockBody, _, diags := blocks[0].Body.PartialContent(&hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: r.burstAttributeName,
},
{
Name: r.rateAttributeName,
},
},
})
if diags.HasErrors() {
return diags
}
// Check throttling limits
var burstLimit int
burstLimitAttribute, burstOk := blockBody.Attributes[r.burstAttributeName]
if !burstOk {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.burstAttributeName),
blockBody.MissingItemRange,
)
} else {
err := runner.EvaluateExpr(burstLimitAttribute.Expr, &burstLimit, nil)
if err != nil {
return err
}
}
var rateLimit int
rateLimitAttribute, rateOk := blockBody.Attributes[r.rateAttributeName]
if !rateOk {
runner.EmitIssue(
r,
fmt.Sprintf("\"%s\" is not present.", r.rateAttributeName),
blockBody.MissingItemRange,
)
} else {
err := runner.EvaluateExpr(rateLimitAttribute.Expr, &rateLimit, nil)
if err != nil {
return err
}
}
return nil
})
}