Skip to content

mapping aws_api_gateway_authorizer, aws_api_gateway_documentation_part, aws_api_gateway_domain_name #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ These rules enforce best practices and naming conventions:
|aws_alb_target_group_invalid_target_type|✔|
|aws_ami_invalid_architecture|✔|
|aws_api_gateway_authorizer_invalid_type|✔|
|aws_api_gateway_domain_name_invalid_security_policy|✔|
|aws_api_gateway_gateway_response_invalid_response_type|✔|
|aws_api_gateway_gateway_response_invalid_status_code|✔|
|aws_api_gateway_integration_invalid_connection_type|✔|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file generated by `generator/`. DO NOT EDIT

package models

import (
"fmt"
"log"

hcl "github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
)

// AwsAPIGatewayDomainNameInvalidSecurityPolicyRule checks the pattern is valid
type AwsAPIGatewayDomainNameInvalidSecurityPolicyRule struct {
resourceType string
attributeName string
enum []string
}

// NewAwsAPIGatewayDomainNameInvalidSecurityPolicyRule returns new rule with default attributes
func NewAwsAPIGatewayDomainNameInvalidSecurityPolicyRule() *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule {
return &AwsAPIGatewayDomainNameInvalidSecurityPolicyRule{
resourceType: "aws_api_gateway_domain_name",
attributeName: "security_policy",
enum: []string{
"TLS_1_0",
"TLS_1_2",
},
}
}

// Name returns the rule name
func (r *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule) Name() string {
return "aws_api_gateway_domain_name_invalid_security_policy"
}

// Enabled returns whether the rule is enabled by default
func (r *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule) Enabled() bool {
return true
}

// Severity returns the rule severity
func (r *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule) Severity() string {
return tflint.ERROR
}

// Link returns the rule reference link
func (r *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule) Link() string {
return ""
}

// Check checks the pattern is valid
func (r *AwsAPIGatewayDomainNameInvalidSecurityPolicyRule) Check(runner tflint.Runner) error {
log.Printf("[TRACE] Check `%s` rule", r.Name())

return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
var val string
err := runner.EvaluateExpr(attribute.Expr, &val, nil)

return runner.EnsureNoError(err, func() error {
found := false
for _, item := range r.enum {
if item == val {
found = true
}
}
if !found {
runner.EmitIssueOnExpr(
r,
fmt.Sprintf(`"%s" is an invalid value as security_policy`, truncateLongMessage(val)),
attribute.Expr,
)
}
return nil
})
})
}
22 changes: 14 additions & 8 deletions rules/models/mappings/apigateway.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import = "aws-sdk-go/models/apis/apigateway/2015-07-09/api-2.json"

mapping "aws_api_gateway_documentation_part" {
location = DocumentationPartLocation
}

mapping "aws_api_gateway_domain_name" {
endpoint_configuration = EndpointConfiguration
mutual_tls_authentication = MutualTlsAuthenticationInput
security_policy = SecurityPolicy
}

mapping "aws_api_gateway_gateway_response" {
response_type = GatewayResponseType
status_code = StatusCode
}

Expand All @@ -14,18 +25,13 @@ mapping "aws_api_gateway_method_response" {
}

mapping "aws_api_gateway_authorizer" {
type = AuthorizerType
}

mapping "aws_api_gateway_gateway_response" {
response_type = GatewayResponseType
authorizer_result_ttl_in_seconds = NullableInteger
provider_arns = ListOfARNs
type = AuthorizerType
}

mapping "aws_api_gateway_integration" {
type = IntegrationType
}

mapping "aws_api_gateway_integration" {
connection_type = ConnectionType
content_handling = ContentHandlingStrategy
}
Expand Down
5 changes: 1 addition & 4 deletions rules/models/mappings/application-autoscaling.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ mapping "aws_appautoscaling_policy" {

mapping "aws_appautoscaling_scheduled_action" {
scalable_dimension = ScalableDimension
service_namespace = ServiceNamespace
}

mapping "aws_appautoscaling_target" {
scalable_dimension = ScalableDimension
service_namespace = ServiceNamespace
}

mapping "aws_appautoscaling_scheduled_action" {
service_namespace = ServiceNamespace
}

test "aws_appautoscaling_policy" "policy_type" {
ok = "StepScaling"
ng = "StopScaling"
Expand Down
1 change: 1 addition & 0 deletions rules/models/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var Rules = []tflint.Rule{
NewAwsALBTargetGroupInvalidTargetTypeRule(),
NewAwsAMIInvalidArchitectureRule(),
NewAwsAPIGatewayAuthorizerInvalidTypeRule(),
NewAwsAPIGatewayDomainNameInvalidSecurityPolicyRule(),
NewAwsAPIGatewayGatewayResponseInvalidResponseTypeRule(),
NewAwsAPIGatewayGatewayResponseInvalidStatusCodeRule(),
NewAwsAPIGatewayIntegrationInvalidConnectionTypeRule(),
Expand Down