github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_cur_report_definition_invalid_s3_region.go (about)

     1  // This file generated by `generator/`. DO NOT EDIT
     2  
     3  package models
     4  
     5  import (
     6  	"fmt"
     7  	"log"
     8  
     9  	hcl "github.com/hashicorp/hcl/v2"
    10  	"github.com/terraform-linters/tflint/tflint"
    11  )
    12  
    13  // AwsCurReportDefinitionInvalidS3RegionRule checks the pattern is valid
    14  type AwsCurReportDefinitionInvalidS3RegionRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	enum          []string
    18  }
    19  
    20  // NewAwsCurReportDefinitionInvalidS3RegionRule returns new rule with default attributes
    21  func NewAwsCurReportDefinitionInvalidS3RegionRule() *AwsCurReportDefinitionInvalidS3RegionRule {
    22  	return &AwsCurReportDefinitionInvalidS3RegionRule{
    23  		resourceType:  "aws_cur_report_definition",
    24  		attributeName: "s3_region",
    25  		enum: []string{
    26  			"af-south-1",
    27  			"ap-east-1",
    28  			"ap-south-1",
    29  			"ap-southeast-1",
    30  			"ap-southeast-2",
    31  			"ap-northeast-1",
    32  			"ap-northeast-2",
    33  			"ap-northeast-3",
    34  			"ca-central-1",
    35  			"eu-central-1",
    36  			"eu-west-1",
    37  			"eu-west-2",
    38  			"eu-west-3",
    39  			"eu-north-1",
    40  			"eu-south-1",
    41  			"me-south-1",
    42  			"sa-east-1",
    43  			"us-east-1",
    44  			"us-east-2",
    45  			"us-west-1",
    46  			"us-west-2",
    47  			"cn-north-1",
    48  			"cn-northwest-1",
    49  		},
    50  	}
    51  }
    52  
    53  // Name returns the rule name
    54  func (r *AwsCurReportDefinitionInvalidS3RegionRule) Name() string {
    55  	return "aws_cur_report_definition_invalid_s3_region"
    56  }
    57  
    58  // Enabled returns whether the rule is enabled by default
    59  func (r *AwsCurReportDefinitionInvalidS3RegionRule) Enabled() bool {
    60  	return true
    61  }
    62  
    63  // Severity returns the rule severity
    64  func (r *AwsCurReportDefinitionInvalidS3RegionRule) Severity() string {
    65  	return tflint.ERROR
    66  }
    67  
    68  // Link returns the rule reference link
    69  func (r *AwsCurReportDefinitionInvalidS3RegionRule) Link() string {
    70  	return ""
    71  }
    72  
    73  // Check checks the pattern is valid
    74  func (r *AwsCurReportDefinitionInvalidS3RegionRule) Check(runner *tflint.Runner) error {
    75  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    76  
    77  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    78  		var val string
    79  		err := runner.EvaluateExpr(attribute.Expr, &val)
    80  
    81  		return runner.EnsureNoError(err, func() error {
    82  			found := false
    83  			for _, item := range r.enum {
    84  				if item == val {
    85  					found = true
    86  				}
    87  			}
    88  			if !found {
    89  				runner.EmitIssue(
    90  					r,
    91  					fmt.Sprintf(`"%s" is an invalid value as s3_region`, truncateLongMessage(val)),
    92  					attribute.Expr.Range(),
    93  				)
    94  			}
    95  			return nil
    96  		})
    97  	})
    98  }