Skip to content

Commit

Permalink
Update naming and add commments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieron Jenkins committed Sep 24, 2024
1 parent 4b0b1e9 commit d706ccb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,44 @@ import (
"github.com/terraform-linters/tflint-ruleset-azurerm/project"
)

func NewAzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule() *AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule {
return &AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule{
// NewAzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule creates a new rule to check for the deprecated attribute partition_key_path.
func NewAzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule() *AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule {
return &AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule{
resourceType: "azurerm_cosmosdb_sql_container",
attributeName: "partition_key_path",
}
}

type AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule struct {
// AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule defines a rule that checks for the deprecated partition_key_path in azurerm_cosmosdb_sql_container.
type AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule struct {
tflint.DefaultRule

resourceType string
attributeName string
}

func (r *AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule) Name() string {
// Name returns the name of the rule.
func (r *AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule) Name() string {
return "azurerm_cosmosdb_sql_container_deprecated_partition_key_path"
}

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

func (r *AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule) Severity() tflint.Severity {
// Severity returns the severity level of the rule.
func (r *AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule) Severity() tflint.Severity {
return tflint.WARNING
}

func (r *AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule) Link() string {
// Link returns the documentation link for the rule.
func (r *AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule) Link() string {
return project.ReferenceLink(r.Name())
}

func (r *AzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule) Check(runner tflint.Runner) error {
// Check examines azurerm_cosmosdb_sql_container resources and emits a warning if the deprecated partition_key_path is used.
func (r *AzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule) Check(runner tflint.Runner) error {
resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{
Attributes: []hclext.AttributeSchema{
{Name: r.attributeName},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resource "azurerm_cosmosdb_sql_container" "example" {
}`,
Expected: helper.Issues{
{
Rule: NewAzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule(),
Rule: NewAzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule(),
Message: "`partition_key_path` is deprecated and should be replaced with `partition_key_paths`.",
Range: hcl.Range{
Filename: "resource.tf",
Expand All @@ -42,7 +42,7 @@ resource "azurerm_cosmosdb_sql_container" "example" {
},
}

rule := NewAzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule()
rule := NewAzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule()

for _, tc := range cases {
runner := helper.TestRunner(t, map[string]string{"resource.tf": tc.Content})
Expand Down
2 changes: 1 addition & 1 deletion rules/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ var Rules = append([]tflint.Rule{
NewAzurermWindowsVirtualMachineInvalidSizeRule(),
NewAzurermWindowsVirtualMachineScaleSetInvalidSkuRule(),
NewAzurermResourceMissingTagsRule(),
NewAzurermCosmosdbSqlContainerDeprecatedPartitionKeyPathRule(),
NewAzurermCosmosdbSQLContainerDeprecatedPartitionKeyPathRule(),
}, apispec.Rules...)

0 comments on commit d706ccb

Please sign in to comment.