1+ package rules
2+
3+ import (
4+ "testing"
5+
6+ hcl "github.com/hashicorp/hcl/v2"
7+ "github.com/terraform-linters/tflint-plugin-sdk/helper"
8+ )
9+
10+ func Test_AzurermLinuxFunctionAppFtpsState (t * testing.T ) {
11+ tests := []struct {
12+ Name string
13+ Content string
14+ Expected helper.Issues
15+ }{
16+ {
17+ Name : "ftps_state not set to Disabled" ,
18+ Content : `
19+ resource "azurerm_linux_function_app" "example" {
20+ site_config {
21+ ftps_state = "FtpsOnly"
22+ }
23+ }` ,
24+ Expected : helper.Issues {
25+ {
26+ Rule : NewAzurermLinuxFunctionAppFtpsState (),
27+ Message : "ftps_state is set to FtpsOnly, should be set to Disabled" ,
28+ Range : hcl.Range {
29+ Filename : "resource.tf" ,
30+ Start : hcl.Pos {
31+ Line : 4 ,
32+ Column : 22 ,
33+ },
34+ End : hcl.Pos {
35+ Line : 4 ,
36+ Column : 32 ,
37+ },
38+ },
39+ },
40+ },
41+ },
42+ {
43+ Name : "ftps_state set to disabled (lowercase)" ,
44+ Content : `
45+ resource "azurerm_linux_function_app" "example" {
46+ site_config {
47+ ftps_state = "disabled"
48+ }
49+ }` ,
50+ Expected : helper.Issues {},
51+ },
52+ {
53+ Name : "ftps_state set to DISABLED (uppercase)" ,
54+ Content : `
55+ resource "azurerm_linux_function_app" "example" {
56+ site_config {
57+ ftps_state = "DISABLED"
58+ }
59+ }` ,
60+ Expected : helper.Issues {},
61+ },
62+ {
63+ Name : "ftps_state attribute missing" ,
64+ Content : `
65+ resource "azurerm_linux_function_app" "example" {
66+ site_config {
67+ }
68+ }` ,
69+ Expected : helper.Issues {
70+ {
71+ Rule : NewAzurermLinuxFunctionAppFtpsState (),
72+ Message : "ftps_state is missing in site_config, should be set to Disabled" ,
73+ Range : hcl.Range {
74+ Filename : "resource.tf" ,
75+ Start : hcl.Pos {
76+ Line : 3 ,
77+ Column : 5 ,
78+ },
79+ End : hcl.Pos {
80+ Line : 3 ,
81+ Column : 16 ,
82+ },
83+ },
84+ },
85+ },
86+ },
87+ {
88+ Name : "site_config block missing" ,
89+ Content : `
90+ resource "azurerm_linux_function_app" "example" {
91+ }` ,
92+ Expected : helper.Issues {
93+ {
94+ Rule : NewAzurermLinuxFunctionAppFtpsState (),
95+ Message : "site_config block is missing, ftps_state should be set to Disabled" ,
96+ Range : hcl.Range {
97+ Filename : "resource.tf" ,
98+ Start : hcl.Pos {
99+ Line : 2 ,
100+ Column : 1 ,
101+ },
102+ End : hcl.Pos {
103+ Line : 2 ,
104+ Column : 48 ,
105+ },
106+ },
107+ },
108+ },
109+ },
110+ }
111+
112+ rule := NewAzurermLinuxFunctionAppFtpsState ()
113+
114+ for _ , test := range tests {
115+ t .Run (test .Name , func (t * testing.T ) {
116+ runner := helper .TestRunner (t , map [string ]string {"resource.tf" : test .Content })
117+
118+ if err := rule .Check (runner ); err != nil {
119+ t .Fatalf ("Unexpected error occurred: %s" , err )
120+ }
121+
122+ helper .AssertIssues (t , test .Expected , runner .Issues )
123+ })
124+ }
125+ }
0 commit comments