@@ -2,25 +2,26 @@ package rules
22
33import (
44 "fmt"
5+ "strings"
56
67 "github.com/terraform-linters/tflint-plugin-sdk/hclext"
78 "github.com/terraform-linters/tflint-plugin-sdk/tflint"
89)
910
10- // AzurermLinuxWebAppFtpsState checks if ftps_state is disabled
11+ // AzurermLinuxWebAppFtpsState checks that ftps_state is set to "Disabled"
1112type AzurermLinuxWebAppFtpsState struct {
1213 tflint.DefaultRule
1314
1415 resourceType string
15- attributeName string
16+ attributePath [] string
1617 expectedValue string
1718}
1819
19- // NewAzurermLinuxWebAppFtpsState creates a new rule instance
20+ // NewAzurermLinuxWebAppFtpsState returns a new rule instance
2021func NewAzurermLinuxWebAppFtpsState () * AzurermLinuxWebAppFtpsState {
2122 return & AzurermLinuxWebAppFtpsState {
2223 resourceType : "azurerm_linux_web_app" ,
23- attributeName : " ftps_state" ,
24+ attributePath : [] string { "site_config" , " ftps_state"} ,
2425 expectedValue : "Disabled" ,
2526 }
2627}
@@ -37,7 +38,7 @@ func (r *AzurermLinuxWebAppFtpsState) Enabled() bool {
3738
3839// Severity returns the rule severity
3940func (r * AzurermLinuxWebAppFtpsState ) Severity () tflint.Severity {
40- return tflint .ERROR
41+ return tflint .WARNING
4142}
4243
4344// Link returns the rule reference link
@@ -48,36 +49,53 @@ func (r *AzurermLinuxWebAppFtpsState) Link() string {
4849// Check verifies that ftps_state is set to "Disabled"
4950func (r * AzurermLinuxWebAppFtpsState ) Check (runner tflint.Runner ) error {
5051 resources , err := runner .GetResourceContent (r .resourceType , & hclext.BodySchema {
51- Attributes : []hclext.AttributeSchema {
52- {Name : r .attributeName },
52+ Blocks : []hclext.BlockSchema {
53+ {
54+ Type : "site_config" ,
55+ Body : & hclext.BodySchema {
56+ Attributes : []hclext.AttributeSchema {
57+ {Name : "ftps_state" },
58+ },
59+ },
60+ },
5361 },
5462 }, nil )
5563 if err != nil {
5664 return err
5765 }
5866
5967 for _ , resource := range resources .Blocks {
60- attribute , exists := resource .Body .Attributes [ r . attributeName ]
61- if ! exists {
68+ siteConfigBlocks := resource .Body .Blocks . OfType ( "site_config" )
69+ if len ( siteConfigBlocks ) == 0 {
6270 runner .EmitIssue (
6371 r ,
64- "ftps_state should be set to Disabled" ,
72+ "site_config block is missing, ftps_state should be set to Disabled" ,
6573 resource .DefRange ,
6674 )
6775 continue
6876 }
6977
78+ siteConfig := siteConfigBlocks [0 ]
79+ attribute , exists := siteConfig .Body .Attributes ["ftps_state" ]
80+ if ! exists {
81+ runner .EmitIssue (
82+ r ,
83+ "ftps_state is missing in site_config, should be set to Disabled" ,
84+ siteConfig .DefRange ,
85+ )
86+ continue
87+ }
88+
7089 err := runner .EvaluateExpr (attribute .Expr , func (val string ) error {
71- if val != r .expectedValue {
90+ if ! strings . EqualFold ( val , r .expectedValue ) {
7291 runner .EmitIssue (
7392 r ,
74- fmt .Sprintf ("ftps_state is set to %q , should be Disabled" , val ),
93+ fmt .Sprintf ("ftps_state is set to %s , should be set to Disabled" , val ),
7594 attribute .Expr .Range (),
7695 )
7796 }
7897 return nil
7998 }, nil )
80-
8199 if err != nil {
82100 return err
83101 }
0 commit comments