Skip to content

Commit 09a19b9

Browse files
authored
feat: azurerm_iothub_endpoint_eventhub_authentication_type (#16)
1 parent c017f1a commit 09a19b9

File tree

6 files changed

+196
-6
lines changed

6 files changed

+196
-6
lines changed

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
|azurerm_eventhub_namespace_public_network_access_enabled|Consider disabling public network access on eventhubs. |NOTICE|||
77
|azurerm_eventhub_namespace_minimum_tls_version|Enforce TLS 1.2 on event hubs |WARNING|||
88

9+
## azurerm_iothub_endpoint_eventhub
10+
|Name|Description|Severity|Enabled|Link|
11+
| --- | --- | --- | --- | --- |
12+
|azurerm_iothub_endpoint_eventhub_authentication_type|Consider using managed identity to authenticate agains eventhub. |NOTICE|||
13+
914
## azurerm_key_vault
1015
|Name|Description|Severity|Enabled|Link|
1116
| --- | --- | --- | --- | --- |

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ require (
2828
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
2929
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
3030
github.com/zclconf/go-cty v1.15.0 // indirect
31-
golang.org/x/mod v0.19.0 // indirect
32-
golang.org/x/net v0.27.0 // indirect
33-
golang.org/x/sync v0.7.0 // indirect
34-
golang.org/x/sys v0.22.0 // indirect
35-
golang.org/x/text v0.16.0 // indirect
36-
golang.org/x/tools v0.23.0 // indirect
31+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
32+
golang.org/x/mod v0.22.0 // indirect
33+
golang.org/x/net v0.31.0 // indirect
34+
golang.org/x/sync v0.9.0 // indirect
35+
golang.org/x/sys v0.27.0 // indirect
36+
golang.org/x/text v0.20.0 // indirect
37+
golang.org/x/tools v0.27.0 // indirect
3738
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
3839
google.golang.org/grpc v1.65.0 // indirect
3940
google.golang.org/protobuf v1.34.2 // indirect

go.sum

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,48 @@ github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ
5757
github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
5858
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
5959
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
60+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
61+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
62+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
63+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
64+
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
6065
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
6166
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
67+
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
68+
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
69+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
70+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
6271
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
6372
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
73+
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
74+
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
75+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6476
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
6577
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
78+
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
79+
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
80+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
81+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6682
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6783
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6884
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6985
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7086
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7187
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
7288
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
89+
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
90+
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
91+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7392
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
7493
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
94+
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
95+
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
96+
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
7597
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
7698
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
99+
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
100+
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
101+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
77102
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
78103
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
79104
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func createRuleSet() *tflint.BuiltinRuleSet {
1414
Rules: []tflint.Rule{
1515
rules.NewAzurermEventhubNamespacePublicNetworkAccessEnabled(),
1616
rules.NewAzurermEventhubNamespaceUnsecureTLS(),
17+
rules.NewAzurermIoTHubEndpointEventHubAuthenticationType(),
1718
rules.NewAzurermKeyVaultNetworkACLsDefaultDeny(),
1819
rules.NewAzurermKeyVaultPublicNetworkAccessEnabled(),
1920
rules.NewAzurermLinuxFunctionAppFtpsState(),
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package rules
2+
3+
import (
4+
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
5+
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
6+
)
7+
8+
// AzurermIoTHubEndpointEventHubAuthenticationType checks that the authentication_type for azurerm_iothub_endpoint_eventhub is "identityBased"
9+
type AzurermIoTHubEndpointEventHubAuthenticationType struct {
10+
tflint.DefaultRule
11+
12+
resourceType string
13+
attributeName string
14+
}
15+
16+
// NewAzurermIoTHubEndpointEventHubAuthenticationType returns a new rule instance
17+
func NewAzurermIoTHubEndpointEventHubAuthenticationType() *AzurermIoTHubEndpointEventHubAuthenticationType {
18+
return &AzurermIoTHubEndpointEventHubAuthenticationType{
19+
resourceType: "azurerm_iothub_endpoint_eventhub",
20+
attributeName: "authentication_type",
21+
}
22+
}
23+
24+
// Name returns the rule name
25+
func (r *AzurermIoTHubEndpointEventHubAuthenticationType) Name() string {
26+
return "azurerm_iothub_endpoint_eventhub_authentication_type"
27+
}
28+
29+
// Enabled returns whether the rule is enabled by default
30+
func (r *AzurermIoTHubEndpointEventHubAuthenticationType) Enabled() bool {
31+
return true
32+
}
33+
34+
// Severity returns the rule severity
35+
func (r *AzurermIoTHubEndpointEventHubAuthenticationType) Severity() tflint.Severity {
36+
return tflint.NOTICE
37+
}
38+
39+
// Link returns the rule reference link
40+
func (r *AzurermIoTHubEndpointEventHubAuthenticationType) Link() string {
41+
return ""
42+
}
43+
44+
// Check checks if the authentication_type for azurerm_iothub_endpoint_eventhub is "identityBased"
45+
func (r *AzurermIoTHubEndpointEventHubAuthenticationType) Check(runner tflint.Runner) error {
46+
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
47+
Attributes: []hclext.AttributeSchema{
48+
{Name: r.attributeName},
49+
},
50+
}, nil)
51+
if err != nil {
52+
return err
53+
}
54+
55+
for _, resource := range resources.Blocks {
56+
attribute, exists := resource.Body.Attributes[r.attributeName]
57+
if !exists {
58+
// Emit an issue if the attribute does not exist
59+
runner.EmitIssue(
60+
r,
61+
"authentication_type is not defined and should be \"identityBased\"",
62+
resource.DefRange,
63+
)
64+
continue
65+
}
66+
67+
err := runner.EvaluateExpr(attribute.Expr, func(val string) error {
68+
if val != "identityBased" {
69+
runner.EmitIssue(
70+
r,
71+
"authentication_type should be \"identityBased\"",
72+
attribute.Expr.Range(),
73+
)
74+
}
75+
return nil
76+
}, nil)
77+
78+
if err != nil {
79+
return err
80+
}
81+
}
82+
83+
return nil
84+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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_AzurermIoTHubEndpointEventHubAuthenticationType(t *testing.T) {
11+
tests := []struct {
12+
Name string
13+
Content string
14+
Expected helper.Issues
15+
}{
16+
{
17+
Name: "authentication_type not \"identityBased\"",
18+
Content: `
19+
resource "azurerm_iothub_endpoint_eventhub" "example" {
20+
authentication_type = "connectionString"
21+
}`,
22+
Expected: helper.Issues{
23+
{
24+
Rule: NewAzurermIoTHubEndpointEventHubAuthenticationType(),
25+
Message: "authentication_type should be \"identityBased\"",
26+
Range: hcl.Range{
27+
Filename: "resource.tf",
28+
Start: hcl.Pos{Line: 3, Column: 27},
29+
End: hcl.Pos{Line: 3, Column: 45},
30+
},
31+
},
32+
},
33+
},
34+
{
35+
Name: "authentication_type attribute missing",
36+
Content: `
37+
resource "azurerm_iothub_endpoint_eventhub" "example" {
38+
}`,
39+
Expected: helper.Issues{
40+
{
41+
Rule: NewAzurermIoTHubEndpointEventHubAuthenticationType(),
42+
Message: "authentication_type is not defined and should be \"identityBased\"",
43+
Range: hcl.Range{
44+
Filename: "resource.tf",
45+
Start: hcl.Pos{Line: 2, Column: 1},
46+
End: hcl.Pos{Line: 2, Column: 54},
47+
},
48+
},
49+
},
50+
},
51+
{
52+
Name: "authentication_type set to \"identityBased\"",
53+
Content: `
54+
resource "azurerm_iothub_endpoint_eventhub" "example" {
55+
authentication_type = "identityBased"
56+
}`,
57+
Expected: helper.Issues{},
58+
},
59+
}
60+
61+
rule := NewAzurermIoTHubEndpointEventHubAuthenticationType()
62+
63+
for _, test := range tests {
64+
t.Run(test.Name, func(t *testing.T) {
65+
runner := helper.TestRunner(t, map[string]string{"resource.tf": test.Content})
66+
67+
if err := rule.Check(runner); err != nil {
68+
t.Fatalf("Unexpected error occurred: %s", err)
69+
}
70+
71+
helper.AssertIssues(t, test.Expected, runner.Issues)
72+
})
73+
}
74+
}

0 commit comments

Comments
 (0)