From ed3780b474c521eba435ab71a6a56419317a8079 Mon Sep 17 00:00:00 2001 From: wata_mac Date: Mon, 21 Mar 2022 03:34:02 +0900 Subject: [PATCH] Bump tflint-plugin-sdk for gRPC-based new plugin system --- go.mod | 19 ++--- go.sum | 77 +++++++++++++------ ...erver_invalid_querypool_connection_mode.go | 34 ++++++-- ...n_insights_analytics_item_invalid_scope.go | 34 ++++++-- ...on_insights_analytics_item_invalid_type.go | 34 ++++++-- ...lication_insights_web_test_invalid_kind.go | 34 ++++++-- ...erm_automation_account_invalid_sku_name.go | 34 ++++++-- ...automation_runbook_invalid_runbook_type.go | 34 ++++++-- ...m_automation_schedule_invalid_frequency.go | 34 ++++++-- .../azurerm_batch_account_invalid_name.go | 34 ++++++-- ...ch_account_invalid_pool_allocation_mode.go | 34 ++++++-- ..._batch_application_invalid_account_name.go | 34 ++++++-- .../azurerm_batch_application_invalid_name.go | 34 ++++++-- ..._batch_certificate_invalid_account_name.go | 34 ++++++-- ...zurerm_batch_certificate_invalid_format.go | 34 ++++++-- ...azurerm_batch_pool_invalid_account_name.go | 34 ++++++-- .../azurerm_batch_pool_invalid_name.go | 34 ++++++-- ...bot_channel_directline_invalid_bot_name.go | 34 ++++++-- ..._directline_invalid_resource_group_name.go | 34 ++++++-- ...rerm_bot_channel_email_invalid_bot_name.go | 34 ++++++-- ...annel_email_invalid_resource_group_name.go | 34 ++++++-- ...m_bot_channel_ms_teams_invalid_bot_name.go | 34 ++++++-- ...el_ms_teams_invalid_resource_group_name.go | 34 ++++++-- ...rerm_bot_channel_slack_invalid_bot_name.go | 34 ++++++-- ...annel_slack_invalid_resource_group_name.go | 34 ++++++-- ...egistration_invalid_resource_group_name.go | 34 ++++++-- ...m_bot_channels_registration_invalid_sku.go | 34 ++++++-- ...azurerm_bot_connection_invalid_bot_name.go | 34 ++++++-- .../azurerm_bot_connection_invalid_name.go | 34 ++++++-- ..._connection_invalid_resource_group_name.go | 34 ++++++-- .../azurerm_bot_web_app_invalid_name.go | 34 ++++++-- ...bot_web_app_invalid_resource_group_name.go | 34 ++++++-- .../azurerm_bot_web_app_invalid_sku.go | 34 ++++++-- ..._cdn_endpoint_invalid_optimization_type.go | 34 ++++++-- ...t_invalid_querystring_caching_behaviour.go | 34 ++++++-- ...dn_endpoint_invalid_resource_group_name.go | 34 ++++++-- ...cdn_profile_invalid_resource_group_name.go | 34 ++++++-- .../azurerm_cdn_profile_invalid_sku.go | 34 ++++++-- .../azurerm_cognitive_account_invalid_name.go | 34 ++++++-- ...container_group_invalid_ip_address_type.go | 34 ++++++-- ...azurerm_container_registry_invalid_name.go | 34 ++++++-- .../azurerm_container_registry_invalid_sku.go | 34 ++++++-- ...container_registry_webhook_invalid_name.go | 34 ++++++-- ..._registry_webhook_invalid_registry_name.go | 34 ++++++-- ...ntainer_registry_webhook_invalid_status.go | 34 ++++++-- .../azurerm_cosmosdb_account_invalid_kind.go | 34 ++++++-- .../azurerm_cosmosdb_account_invalid_name.go | 34 ++++++-- ...erm_cosmosdb_account_invalid_offer_type.go | 34 ++++++-- ...sdb_account_invalid_resource_group_name.go | 34 ++++++-- ...cassandra_keyspace_invalid_account_name.go | 34 ++++++-- ...ra_keyspace_invalid_resource_group_name.go | 34 ++++++-- ...b_gremlin_database_invalid_account_name.go | 34 ++++++-- ...in_database_invalid_resource_group_name.go | 34 ++++++-- ...osdb_gremlin_graph_invalid_account_name.go | 34 ++++++-- ...emlin_graph_invalid_resource_group_name.go | 34 ++++++-- ..._collection_invalid_resource_group_name.go | 34 ++++++-- ...sdb_mongo_database_invalid_account_name.go | 34 ++++++-- ...go_database_invalid_resource_group_name.go | 34 ++++++-- ...osdb_sql_container_invalid_account_name.go | 34 ++++++-- ...l_container_invalid_resource_group_name.go | 34 ++++++-- ...mosdb_sql_database_invalid_account_name.go | 34 ++++++-- ...ql_database_invalid_resource_group_name.go | 34 ++++++-- ...erm_cosmosdb_table_invalid_account_name.go | 34 ++++++-- ...mosdb_table_invalid_resource_group_name.go | 34 ++++++-- ..._resource_group_invalid_recurrence_type.go | 34 ++++++-- ...dataset_mysql_invalid_data_factory_name.go | 34 ++++++-- ...taset_mysql_invalid_linked_service_name.go | 34 ++++++-- ...data_factory_dataset_mysql_invalid_name.go | 34 ++++++-- ...taset_mysql_invalid_resource_group_name.go | 34 ++++++-- ...et_postgresql_invalid_data_factory_name.go | 34 ++++++-- ..._postgresql_invalid_linked_service_name.go | 34 ++++++-- ...factory_dataset_postgresql_invalid_name.go | 34 ++++++-- ..._postgresql_invalid_resource_group_name.go | 34 ++++++-- ..._server_table_invalid_data_factory_name.go | 34 ++++++-- ...erver_table_invalid_linked_service_name.go | 34 ++++++-- ...y_dataset_sql_server_table_invalid_name.go | 34 ++++++-- ...erver_table_invalid_resource_group_name.go | 34 ++++++-- ...gration_runtime_managed_invalid_edition.go | 34 ++++++-- ...on_runtime_managed_invalid_license_type.go | 34 ++++++-- ...nvalid_max_parallel_executions_per_node.go | 34 ++++++-- ...runtime_managed_invalid_number_of_nodes.go | 34 ++++++-- .../azurerm_data_factory_invalid_name.go | 34 ++++++-- ...ata_factory_invalid_resource_group_name.go | 34 ++++++-- ..._storage_gen2_invalid_data_factory_name.go | 34 ++++++-- ...ice_data_lake_storage_gen2_invalid_name.go | 34 ++++++-- ...torage_gen2_invalid_resource_group_name.go | 34 ++++++-- ...service_mysql_invalid_data_factory_name.go | 34 ++++++-- ...ctory_linked_service_mysql_invalid_name.go | 34 ++++++-- ...rvice_mysql_invalid_resource_group_name.go | 34 ++++++-- ...ce_postgresql_invalid_data_factory_name.go | 34 ++++++-- ..._linked_service_postgresql_invalid_name.go | 34 ++++++-- ..._postgresql_invalid_resource_group_name.go | 34 ++++++-- ...ce_sql_server_invalid_data_factory_name.go | 34 ++++++-- ..._linked_service_sql_server_invalid_name.go | 34 ++++++-- ..._sql_server_invalid_resource_group_name.go | 34 ++++++-- ...tory_pipeline_invalid_data_factory_name.go | 34 ++++++-- ...rerm_data_factory_pipeline_invalid_name.go | 34 ++++++-- ...ry_pipeline_invalid_resource_group_name.go | 34 ++++++-- ...tory_trigger_schedule_invalid_frequency.go | 34 ++++++-- ...ata_lake_analytics_account_invalid_tier.go | 34 ++++++-- ...ata_lake_store_invalid_encryption_state.go | 34 ++++++-- ...data_lake_store_invalid_encryption_type.go | 34 ++++++-- ..._store_invalid_firewall_allow_azure_ips.go | 34 ++++++-- ..._data_lake_store_invalid_firewall_state.go | 34 ++++++-- .../azurerm_data_lake_store_invalid_tier.go | 34 ++++++-- ...gration_project_invalid_source_platform.go | 34 ++++++-- ...gration_project_invalid_target_platform.go | 34 ++++++-- ...ace_invalid_managed_resource_group_name.go | 34 ++++++-- ...s_workspace_invalid_resource_group_name.go | 34 ++++++-- ...oup_invalid_platform_fault_domain_count.go | 34 ++++++-- ...erm_dedicated_host_invalid_license_type.go | 34 ++++++-- ...ated_host_invalid_platform_fault_domain.go | 34 ++++++-- ..._dev_test_policy_invalid_evaluator_type.go | 34 ++++++-- .../azurerm_dev_test_policy_invalid_name.go | 34 ++++++-- ...zurerm_dev_test_schedule_invalid_status.go | 34 ++++++-- ...zurerm_devspace_controller_invalid_name.go | 34 ++++++-- ...rm_devspace_controller_invalid_sku_name.go | 34 ++++++-- ...m_eventgrid_domain_invalid_input_schema.go | 34 ++++++-- ...scription_invalid_event_delivery_schema.go | 34 ++++++-- ...erm_eventhub_namespace_invalid_capacity.go | 34 ++++++-- .../azurerm_eventhub_namespace_invalid_sku.go | 34 ++++++-- ...te_circuit_peering_invalid_peering_type.go | 34 ++++++-- ...lication_rule_collection_invalid_action.go | 34 ++++++-- ...cation_rule_collection_invalid_priority.go | 38 ++++++--- ...wall_nat_rule_collection_invalid_action.go | 34 ++++++-- ...ll_nat_rule_collection_invalid_priority.go | 38 ++++++--- ..._network_rule_collection_invalid_action.go | 34 ++++++-- ...etwork_rule_collection_invalid_priority.go | 38 ++++++--- ...licy_invalid_custom_block_response_body.go | 34 ++++++-- ..._frontdoor_firewall_policy_invalid_mode.go | 34 ++++++-- ...wall_policy_invalid_resource_group_name.go | 34 ++++++-- ...kend_pools_send_receive_timeout_seconds.go | 34 ++++++-- .../apispec/azurerm_frontdoor_invalid_name.go | 34 ++++++-- ...m_frontdoor_invalid_resource_group_name.go | 34 ++++++-- ...m_hdinsight_hadoop_cluster_invalid_tier.go | 34 ++++++-- ...rm_hdinsight_hbase_cluster_invalid_tier.go | 34 ++++++-- ..._interactive_query_cluster_invalid_tier.go | 34 ++++++-- ...rm_hdinsight_kafka_cluster_invalid_tier.go | 34 ++++++-- ...nsight_ml_services_cluster_invalid_tier.go | 34 ++++++-- ..._hdinsight_rserver_cluster_invalid_tier.go | 34 ++++++-- ...rm_hdinsight_spark_cluster_invalid_tier.go | 34 ++++++-- ...rm_hdinsight_storm_cluster_invalid_tier.go | 34 ++++++-- ...are_service_invalid_cosmosdb_throughput.go | 38 ++++++--- ...azurerm_healthcare_service_invalid_kind.go | 34 ++++++-- ...are_service_invalid_resource_group_name.go | 34 ++++++-- .../apispec/azurerm_hpc_cache_invalid_name.go | 34 ++++++-- ...zurerm_image_invalid_hyper_v_generation.go | 34 ++++++-- ...rerm_iotcentral_application_invalid_sku.go | 34 ++++++-- ...iner_invalid_batch_frequency_in_seconds.go | 38 ++++++--- ...oint_storage_container_invalid_encoding.go | 34 ++++++-- ...ntainer_invalid_max_chunk_size_in_bytes.go | 38 ++++++--- ...endpoint_storage_container_invalid_name.go | 34 ++++++-- .../azurerm_iothub_route_invalid_name.go | 34 ++++++-- .../azurerm_iothub_route_invalid_source.go | 34 ++++++-- .../apispec/azurerm_key_vault_invalid_name.go | 34 ++++++-- .../azurerm_key_vault_invalid_sku_name.go | 34 ++++++-- .../azurerm_key_vault_key_invalid_curve.go | 34 ++++++-- .../azurerm_key_vault_key_invalid_key_type.go | 34 ++++++-- ...uster_default_node_pool_invalid_vm_size.go | 48 ++++++++---- ...azurerm_kubernetes_cluster_invalid_name.go | 34 ++++++-- ...uster_node_pool_invalid_os_disk_size_gb.go | 38 ++++++--- ...netes_cluster_node_pool_invalid_os_type.go | 34 ++++++-- ...netes_cluster_node_pool_invalid_vm_size.go | 34 ++++++-- ...m_kusto_database_principal_invalid_role.go | 34 ++++++-- ...m_kusto_database_principal_invalid_type.go | 34 ++++++-- ...hub_data_connection_invalid_data_format.go | 34 ++++++-- rules/apispec/azurerm_lb_invalid_sku.go | 34 ++++++-- .../azurerm_lb_nat_pool_invalid_protocol.go | 34 ++++++-- .../azurerm_lb_nat_rule_invalid_protocol.go | 34 ++++++-- ...urerm_lb_outbound_rule_invalid_protocol.go | 34 ++++++-- .../azurerm_lb_probe_invalid_protocol.go | 34 ++++++-- ...urerm_lb_rule_invalid_load_distribution.go | 34 ++++++-- .../azurerm_lb_rule_invalid_protocol.go | 34 ++++++-- ...virtual_machine_invalid_eviction_policy.go | 34 ++++++-- ..._linux_virtual_machine_invalid_priority.go | 34 ++++++-- ...chine_scale_set_invalid_eviction_policy.go | 34 ++++++-- ...tual_machine_scale_set_invalid_priority.go | 34 ++++++-- ..._machine_scale_set_invalid_upgrade_mode.go | 34 ++++++-- ...pp_trigger_recurrence_invalid_frequency.go | 34 ++++++-- ...maintenance_configuration_invalid_scope.go | 34 ++++++-- ...plication_definition_invalid_lock_level.go | 34 ++++++-- ...rerm_managed_disk_invalid_create_option.go | 34 ++++++-- .../azurerm_managed_disk_invalid_os_type.go | 34 ++++++-- ...naged_disk_invalid_storage_account_type.go | 34 ++++++-- .../azurerm_maps_account_invalid_sku_name.go | 34 ++++++-- ...db_firewall_rule_invalid_end_ip_address.go | 34 ++++++-- ..._firewall_rule_invalid_start_ip_address.go | 34 ++++++-- ..._mariadb_server_invalid_ssl_enforcement.go | 34 ++++++-- .../azurerm_mariadb_server_invalid_version.go | 34 ++++++-- ...uled_query_rules_alert_invalid_severity.go | 34 ++++++-- ...l_machine_invalid_sql_connectivity_type.go | 34 ++++++-- ...irtual_machine_invalid_sql_license_type.go | 34 ++++++-- ...ql_firewall_rule_invalid_end_ip_address.go | 34 ++++++-- ..._firewall_rule_invalid_start_ip_address.go | 34 ++++++-- ...rm_mysql_server_invalid_ssl_enforcement.go | 75 ------------------ .../azurerm_mysql_server_invalid_version.go | 34 ++++++-- .../azurerm_nat_gateway_invalid_sku_name.go | 34 ++++++-- ...app_account_invalid_resource_group_name.go | 34 ++++++-- .../azurerm_netapp_pool_invalid_name.go | 34 ++++++-- ...netapp_pool_invalid_resource_group_name.go | 34 ++++++-- ...urerm_netapp_pool_invalid_service_level.go | 34 ++++++-- ...pp_snapshot_invalid_resource_group_name.go | 34 ++++++-- .../azurerm_netapp_volume_invalid_name.go | 34 ++++++-- ...azurerm_netapp_volume_invalid_pool_name.go | 34 ++++++-- ...tapp_volume_invalid_resource_group_name.go | 34 ++++++-- ...erm_netapp_volume_invalid_service_level.go | 34 ++++++-- ...apture_invalid_maximum_capture_duration.go | 38 ++++++--- ...rm_network_security_rule_invalid_access.go | 34 ++++++-- ...network_security_rule_invalid_direction.go | 34 ++++++-- ..._network_security_rule_invalid_protocol.go | 34 ++++++-- ...on_hub_namespace_invalid_namespace_type.go | 34 ++++++-- ...fication_hub_namespace_invalid_sku_name.go | 34 ++++++-- ...apture_invalid_maximum_capture_duration.go | 38 ++++++--- ...ql_firewall_rule_invalid_end_ip_address.go | 34 ++++++-- ..._firewall_rule_invalid_start_ip_address.go | 34 ++++++-- ...stgresql_server_invalid_ssl_enforcement.go | 34 ++++++-- ...urerm_postgresql_server_invalid_version.go | 34 ++++++-- .../apispec/azurerm_public_ip_invalid_sku.go | 34 ++++++-- .../azurerm_public_ip_prefix_invalid_sku.go | 34 ++++++-- ...erm_recovery_services_vault_invalid_sku.go | 34 ++++++-- .../azurerm_redis_cache_invalid_family.go | 34 ++++++-- ...redis_cache_invalid_minimum_tls_version.go | 34 ++++++-- ...cache_invalid_private_static_ip_address.go | 34 ++++++-- .../azurerm_redis_cache_invalid_sku_name.go | 34 ++++++-- .../azurerm_redis_cache_invalid_subnet_id.go | 34 ++++++-- ...zurerm_relay_namespace_invalid_sku_name.go | 34 ++++++-- .../azurerm_route_invalid_next_hop_type.go | 34 ++++++-- ..._search_service_invalid_partition_count.go | 38 ++++++--- ...rm_search_service_invalid_replica_count.go | 38 ++++++--- .../azurerm_search_service_invalid_sku.go | 34 ++++++-- ...ecurity_incident_invalid_product_filter.go | 34 ++++++-- ...abric_cluster_invalid_reliability_level.go | 34 ++++++-- ...ice_fabric_cluster_invalid_upgrade_mode.go | 34 ++++++-- ...zurerm_servicebus_namespace_invalid_sku.go | 34 ++++++-- ...s_subscription_rule_invalid_filter_type.go | 34 ++++++-- ...azurerm_servicebus_topic_invalid_status.go | 34 ++++++-- .../azurerm_shared_image_invalid_os_type.go | 34 ++++++-- .../azurerm_snapshot_invalid_create_option.go | 34 ++++++-- ...zurerm_sql_database_invalid_create_mode.go | 34 ++++++-- ...erm_storage_account_invalid_access_tier.go | 34 ++++++-- ...rm_storage_account_invalid_account_kind.go | 34 ++++++-- ...age_account_invalid_resource_group_name.go | 34 ++++++-- ...nt_network_rules_invalid_default_action.go | 34 ++++++-- ...twork_rules_invalid_resource_group_name.go | 34 ++++++-- ...alytics_job_invalid_compatibility_level.go | 34 ++++++-- ..._job_invalid_events_out_of_order_policy.go | 34 ++++++-- ...alytics_job_invalid_output_error_policy.go | 34 ++++++-- ...late_deployment_invalid_deployment_mode.go | 34 ++++++-- ...anager_endpoint_invalid_endpoint_status.go | 34 ++++++-- ..._manager_profile_invalid_profile_status.go | 34 ++++++-- ..._profile_invalid_traffic_routing_method.go | 34 ++++++-- ...ne_data_disk_attachment_invalid_caching.go | 34 ++++++-- ...a_disk_attachment_invalid_create_option.go | 34 ++++++-- ...chine_scale_set_invalid_eviction_policy.go | 34 ++++++-- ...tual_machine_scale_set_invalid_priority.go | 34 ++++++-- ...e_scale_set_invalid_upgrade_policy_mode.go | 34 ++++++-- ..._connection_invalid_connection_protocol.go | 34 ++++++-- ...network_gateway_connection_invalid_type.go | 34 ++++++-- ...tual_network_gateway_invalid_generation.go | 34 ++++++-- ...erm_virtual_network_gateway_invalid_sku.go | 34 ++++++-- ...rm_virtual_network_gateway_invalid_type.go | 34 ++++++-- ...irtual_network_gateway_invalid_vpn_type.go | 34 ++++++-- ...valid_office365_local_breakout_category.go | 34 ++++++-- ...virtual_machine_invalid_eviction_policy.go | 34 ++++++-- ...indows_virtual_machine_invalid_priority.go | 34 ++++++-- ...chine_scale_set_invalid_eviction_policy.go | 34 ++++++-- ...tual_machine_scale_set_invalid_priority.go | 34 ++++++-- ..._machine_scale_set_invalid_upgrade_mode.go | 34 ++++++-- ...rerm_linux_virtual_machine_invalid_size.go | 33 ++++++-- ...x_virtual_machine_scale_set_invalid_sku.go | 33 ++++++-- ...azurerm_virtual_machine_invalid_vm_size.go | 33 ++++++-- ...rm_windows_virtual_machine_invalid_size.go | 33 ++++++-- ...s_virtual_machine_scale_set_invalid_sku.go | 33 ++++++-- tools/apispec-rule-gen/rule.go.tmpl | 47 +++++++---- tools/apispec-rule-gen/rule_block.go.tmpl | 61 +++++++++------ 275 files changed, 7445 insertions(+), 2067 deletions(-) delete mode 100644 rules/apispec/azurerm_mysql_server_invalid_ssl_enforcement.go diff --git a/go.mod b/go.mod index 7788358c..c0688bcb 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,11 @@ go 1.17 require ( github.com/dave/dst v0.26.2 - github.com/google/go-cmp v0.5.6 + github.com/google/go-cmp v0.5.7 github.com/hashicorp/hcl/v2 v2.11.1 github.com/onsi/gomega v1.14.0 // indirect github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e - github.com/terraform-linters/tflint-plugin-sdk v0.9.1 + github.com/terraform-linters/tflint-plugin-sdk v0.9.2-0.20220327063603-919fa2776c6c ) require ( @@ -16,10 +16,8 @@ require ( github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/fatih/color v1.7.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/hashicorp/go-hclog v0.16.2 // indirect - github.com/hashicorp/go-plugin v1.4.2 // indirect - github.com/hashicorp/go-version v1.3.0 // indirect - github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect + github.com/hashicorp/go-hclog v1.2.0 // indirect + github.com/hashicorp/go-plugin v1.4.3 // indirect github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-isatty v0.0.10 // indirect @@ -27,10 +25,9 @@ require ( github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect github.com/oklog/run v1.0.0 // indirect github.com/onsi/ginkgo v1.16.4 // indirect - github.com/stretchr/testify v1.5.1 // indirect github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect github.com/vmihailenco/tagparser v0.1.1 // indirect - github.com/zclconf/go-cty v1.9.0 // indirect + github.com/zclconf/go-cty v1.10.0 // indirect golang.org/x/mod v0.3.0 // indirect golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect @@ -38,7 +35,7 @@ require ( golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/appengine v1.6.5 // indirect - google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect - google.golang.org/grpc v1.27.1 // indirect - google.golang.org/protobuf v1.26.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/grpc v1.45.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect ) diff --git a/go.sum b/go.sum index fe881f17..cc3a925c 100644 --- a/go.sum +++ b/go.sum @@ -3,13 +3,21 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/dave/dst v0.26.2 h1:lnxLAKI3tx7MgLNVDirFCsDTlTG9nKTk7GcptKcWSwY= github.com/dave/dst v0.26.2/go.mod h1:UMDJuIRPfyUCC78eFuB+SV/WI8oDeyFDvM/JR6NI3IU= github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ= @@ -19,30 +27,37 @@ github.com/dave/rebecca v0.9.1/go.mod h1:N6XYdMD/OKw3lkF3ywh8Z6wPGuwNFDNtWYEMFWE github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -50,24 +65,20 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/pprof v0.0.0-20181127221834-b4f47329b966/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-hclog v0.16.2 h1:K4ev2ib4LdQETX5cSZBG0DVLk1jwGqSPXBjdah3veNs= -github.com/hashicorp/go-hclog v0.16.2/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= -github.com/hashicorp/go-plugin v1.4.2 h1:yFvG3ufXXpqiMiZx9HLcaK3XbIqQ1WJFR/F1a2CuVw0= -github.com/hashicorp/go-plugin v1.4.2/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04x7iNw= -github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hcl/v2 v2.10.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= +github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= +github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v6UZM= +github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ= github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJbcc= github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= -github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= -github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -106,6 +117,7 @@ github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+t github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e h1:zWKUYT07mGmVBH+9UgnHXd/ekCK99C8EbDSAt5qsjXE= github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= @@ -114,10 +126,11 @@ github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/terraform-linters/tflint-plugin-sdk v0.9.1 h1:Q7+QmvkxrINjsxQ9iOR9GDIppS7kT2hXQBHNaZ+01ug= -github.com/terraform-linters/tflint-plugin-sdk v0.9.1/go.mod h1:2pu+KHPrxfV/Y0inO9c5w4ptL6dNIHu8Em7ZxXBNP4E= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/terraform-linters/tflint-plugin-sdk v0.9.2-0.20220327063603-919fa2776c6c h1:O/HVL2Lt+1hn2pwPZ7KTqU8H8rpi+OTEkkwdDEOy0KE= +github.com/terraform-linters/tflint-plugin-sdk v0.9.2-0.20220327063603-919fa2776c6c/go.mod h1:buSG6YRD4H7GzQpPerADmNBFaYOx31B8o8u9l+7SegY= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U= @@ -126,12 +139,12 @@ github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37w github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.9.0 h1:IgJxw5b4LPXCPeqFjjhLaNEA8NKXMyaEUdAd399acts= -github.com/zclconf/go-cty v1.9.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0= +github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.org/x/arch v0.0.0-20180920145803-b19384d3c130/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -155,15 +168,15 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -214,22 +227,33 @@ google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpC google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20170818010345-ee236bd376b0/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.8.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.45.0 h1:NEpgUqV3Z+ZjkqMsxMg11IaDrXY4RY6CQukSGK0uI1M= +google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -238,9 +262,12 @@ gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/rules/apispec/azurerm_analysis_services_server_invalid_querypool_connection_mode.go b/rules/apispec/azurerm_analysis_services_server_invalid_querypool_connection_mode.go index 45cd965c..0df5189a 100644 --- a/rules/apispec/azurerm_analysis_services_server_invalid_querypool_connection_mode.go +++ b/rules/apispec/azurerm_analysis_services_server_invalid_querypool_connection_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule checks the pattern is valid type AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Enable } // Severity returns the rule severity -func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Severity() string { +func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Link() // Check checks the pattern is valid func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermAnalysisServicesServerInvalidQuerypoolConnectionModeRule) Check( } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as querypool_connection_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_application_insights_analytics_item_invalid_scope.go b/rules/apispec/azurerm_application_insights_analytics_item_invalid_scope.go index 68bc72d4..1434ee1e 100644 --- a/rules/apispec/azurerm_application_insights_analytics_item_invalid_scope.go +++ b/rules/apispec/azurerm_application_insights_analytics_item_invalid_scope.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermApplicationInsightsAnalyticsItemInvalidScopeRule checks the pattern is valid type AzurermApplicationInsightsAnalyticsItemInvalidScopeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Severity() string { +func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Link() string // Check checks the pattern is valid func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidScopeRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as scope`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_application_insights_analytics_item_invalid_type.go b/rules/apispec/azurerm_application_insights_analytics_item_invalid_type.go index b8cffa98..fd3882c9 100644 --- a/rules/apispec/azurerm_application_insights_analytics_item_invalid_type.go +++ b/rules/apispec/azurerm_application_insights_analytics_item_invalid_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermApplicationInsightsAnalyticsItemInvalidTypeRule checks the pattern is valid type AzurermApplicationInsightsAnalyticsItemInvalidTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Severity() string { +func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermApplicationInsightsAnalyticsItemInvalidTypeRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_application_insights_web_test_invalid_kind.go b/rules/apispec/azurerm_application_insights_web_test_invalid_kind.go index 4be03bbe..dd405335 100644 --- a/rules/apispec/azurerm_application_insights_web_test_invalid_kind.go +++ b/rules/apispec/azurerm_application_insights_web_test_invalid_kind.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermApplicationInsightsWebTestInvalidKindRule checks the pattern is valid type AzurermApplicationInsightsWebTestInvalidKindRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Severity() string { +func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Link() string { // Check checks the pattern is valid func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermApplicationInsightsWebTestInvalidKindRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as kind`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_automation_account_invalid_sku_name.go b/rules/apispec/azurerm_automation_account_invalid_sku_name.go index e2662332..0d190c69 100644 --- a/rules/apispec/azurerm_automation_account_invalid_sku_name.go +++ b/rules/apispec/azurerm_automation_account_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermAutomationAccountInvalidSkuNameRule checks the pattern is valid type AzurermAutomationAccountInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermAutomationAccountInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermAutomationAccountInvalidSkuNameRule) Severity() string { +func (r *AzurermAutomationAccountInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermAutomationAccountInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermAutomationAccountInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermAutomationAccountInvalidSkuNameRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_automation_runbook_invalid_runbook_type.go b/rules/apispec/azurerm_automation_runbook_invalid_runbook_type.go index f477c754..8f39fac9 100644 --- a/rules/apispec/azurerm_automation_runbook_invalid_runbook_type.go +++ b/rules/apispec/azurerm_automation_runbook_invalid_runbook_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermAutomationRunbookInvalidRunbookTypeRule checks the pattern is valid type AzurermAutomationRunbookInvalidRunbookTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Severity() string { +func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermAutomationRunbookInvalidRunbookTypeRule) Check(runner tflint.Run } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as runbook_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_automation_schedule_invalid_frequency.go b/rules/apispec/azurerm_automation_schedule_invalid_frequency.go index 070c10e7..7798133d 100644 --- a/rules/apispec/azurerm_automation_schedule_invalid_frequency.go +++ b/rules/apispec/azurerm_automation_schedule_invalid_frequency.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermAutomationScheduleInvalidFrequencyRule checks the pattern is valid type AzurermAutomationScheduleInvalidFrequencyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermAutomationScheduleInvalidFrequencyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermAutomationScheduleInvalidFrequencyRule) Severity() string { +func (r *AzurermAutomationScheduleInvalidFrequencyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermAutomationScheduleInvalidFrequencyRule) Link() string { // Check checks the pattern is valid func (r *AzurermAutomationScheduleInvalidFrequencyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermAutomationScheduleInvalidFrequencyRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as frequency`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_account_invalid_name.go b/rules/apispec/azurerm_batch_account_invalid_name.go index 70fb6995..297a3f95 100644 --- a/rules/apispec/azurerm_batch_account_invalid_name.go +++ b/rules/apispec/azurerm_batch_account_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchAccountInvalidNameRule checks the pattern is valid type AzurermBatchAccountInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchAccountInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchAccountInvalidNameRule) Severity() string { +func (r *AzurermBatchAccountInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchAccountInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchAccountInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_account_invalid_pool_allocation_mode.go b/rules/apispec/azurerm_batch_account_invalid_pool_allocation_mode.go index 87c6da7c..79057638 100644 --- a/rules/apispec/azurerm_batch_account_invalid_pool_allocation_mode.go +++ b/rules/apispec/azurerm_batch_account_invalid_pool_allocation_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchAccountInvalidPoolAllocationModeRule checks the pattern is valid type AzurermBatchAccountInvalidPoolAllocationModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Severity() string { +func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermBatchAccountInvalidPoolAllocationModeRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as pool_allocation_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_application_invalid_account_name.go b/rules/apispec/azurerm_batch_application_invalid_account_name.go index 1db25b99..16831b66 100644 --- a/rules/apispec/azurerm_batch_application_invalid_account_name.go +++ b/rules/apispec/azurerm_batch_application_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchApplicationInvalidAccountNameRule checks the pattern is valid type AzurermBatchApplicationInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchApplicationInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchApplicationInvalidAccountNameRule) Severity() string { +func (r *AzurermBatchApplicationInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchApplicationInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchApplicationInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_application_invalid_name.go b/rules/apispec/azurerm_batch_application_invalid_name.go index 5e21780b..07348e43 100644 --- a/rules/apispec/azurerm_batch_application_invalid_name.go +++ b/rules/apispec/azurerm_batch_application_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchApplicationInvalidNameRule checks the pattern is valid type AzurermBatchApplicationInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchApplicationInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchApplicationInvalidNameRule) Severity() string { +func (r *AzurermBatchApplicationInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchApplicationInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchApplicationInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9_-]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_certificate_invalid_account_name.go b/rules/apispec/azurerm_batch_certificate_invalid_account_name.go index 92d22cb8..e44ef729 100644 --- a/rules/apispec/azurerm_batch_certificate_invalid_account_name.go +++ b/rules/apispec/azurerm_batch_certificate_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchCertificateInvalidAccountNameRule checks the pattern is valid type AzurermBatchCertificateInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchCertificateInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchCertificateInvalidAccountNameRule) Severity() string { +func (r *AzurermBatchCertificateInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchCertificateInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchCertificateInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_certificate_invalid_format.go b/rules/apispec/azurerm_batch_certificate_invalid_format.go index 3f70e67c..3144e82f 100644 --- a/rules/apispec/azurerm_batch_certificate_invalid_format.go +++ b/rules/apispec/azurerm_batch_certificate_invalid_format.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchCertificateInvalidFormatRule checks the pattern is valid type AzurermBatchCertificateInvalidFormatRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermBatchCertificateInvalidFormatRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchCertificateInvalidFormatRule) Severity() string { +func (r *AzurermBatchCertificateInvalidFormatRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermBatchCertificateInvalidFormatRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchCertificateInvalidFormatRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermBatchCertificateInvalidFormatRule) Check(runner tflint.Runner) e } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as format`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_pool_invalid_account_name.go b/rules/apispec/azurerm_batch_pool_invalid_account_name.go index d7bcc83a..16c5bd0f 100644 --- a/rules/apispec/azurerm_batch_pool_invalid_account_name.go +++ b/rules/apispec/azurerm_batch_pool_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchPoolInvalidAccountNameRule checks the pattern is valid type AzurermBatchPoolInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchPoolInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchPoolInvalidAccountNameRule) Severity() string { +func (r *AzurermBatchPoolInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchPoolInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchPoolInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_batch_pool_invalid_name.go b/rules/apispec/azurerm_batch_pool_invalid_name.go index d5f414a1..6fb9ef6a 100644 --- a/rules/apispec/azurerm_batch_pool_invalid_name.go +++ b/rules/apispec/azurerm_batch_pool_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBatchPoolInvalidNameRule checks the pattern is valid type AzurermBatchPoolInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBatchPoolInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBatchPoolInvalidNameRule) Severity() string { +func (r *AzurermBatchPoolInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBatchPoolInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBatchPoolInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9_-]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_directline_invalid_bot_name.go b/rules/apispec/azurerm_bot_channel_directline_invalid_bot_name.go index 9ebd04e9..614e1d70 100644 --- a/rules/apispec/azurerm_bot_channel_directline_invalid_bot_name.go +++ b/rules/apispec/azurerm_bot_channel_directline_invalid_bot_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelDirectlineInvalidBotNameRule checks the pattern is valid type AzurermBotChannelDirectlineInvalidBotNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelDirectlineInvalidBotNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelDirectlineInvalidBotNameRule) Severity() string { +func (r *AzurermBotChannelDirectlineInvalidBotNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelDirectlineInvalidBotNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelDirectlineInvalidBotNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_directline_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_channel_directline_invalid_resource_group_name.go index e5381f57..7bf5eaf1 100644 --- a/rules/apispec/azurerm_bot_channel_directline_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_channel_directline_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelDirectlineInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotChannelDirectlineInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelDirectlineInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermBotChannelDirectlineInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotChannelDirectlineInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelDirectlineInvalidResourceGroupNameRule) Link() string // Check checks the pattern is valid func (r *AzurermBotChannelDirectlineInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_email_invalid_bot_name.go b/rules/apispec/azurerm_bot_channel_email_invalid_bot_name.go index 2331fc5d..c22ee4b2 100644 --- a/rules/apispec/azurerm_bot_channel_email_invalid_bot_name.go +++ b/rules/apispec/azurerm_bot_channel_email_invalid_bot_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelEmailInvalidBotNameRule checks the pattern is valid type AzurermBotChannelEmailInvalidBotNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelEmailInvalidBotNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelEmailInvalidBotNameRule) Severity() string { +func (r *AzurermBotChannelEmailInvalidBotNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelEmailInvalidBotNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelEmailInvalidBotNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_email_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_channel_email_invalid_resource_group_name.go index 6ce8a48e..742803cd 100644 --- a/rules/apispec/azurerm_bot_channel_email_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_channel_email_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelEmailInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotChannelEmailInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelEmailInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelEmailInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotChannelEmailInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelEmailInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelEmailInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_ms_teams_invalid_bot_name.go b/rules/apispec/azurerm_bot_channel_ms_teams_invalid_bot_name.go index 08e57629..be90b17f 100644 --- a/rules/apispec/azurerm_bot_channel_ms_teams_invalid_bot_name.go +++ b/rules/apispec/azurerm_bot_channel_ms_teams_invalid_bot_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelMsTeamsInvalidBotNameRule checks the pattern is valid type AzurermBotChannelMsTeamsInvalidBotNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelMsTeamsInvalidBotNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelMsTeamsInvalidBotNameRule) Severity() string { +func (r *AzurermBotChannelMsTeamsInvalidBotNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelMsTeamsInvalidBotNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelMsTeamsInvalidBotNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_ms_teams_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_channel_ms_teams_invalid_resource_group_name.go index 2bbad2ed..8449e0f0 100644 --- a/rules/apispec/azurerm_bot_channel_ms_teams_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_channel_ms_teams_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelMsTeamsInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotChannelMsTeamsInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelMsTeamsInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelMsTeamsInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotChannelMsTeamsInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelMsTeamsInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelMsTeamsInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_slack_invalid_bot_name.go b/rules/apispec/azurerm_bot_channel_slack_invalid_bot_name.go index bc90e1af..3a7692ef 100644 --- a/rules/apispec/azurerm_bot_channel_slack_invalid_bot_name.go +++ b/rules/apispec/azurerm_bot_channel_slack_invalid_bot_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelSlackInvalidBotNameRule checks the pattern is valid type AzurermBotChannelSlackInvalidBotNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelSlackInvalidBotNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelSlackInvalidBotNameRule) Severity() string { +func (r *AzurermBotChannelSlackInvalidBotNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelSlackInvalidBotNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelSlackInvalidBotNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channel_slack_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_channel_slack_invalid_resource_group_name.go index 4a54034e..96d13835 100644 --- a/rules/apispec/azurerm_bot_channel_slack_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_channel_slack_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelSlackInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotChannelSlackInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelSlackInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelSlackInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotChannelSlackInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelSlackInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelSlackInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channels_registration_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_channels_registration_invalid_resource_group_name.go index 54e4b507..40480444 100644 --- a/rules/apispec/azurerm_bot_channels_registration_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_channels_registration_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelsRegistrationInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotChannelsRegistrationInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotChannelsRegistrationInvalidResourceGroupNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermBotChannelsRegistrationInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotChannelsRegistrationInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotChannelsRegistrationInvalidResourceGroupNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermBotChannelsRegistrationInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_channels_registration_invalid_sku.go b/rules/apispec/azurerm_bot_channels_registration_invalid_sku.go index 6691cc81..8521c8f0 100644 --- a/rules/apispec/azurerm_bot_channels_registration_invalid_sku.go +++ b/rules/apispec/azurerm_bot_channels_registration_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotChannelsRegistrationInvalidSkuRule checks the pattern is valid type AzurermBotChannelsRegistrationInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Severity() string { +func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermBotChannelsRegistrationInvalidSkuRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_connection_invalid_bot_name.go b/rules/apispec/azurerm_bot_connection_invalid_bot_name.go index af26a756..db2f9d7f 100644 --- a/rules/apispec/azurerm_bot_connection_invalid_bot_name.go +++ b/rules/apispec/azurerm_bot_connection_invalid_bot_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotConnectionInvalidBotNameRule checks the pattern is valid type AzurermBotConnectionInvalidBotNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotConnectionInvalidBotNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotConnectionInvalidBotNameRule) Severity() string { +func (r *AzurermBotConnectionInvalidBotNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotConnectionInvalidBotNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotConnectionInvalidBotNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_connection_invalid_name.go b/rules/apispec/azurerm_bot_connection_invalid_name.go index 7f20847d..6c29fb54 100644 --- a/rules/apispec/azurerm_bot_connection_invalid_name.go +++ b/rules/apispec/azurerm_bot_connection_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotConnectionInvalidNameRule checks the pattern is valid type AzurermBotConnectionInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotConnectionInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotConnectionInvalidNameRule) Severity() string { +func (r *AzurermBotConnectionInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotConnectionInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotConnectionInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][\sa-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_connection_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_connection_invalid_resource_group_name.go index 0eb1c101..6de79a2c 100644 --- a/rules/apispec/azurerm_bot_connection_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_connection_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotConnectionInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotConnectionInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotConnectionInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotConnectionInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotConnectionInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotConnectionInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotConnectionInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_web_app_invalid_name.go b/rules/apispec/azurerm_bot_web_app_invalid_name.go index 082fe09b..474a61da 100644 --- a/rules/apispec/azurerm_bot_web_app_invalid_name.go +++ b/rules/apispec/azurerm_bot_web_app_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotWebAppInvalidNameRule checks the pattern is valid type AzurermBotWebAppInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotWebAppInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotWebAppInvalidNameRule) Severity() string { +func (r *AzurermBotWebAppInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotWebAppInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotWebAppInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_web_app_invalid_resource_group_name.go b/rules/apispec/azurerm_bot_web_app_invalid_resource_group_name.go index 6669a361..6c3decaf 100644 --- a/rules/apispec/azurerm_bot_web_app_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_bot_web_app_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotWebAppInvalidResourceGroupNameRule checks the pattern is valid type AzurermBotWebAppInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermBotWebAppInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotWebAppInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermBotWebAppInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermBotWebAppInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotWebAppInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_bot_web_app_invalid_sku.go b/rules/apispec/azurerm_bot_web_app_invalid_sku.go index cc02bdfa..b48ae081 100644 --- a/rules/apispec/azurerm_bot_web_app_invalid_sku.go +++ b/rules/apispec/azurerm_bot_web_app_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermBotWebAppInvalidSkuRule checks the pattern is valid type AzurermBotWebAppInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermBotWebAppInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermBotWebAppInvalidSkuRule) Severity() string { +func (r *AzurermBotWebAppInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermBotWebAppInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermBotWebAppInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermBotWebAppInvalidSkuRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cdn_endpoint_invalid_optimization_type.go b/rules/apispec/azurerm_cdn_endpoint_invalid_optimization_type.go index b0da5e86..3981d945 100644 --- a/rules/apispec/azurerm_cdn_endpoint_invalid_optimization_type.go +++ b/rules/apispec/azurerm_cdn_endpoint_invalid_optimization_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCdnEndpointInvalidOptimizationTypeRule checks the pattern is valid type AzurermCdnEndpointInvalidOptimizationTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Severity() string { +func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermCdnEndpointInvalidOptimizationTypeRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as optimization_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cdn_endpoint_invalid_querystring_caching_behaviour.go b/rules/apispec/azurerm_cdn_endpoint_invalid_querystring_caching_behaviour.go index d881356f..805cda5f 100644 --- a/rules/apispec/azurerm_cdn_endpoint_invalid_querystring_caching_behaviour.go +++ b/rules/apispec/azurerm_cdn_endpoint_invalid_querystring_caching_behaviour.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule checks the pattern is valid type AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Severity() string { +func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Link() string // Check checks the pattern is valid func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermCdnEndpointInvalidQuerystringCachingBehaviourRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as querystring_caching_behaviour`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cdn_endpoint_invalid_resource_group_name.go b/rules/apispec/azurerm_cdn_endpoint_invalid_resource_group_name.go index 5a15283f..7c1e0b98 100644 --- a/rules/apispec/azurerm_cdn_endpoint_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cdn_endpoint_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCdnEndpointInvalidResourceGroupNameRule checks the pattern is valid type AzurermCdnEndpointInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCdnEndpointInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCdnEndpointInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCdnEndpointInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCdnEndpointInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCdnEndpointInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cdn_profile_invalid_resource_group_name.go b/rules/apispec/azurerm_cdn_profile_invalid_resource_group_name.go index f3e25893..ad599e36 100644 --- a/rules/apispec/azurerm_cdn_profile_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cdn_profile_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCdnProfileInvalidResourceGroupNameRule checks the pattern is valid type AzurermCdnProfileInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCdnProfileInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCdnProfileInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCdnProfileInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCdnProfileInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCdnProfileInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cdn_profile_invalid_sku.go b/rules/apispec/azurerm_cdn_profile_invalid_sku.go index 23f00624..898ae1f2 100644 --- a/rules/apispec/azurerm_cdn_profile_invalid_sku.go +++ b/rules/apispec/azurerm_cdn_profile_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCdnProfileInvalidSkuRule checks the pattern is valid type AzurermCdnProfileInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -52,7 +54,7 @@ func (r *AzurermCdnProfileInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCdnProfileInvalidSkuRule) Severity() string { +func (r *AzurermCdnProfileInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -63,11 +65,24 @@ func (r *AzurermCdnProfileInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermCdnProfileInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -75,13 +90,18 @@ func (r *AzurermCdnProfileInvalidSkuRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cognitive_account_invalid_name.go b/rules/apispec/azurerm_cognitive_account_invalid_name.go index 35b8319f..6c46d324 100644 --- a/rules/apispec/azurerm_cognitive_account_invalid_name.go +++ b/rules/apispec/azurerm_cognitive_account_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCognitiveAccountInvalidNameRule checks the pattern is valid type AzurermCognitiveAccountInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCognitiveAccountInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCognitiveAccountInvalidNameRule) Severity() string { +func (r *AzurermCognitiveAccountInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCognitiveAccountInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCognitiveAccountInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_group_invalid_ip_address_type.go b/rules/apispec/azurerm_container_group_invalid_ip_address_type.go index 0a9b659a..1b956077 100644 --- a/rules/apispec/azurerm_container_group_invalid_ip_address_type.go +++ b/rules/apispec/azurerm_container_group_invalid_ip_address_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerGroupInvalidIPAddressTypeRule checks the pattern is valid type AzurermContainerGroupInvalidIPAddressTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Severity() string { +func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermContainerGroupInvalidIPAddressTypeRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as ip_address_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_registry_invalid_name.go b/rules/apispec/azurerm_container_registry_invalid_name.go index dee7ecc3..9decd48e 100644 --- a/rules/apispec/azurerm_container_registry_invalid_name.go +++ b/rules/apispec/azurerm_container_registry_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerRegistryInvalidNameRule checks the pattern is valid type AzurermContainerRegistryInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermContainerRegistryInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermContainerRegistryInvalidNameRule) Severity() string { +func (r *AzurermContainerRegistryInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermContainerRegistryInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerRegistryInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_registry_invalid_sku.go b/rules/apispec/azurerm_container_registry_invalid_sku.go index d9b780cf..64018668 100644 --- a/rules/apispec/azurerm_container_registry_invalid_sku.go +++ b/rules/apispec/azurerm_container_registry_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerRegistryInvalidSkuRule checks the pattern is valid type AzurermContainerRegistryInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermContainerRegistryInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermContainerRegistryInvalidSkuRule) Severity() string { +func (r *AzurermContainerRegistryInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermContainerRegistryInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerRegistryInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermContainerRegistryInvalidSkuRule) Check(runner tflint.Runner) err } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_registry_webhook_invalid_name.go b/rules/apispec/azurerm_container_registry_webhook_invalid_name.go index 4a903380..b455b40f 100644 --- a/rules/apispec/azurerm_container_registry_webhook_invalid_name.go +++ b/rules/apispec/azurerm_container_registry_webhook_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerRegistryWebhookInvalidNameRule checks the pattern is valid type AzurermContainerRegistryWebhookInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermContainerRegistryWebhookInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermContainerRegistryWebhookInvalidNameRule) Severity() string { +func (r *AzurermContainerRegistryWebhookInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermContainerRegistryWebhookInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerRegistryWebhookInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_registry_webhook_invalid_registry_name.go b/rules/apispec/azurerm_container_registry_webhook_invalid_registry_name.go index 97125aad..c47cce81 100644 --- a/rules/apispec/azurerm_container_registry_webhook_invalid_registry_name.go +++ b/rules/apispec/azurerm_container_registry_webhook_invalid_registry_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerRegistryWebhookInvalidRegistryNameRule checks the pattern is valid type AzurermContainerRegistryWebhookInvalidRegistryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermContainerRegistryWebhookInvalidRegistryNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermContainerRegistryWebhookInvalidRegistryNameRule) Severity() string { +func (r *AzurermContainerRegistryWebhookInvalidRegistryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermContainerRegistryWebhookInvalidRegistryNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerRegistryWebhookInvalidRegistryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_container_registry_webhook_invalid_status.go b/rules/apispec/azurerm_container_registry_webhook_invalid_status.go index 3a5959d3..16eb51bb 100644 --- a/rules/apispec/azurerm_container_registry_webhook_invalid_status.go +++ b/rules/apispec/azurerm_container_registry_webhook_invalid_status.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermContainerRegistryWebhookInvalidStatusRule checks the pattern is valid type AzurermContainerRegistryWebhookInvalidStatusRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Severity() string { +func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Link() string { // Check checks the pattern is valid func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermContainerRegistryWebhookInvalidStatusRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as status`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_account_invalid_kind.go b/rules/apispec/azurerm_cosmosdb_account_invalid_kind.go index 807980fd..726a8019 100644 --- a/rules/apispec/azurerm_cosmosdb_account_invalid_kind.go +++ b/rules/apispec/azurerm_cosmosdb_account_invalid_kind.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbAccountInvalidKindRule checks the pattern is valid type AzurermCosmosdbAccountInvalidKindRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermCosmosdbAccountInvalidKindRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbAccountInvalidKindRule) Severity() string { +func (r *AzurermCosmosdbAccountInvalidKindRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermCosmosdbAccountInvalidKindRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbAccountInvalidKindRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermCosmosdbAccountInvalidKindRule) Check(runner tflint.Runner) erro } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as kind`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_account_invalid_name.go b/rules/apispec/azurerm_cosmosdb_account_invalid_name.go index 144b0776..9fa98099 100644 --- a/rules/apispec/azurerm_cosmosdb_account_invalid_name.go +++ b/rules/apispec/azurerm_cosmosdb_account_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbAccountInvalidNameRule checks the pattern is valid type AzurermCosmosdbAccountInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbAccountInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbAccountInvalidNameRule) Severity() string { +func (r *AzurermCosmosdbAccountInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbAccountInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbAccountInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_account_invalid_offer_type.go b/rules/apispec/azurerm_cosmosdb_account_invalid_offer_type.go index cd9ac866..162c5732 100644 --- a/rules/apispec/azurerm_cosmosdb_account_invalid_offer_type.go +++ b/rules/apispec/azurerm_cosmosdb_account_invalid_offer_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbAccountInvalidOfferTypeRule checks the pattern is valid type AzurermCosmosdbAccountInvalidOfferTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Severity() string { +func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermCosmosdbAccountInvalidOfferTypeRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as offer_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_account_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_account_invalid_resource_group_name.go index 734da70d..afdbd06d 100644 --- a/rules/apispec/azurerm_cosmosdb_account_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_account_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbAccountInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbAccountInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbAccountInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbAccountInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbAccountInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbAccountInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbAccountInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_account_name.go index 5f9c6c18..ed3df00e 100644 --- a/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbCassandraKeyspaceInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_resource_group_name.go index 900de12f..91a7e60e 100644 --- a/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_cassandra_keyspace_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule) Enabled() } // Severity returns the rule severity -func (r *AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule) Link() st // Check checks the pattern is valid func (r *AzurermCosmosdbCassandraKeyspaceInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_account_name.go index 1765fa16..82271a79 100644 --- a/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbGremlinDatabaseInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_resource_group_name.go index c94affa9..148359b9 100644 --- a/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_gremlin_database_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermCosmosdbGremlinDatabaseInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_account_name.go index 9d2567c7..f3e6f4ee 100644 --- a/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbGremlinGraphInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbGremlinGraphInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbGremlinGraphInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbGremlinGraphInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbGremlinGraphInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbGremlinGraphInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbGremlinGraphInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_resource_group_name.go index 3ffa3daf..3d09ffef 100644 --- a/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_gremlin_graph_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule) Link() string // Check checks the pattern is valid func (r *AzurermCosmosdbGremlinGraphInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_mongo_collection_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_mongo_collection_invalid_resource_group_name.go index 9ecd7db1..cb208e70 100644 --- a/rules/apispec/azurerm_cosmosdb_mongo_collection_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_mongo_collection_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermCosmosdbMongoCollectionInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_account_name.go index 10983a61..910173dd 100644 --- a/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbMongoDatabaseInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbMongoDatabaseInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbMongoDatabaseInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbMongoDatabaseInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbMongoDatabaseInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbMongoDatabaseInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbMongoDatabaseInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_resource_group_name.go index 5c9a0937..c1dc6222 100644 --- a/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_mongo_database_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule) Link() string // Check checks the pattern is valid func (r *AzurermCosmosdbMongoDatabaseInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_sql_container_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_sql_container_invalid_account_name.go index 228a8d2d..c76b599c 100644 --- a/rules/apispec/azurerm_cosmosdb_sql_container_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_sql_container_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbSQLContainerInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbSQLContainerInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbSQLContainerInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbSQLContainerInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbSQLContainerInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbSQLContainerInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbSQLContainerInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_sql_container_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_sql_container_invalid_resource_group_name.go index fe20da28..182a1d1e 100644 --- a/rules/apispec/azurerm_cosmosdb_sql_container_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_sql_container_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule) Link() string // Check checks the pattern is valid func (r *AzurermCosmosdbSQLContainerInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_sql_database_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_sql_database_invalid_account_name.go index f51e1e7f..d45ce288 100644 --- a/rules/apispec/azurerm_cosmosdb_sql_database_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_sql_database_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbSQLDatabaseInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbSQLDatabaseInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbSQLDatabaseInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbSQLDatabaseInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbSQLDatabaseInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbSQLDatabaseInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbSQLDatabaseInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_sql_database_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_sql_database_invalid_resource_group_name.go index 600c9f64..c141acb3 100644 --- a/rules/apispec/azurerm_cosmosdb_sql_database_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_sql_database_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbSQLDatabaseInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_table_invalid_account_name.go b/rules/apispec/azurerm_cosmosdb_table_invalid_account_name.go index e3d6f4db..e61b1ca3 100644 --- a/rules/apispec/azurerm_cosmosdb_table_invalid_account_name.go +++ b/rules/apispec/azurerm_cosmosdb_table_invalid_account_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbTableInvalidAccountNameRule checks the pattern is valid type AzurermCosmosdbTableInvalidAccountNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbTableInvalidAccountNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbTableInvalidAccountNameRule) Severity() string { +func (r *AzurermCosmosdbTableInvalidAccountNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbTableInvalidAccountNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbTableInvalidAccountNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-z0-9]+(-[a-z0-9]+)*`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cosmosdb_table_invalid_resource_group_name.go b/rules/apispec/azurerm_cosmosdb_table_invalid_resource_group_name.go index 36643131..4c831013 100644 --- a/rules/apispec/azurerm_cosmosdb_table_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_cosmosdb_table_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCosmosdbTableInvalidResourceGroupNameRule checks the pattern is valid type AzurermCosmosdbTableInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermCosmosdbTableInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermCosmosdbTableInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermCosmosdbTableInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermCosmosdbTableInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermCosmosdbTableInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_cost_management_export_resource_group_invalid_recurrence_type.go b/rules/apispec/azurerm_cost_management_export_resource_group_invalid_recurrence_type.go index 00baa991..f53aae29 100644 --- a/rules/apispec/azurerm_cost_management_export_resource_group_invalid_recurrence_type.go +++ b/rules/apispec/azurerm_cost_management_export_resource_group_invalid_recurrence_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule checks the pattern is valid type AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Enab } // Severity returns the rule severity -func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Severity() string { +func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Link // Check checks the pattern is valid func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermCostManagementExportResourceGroupInvalidRecurrenceTypeRule) Chec } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as recurrence_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_data_factory_name.go index 7f5e3608..864f1a07 100644 --- a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule) Link() string // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetMysqlInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_linked_service_name.go b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_linked_service_name.go index 9a251317..c7f14e49 100644 --- a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_linked_service_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_linked_service_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule checks the pattern is valid type AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetMysqlInvalidLinkedServiceNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_name.go b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_name.go index b45053f2..1f6b3c65 100644 --- a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetMysqlInvalidNameRule checks the pattern is valid type AzurermDataFactoryDatasetMysqlInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetMysqlInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetMysqlInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetMysqlInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_resource_group_name.go index 8592e8f6..5511a7c5 100644 --- a/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_mysql_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetMysqlInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_data_factory_name.go index 57ea9196..0c320f18 100644 --- a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule) Enabled( } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule) Link() s // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetPostgresqlInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_linked_service_name.go b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_linked_service_name.go index d0bed438..ace2ef8d 100644 --- a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_linked_service_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_linked_service_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule checks the pattern is valid type AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule) Enable } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule) Link() // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetPostgresqlInvalidLinkedServiceNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_name.go b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_name.go index a0a6c8ce..8a053f0a 100644 --- a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetPostgresqlInvalidNameRule checks the pattern is valid type AzurermDataFactoryDatasetPostgresqlInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetPostgresqlInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetPostgresqlInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetPostgresqlInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_resource_group_name.go index ea878fc4..54408ccb 100644 --- a/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_postgresql_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule) Enable } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule) Link() // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetPostgresqlInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_data_factory_name.go index c921c36c..63e7f743 100644 --- a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule) Enab } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule) Link // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetSQLServerTableInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_linked_service_name.go b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_linked_service_name.go index ed53e02e..56105c37 100644 --- a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_linked_service_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_linked_service_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule checks the pattern is valid type AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule) En } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule) Li // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetSQLServerTableInvalidLinkedServiceNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_name.go b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_name.go index dbf5ff7d..1b0a6bf9 100644 --- a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetSQLServerTableInvalidNameRule checks the pattern is valid type AzurermDataFactoryDatasetSQLServerTableInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetSQLServerTableInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetSQLServerTableInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetSQLServerTableInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_resource_group_name.go index cad6c6fc..0004f937 100644 --- a/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_dataset_sql_server_table_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule) En } // Severity returns the rule severity -func (r *AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule) Li // Check checks the pattern is valid func (r *AzurermDataFactoryDatasetSQLServerTableInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_edition.go b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_edition.go index dd2186df..584d6b45 100644 --- a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_edition.go +++ b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_edition.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule checks the pattern is valid type AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Enabled( } // Severity returns the rule severity -func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Severity() string { +func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Link() s // Check checks the pattern is valid func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidEditionRule) Check(ru } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as edition`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_license_type.go b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_license_type.go index d6851172..8a69766a 100644 --- a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_license_type.go +++ b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_license_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule checks the pattern is valid type AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Enab } // Severity returns the rule severity -func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Severity() string { +func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Link // Check checks the pattern is valid func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidLicenseTypeRule) Chec } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as license_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_max_parallel_executions_per_node.go b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_max_parallel_executions_per_node.go index eaa09e05..20f6352d 100644 --- a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_max_parallel_executions_per_node.go +++ b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_max_parallel_executions_per_node.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutionsPerNodeRule checks the pattern is valid type AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutionsPerNodeRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutions } // Severity returns the rule severity -func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutionsPerNodeRule) Severity() string { +func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutionsPerNodeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutions // Check checks the pattern is valid func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidMaxParallelExecutionsPerNodeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "max_parallel_executions_per_node must be 1 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_number_of_nodes.go b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_number_of_nodes.go index 7e4998a2..aa96c65f 100644 --- a/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_number_of_nodes.go +++ b/rules/apispec/azurerm_data_factory_integration_runtime_managed_invalid_number_of_nodes.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule checks the pattern is valid type AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule) En } // Severity returns the rule severity -func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule) Severity() string { +func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule) Li // Check checks the pattern is valid func (r *AzurermDataFactoryIntegrationRuntimeManagedInvalidNumberOfNodesRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "number_of_nodes must be 1 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_invalid_name.go b/rules/apispec/azurerm_data_factory_invalid_name.go index 96fda255..c028ad77 100644 --- a/rules/apispec/azurerm_data_factory_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryInvalidNameRule checks the pattern is valid type AzurermDataFactoryInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_invalid_resource_group_name.go index 50005f04..c2fb6044 100644 --- a/rules/apispec/azurerm_data_factory_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_data_factory_name.go index 2d978539..faf10b30 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNam } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNam // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_name.go b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_name.go index 559ad87e..d758f202 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule) Enab } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule) Link // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_resource_group_name.go index f50a5ad9..7bf0e969 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_data_lake_storage_gen2_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupN } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupN // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceDataLakeStorageGen2InvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_data_factory_name.go index a1990957..13a189b1 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule) Enabled } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule) Link() // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceMysqlInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_name.go b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_name.go index 6559fc01..d1772d2c 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceMysqlInvalidNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceMysqlInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceMysqlInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceMysqlInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceMysqlInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_resource_group_name.go index 892870b7..b1d34489 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_mysql_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule) Enabl } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule) Link( // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceMysqlInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_data_factory_name.go index a5707422..bd803a9f 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule) En } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule) Li // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_name.go b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_name.go index f8b081ba..71600404 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule checks the pattern is valid type AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule) Link() string // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_resource_group_name.go index 3d1ef231..9f2eb9f8 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_postgresql_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule) } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule) // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServicePostgresqlInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_data_factory_name.go index 014dc86c..a43849a5 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule) Ena } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule) Lin // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_name.go b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_name.go index b64b0515..e737a05e 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule) Link() string // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_resource_group_name.go index b97a65a3..4066c8ae 100644 --- a/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_linked_service_sql_server_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule) E } // Severity returns the rule severity -func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule) L // Check checks the pattern is valid func (r *AzurermDataFactoryLinkedServiceSQLServerInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_pipeline_invalid_data_factory_name.go b/rules/apispec/azurerm_data_factory_pipeline_invalid_data_factory_name.go index cf024f5a..cbd066d3 100644 --- a/rules/apispec/azurerm_data_factory_pipeline_invalid_data_factory_name.go +++ b/rules/apispec/azurerm_data_factory_pipeline_invalid_data_factory_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryPipelineInvalidDataFactoryNameRule checks the pattern is valid type AzurermDataFactoryPipelineInvalidDataFactoryNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryPipelineInvalidDataFactoryNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryPipelineInvalidDataFactoryNameRule) Severity() string { +func (r *AzurermDataFactoryPipelineInvalidDataFactoryNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryPipelineInvalidDataFactoryNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryPipelineInvalidDataFactoryNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_pipeline_invalid_name.go b/rules/apispec/azurerm_data_factory_pipeline_invalid_name.go index d7c68694..e3481e35 100644 --- a/rules/apispec/azurerm_data_factory_pipeline_invalid_name.go +++ b/rules/apispec/azurerm_data_factory_pipeline_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryPipelineInvalidNameRule checks the pattern is valid type AzurermDataFactoryPipelineInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryPipelineInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryPipelineInvalidNameRule) Severity() string { +func (r *AzurermDataFactoryPipelineInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryPipelineInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryPipelineInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_pipeline_invalid_resource_group_name.go b/rules/apispec/azurerm_data_factory_pipeline_invalid_resource_group_name.go index a7546f3f..ec2574e4 100644 --- a/rules/apispec/azurerm_data_factory_pipeline_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_data_factory_pipeline_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryPipelineInvalidResourceGroupNameRule checks the pattern is valid type AzurermDataFactoryPipelineInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDataFactoryPipelineInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermDataFactoryPipelineInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDataFactoryPipelineInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDataFactoryPipelineInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryPipelineInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_factory_trigger_schedule_invalid_frequency.go b/rules/apispec/azurerm_data_factory_trigger_schedule_invalid_frequency.go index 2561b772..770d1338 100644 --- a/rules/apispec/azurerm_data_factory_trigger_schedule_invalid_frequency.go +++ b/rules/apispec/azurerm_data_factory_trigger_schedule_invalid_frequency.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataFactoryTriggerScheduleInvalidFrequencyRule checks the pattern is valid type AzurermDataFactoryTriggerScheduleInvalidFrequencyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Severity() string { +func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermDataFactoryTriggerScheduleInvalidFrequencyRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as frequency`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_analytics_account_invalid_tier.go b/rules/apispec/azurerm_data_lake_analytics_account_invalid_tier.go index b883c5cc..326127ea 100644 --- a/rules/apispec/azurerm_data_lake_analytics_account_invalid_tier.go +++ b/rules/apispec/azurerm_data_lake_analytics_account_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeAnalyticsAccountInvalidTierRule checks the pattern is valid type AzurermDataLakeAnalyticsAccountInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -47,7 +49,7 @@ func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Severity() string { +func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -58,11 +60,24 @@ func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -70,13 +85,18 @@ func (r *AzurermDataLakeAnalyticsAccountInvalidTierRule) Check(runner tflint.Run } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_store_invalid_encryption_state.go b/rules/apispec/azurerm_data_lake_store_invalid_encryption_state.go index 9e64acd5..87fb1534 100644 --- a/rules/apispec/azurerm_data_lake_store_invalid_encryption_state.go +++ b/rules/apispec/azurerm_data_lake_store_invalid_encryption_state.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeStoreInvalidEncryptionStateRule checks the pattern is valid type AzurermDataLakeStoreInvalidEncryptionStateRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Severity() string { +func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataLakeStoreInvalidEncryptionStateRule) Check(runner tflint.Run } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as encryption_state`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_store_invalid_encryption_type.go b/rules/apispec/azurerm_data_lake_store_invalid_encryption_type.go index 09b243a2..85c4b6cf 100644 --- a/rules/apispec/azurerm_data_lake_store_invalid_encryption_type.go +++ b/rules/apispec/azurerm_data_lake_store_invalid_encryption_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeStoreInvalidEncryptionTypeRule checks the pattern is valid type AzurermDataLakeStoreInvalidEncryptionTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Severity() string { +func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataLakeStoreInvalidEncryptionTypeRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as encryption_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_store_invalid_firewall_allow_azure_ips.go b/rules/apispec/azurerm_data_lake_store_invalid_firewall_allow_azure_ips.go index 660f7529..7ef7811e 100644 --- a/rules/apispec/azurerm_data_lake_store_invalid_firewall_allow_azure_ips.go +++ b/rules/apispec/azurerm_data_lake_store_invalid_firewall_allow_azure_ips.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule checks the pattern is valid type AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Severity() string { +func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataLakeStoreInvalidFirewallAllowAzureIpsRule) Check(runner tfli } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as firewall_allow_azure_ips`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_store_invalid_firewall_state.go b/rules/apispec/azurerm_data_lake_store_invalid_firewall_state.go index 3cb84012..7987a875 100644 --- a/rules/apispec/azurerm_data_lake_store_invalid_firewall_state.go +++ b/rules/apispec/azurerm_data_lake_store_invalid_firewall_state.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeStoreInvalidFirewallStateRule checks the pattern is valid type AzurermDataLakeStoreInvalidFirewallStateRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Severity() string { +func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDataLakeStoreInvalidFirewallStateRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as firewall_state`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_data_lake_store_invalid_tier.go b/rules/apispec/azurerm_data_lake_store_invalid_tier.go index 8f2f6d1e..b76a2d8f 100644 --- a/rules/apispec/azurerm_data_lake_store_invalid_tier.go +++ b/rules/apispec/azurerm_data_lake_store_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDataLakeStoreInvalidTierRule checks the pattern is valid type AzurermDataLakeStoreInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermDataLakeStoreInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDataLakeStoreInvalidTierRule) Severity() string { +func (r *AzurermDataLakeStoreInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermDataLakeStoreInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermDataLakeStoreInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermDataLakeStoreInvalidTierRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_database_migration_project_invalid_source_platform.go b/rules/apispec/azurerm_database_migration_project_invalid_source_platform.go index 7d439e6c..50874fa2 100644 --- a/rules/apispec/azurerm_database_migration_project_invalid_source_platform.go +++ b/rules/apispec/azurerm_database_migration_project_invalid_source_platform.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDatabaseMigrationProjectInvalidSourcePlatformRule checks the pattern is valid type AzurermDatabaseMigrationProjectInvalidSourcePlatformRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Severity() string { +func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Link() string // Check checks the pattern is valid func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDatabaseMigrationProjectInvalidSourcePlatformRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as source_platform`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_database_migration_project_invalid_target_platform.go b/rules/apispec/azurerm_database_migration_project_invalid_target_platform.go index 7c719796..c1418204 100644 --- a/rules/apispec/azurerm_database_migration_project_invalid_target_platform.go +++ b/rules/apispec/azurerm_database_migration_project_invalid_target_platform.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDatabaseMigrationProjectInvalidTargetPlatformRule checks the pattern is valid type AzurermDatabaseMigrationProjectInvalidTargetPlatformRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Severity() string { +func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Link() string // Check checks the pattern is valid func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDatabaseMigrationProjectInvalidTargetPlatformRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as target_platform`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_databricks_workspace_invalid_managed_resource_group_name.go b/rules/apispec/azurerm_databricks_workspace_invalid_managed_resource_group_name.go index a2d9363f..678e43ee 100644 --- a/rules/apispec/azurerm_databricks_workspace_invalid_managed_resource_group_name.go +++ b/rules/apispec/azurerm_databricks_workspace_invalid_managed_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule checks the pattern is valid type AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule) Enabled( } // Severity returns the rule severity -func (r *AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule) Severity() string { +func (r *AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule) Link() s // Check checks the pattern is valid func (r *AzurermDatabricksWorkspaceInvalidManagedResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_databricks_workspace_invalid_resource_group_name.go b/rules/apispec/azurerm_databricks_workspace_invalid_resource_group_name.go index c1b19bb3..3af83b6d 100644 --- a/rules/apispec/azurerm_databricks_workspace_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_databricks_workspace_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDatabricksWorkspaceInvalidResourceGroupNameRule checks the pattern is valid type AzurermDatabricksWorkspaceInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDatabricksWorkspaceInvalidResourceGroupNameRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermDatabricksWorkspaceInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermDatabricksWorkspaceInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDatabricksWorkspaceInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDatabricksWorkspaceInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dedicated_host_group_invalid_platform_fault_domain_count.go b/rules/apispec/azurerm_dedicated_host_group_invalid_platform_fault_domain_count.go index d9d6407a..7082c8da 100644 --- a/rules/apispec/azurerm_dedicated_host_group_invalid_platform_fault_domain_count.go +++ b/rules/apispec/azurerm_dedicated_host_group_invalid_platform_fault_domain_count.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule checks the pattern is valid type AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule) Enabled() } // Severity returns the rule severity -func (r *AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule) Severity() string { +func (r *AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule) Link() st // Check checks the pattern is valid func (r *AzurermDedicatedHostGroupInvalidPlatformFaultDomainCountRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "platform_fault_domain_count must be 1 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dedicated_host_invalid_license_type.go b/rules/apispec/azurerm_dedicated_host_invalid_license_type.go index 86eb63b5..344f6d97 100644 --- a/rules/apispec/azurerm_dedicated_host_invalid_license_type.go +++ b/rules/apispec/azurerm_dedicated_host_invalid_license_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDedicatedHostInvalidLicenseTypeRule checks the pattern is valid type AzurermDedicatedHostInvalidLicenseTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Severity() string { +func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermDedicatedHostInvalidLicenseTypeRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as license_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dedicated_host_invalid_platform_fault_domain.go b/rules/apispec/azurerm_dedicated_host_invalid_platform_fault_domain.go index 1a072742..eaf097ae 100644 --- a/rules/apispec/azurerm_dedicated_host_invalid_platform_fault_domain.go +++ b/rules/apispec/azurerm_dedicated_host_invalid_platform_fault_domain.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDedicatedHostInvalidPlatformFaultDomainRule checks the pattern is valid type AzurermDedicatedHostInvalidPlatformFaultDomainRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermDedicatedHostInvalidPlatformFaultDomainRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDedicatedHostInvalidPlatformFaultDomainRule) Severity() string { +func (r *AzurermDedicatedHostInvalidPlatformFaultDomainRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermDedicatedHostInvalidPlatformFaultDomainRule) Link() string { // Check checks the pattern is valid func (r *AzurermDedicatedHostInvalidPlatformFaultDomainRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "platform_fault_domain must be 0 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dev_test_policy_invalid_evaluator_type.go b/rules/apispec/azurerm_dev_test_policy_invalid_evaluator_type.go index cd26b1b2..b3d2e1bc 100644 --- a/rules/apispec/azurerm_dev_test_policy_invalid_evaluator_type.go +++ b/rules/apispec/azurerm_dev_test_policy_invalid_evaluator_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDevTestPolicyInvalidEvaluatorTypeRule checks the pattern is valid type AzurermDevTestPolicyInvalidEvaluatorTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Severity() string { +func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDevTestPolicyInvalidEvaluatorTypeRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as evaluator_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dev_test_policy_invalid_name.go b/rules/apispec/azurerm_dev_test_policy_invalid_name.go index 3b1c8bdd..86865bd5 100644 --- a/rules/apispec/azurerm_dev_test_policy_invalid_name.go +++ b/rules/apispec/azurerm_dev_test_policy_invalid_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDevTestPolicyInvalidNameRule checks the pattern is valid type AzurermDevTestPolicyInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -48,7 +50,7 @@ func (r *AzurermDevTestPolicyInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDevTestPolicyInvalidNameRule) Severity() string { +func (r *AzurermDevTestPolicyInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -59,11 +61,24 @@ func (r *AzurermDevTestPolicyInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDevTestPolicyInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -71,13 +86,18 @@ func (r *AzurermDevTestPolicyInvalidNameRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_dev_test_schedule_invalid_status.go b/rules/apispec/azurerm_dev_test_schedule_invalid_status.go index de805f94..b47460b2 100644 --- a/rules/apispec/azurerm_dev_test_schedule_invalid_status.go +++ b/rules/apispec/azurerm_dev_test_schedule_invalid_status.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDevTestScheduleInvalidStatusRule checks the pattern is valid type AzurermDevTestScheduleInvalidStatusRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermDevTestScheduleInvalidStatusRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDevTestScheduleInvalidStatusRule) Severity() string { +func (r *AzurermDevTestScheduleInvalidStatusRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermDevTestScheduleInvalidStatusRule) Link() string { // Check checks the pattern is valid func (r *AzurermDevTestScheduleInvalidStatusRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermDevTestScheduleInvalidStatusRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as status`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_devspace_controller_invalid_name.go b/rules/apispec/azurerm_devspace_controller_invalid_name.go index 98bc7f51..b02b1786 100644 --- a/rules/apispec/azurerm_devspace_controller_invalid_name.go +++ b/rules/apispec/azurerm_devspace_controller_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDevspaceControllerInvalidNameRule checks the pattern is valid type AzurermDevspaceControllerInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermDevspaceControllerInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDevspaceControllerInvalidNameRule) Severity() string { +func (r *AzurermDevspaceControllerInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermDevspaceControllerInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDevspaceControllerInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]([_-]*[a-zA-Z0-9])*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_devspace_controller_invalid_sku_name.go b/rules/apispec/azurerm_devspace_controller_invalid_sku_name.go index a9f7e9a5..2559e9ea 100644 --- a/rules/apispec/azurerm_devspace_controller_invalid_sku_name.go +++ b/rules/apispec/azurerm_devspace_controller_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermDevspaceControllerInvalidSkuNameRule checks the pattern is valid type AzurermDevspaceControllerInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermDevspaceControllerInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermDevspaceControllerInvalidSkuNameRule) Severity() string { +func (r *AzurermDevspaceControllerInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermDevspaceControllerInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermDevspaceControllerInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermDevspaceControllerInvalidSkuNameRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_eventgrid_domain_invalid_input_schema.go b/rules/apispec/azurerm_eventgrid_domain_invalid_input_schema.go index 1e22517e..aedb94bb 100644 --- a/rules/apispec/azurerm_eventgrid_domain_invalid_input_schema.go +++ b/rules/apispec/azurerm_eventgrid_domain_invalid_input_schema.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermEventgridDomainInvalidInputSchemaRule checks the pattern is valid type AzurermEventgridDomainInvalidInputSchemaRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermEventgridDomainInvalidInputSchemaRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermEventgridDomainInvalidInputSchemaRule) Severity() string { +func (r *AzurermEventgridDomainInvalidInputSchemaRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermEventgridDomainInvalidInputSchemaRule) Link() string { // Check checks the pattern is valid func (r *AzurermEventgridDomainInvalidInputSchemaRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermEventgridDomainInvalidInputSchemaRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as input_schema`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_eventgrid_event_subscription_invalid_event_delivery_schema.go b/rules/apispec/azurerm_eventgrid_event_subscription_invalid_event_delivery_schema.go index fd5b6b53..9d8ca495 100644 --- a/rules/apispec/azurerm_eventgrid_event_subscription_invalid_event_delivery_schema.go +++ b/rules/apispec/azurerm_eventgrid_event_subscription_invalid_event_delivery_schema.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule checks the pattern is valid type AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Enable } // Severity returns the rule severity -func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Severity() string { +func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Link() // Check checks the pattern is valid func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermEventgridEventSubscriptionInvalidEventDeliverySchemaRule) Check( } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as event_delivery_schema`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_eventhub_namespace_invalid_capacity.go b/rules/apispec/azurerm_eventhub_namespace_invalid_capacity.go index 4a77b711..e78331e3 100644 --- a/rules/apispec/azurerm_eventhub_namespace_invalid_capacity.go +++ b/rules/apispec/azurerm_eventhub_namespace_invalid_capacity.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermEventhubNamespaceInvalidCapacityRule checks the pattern is valid type AzurermEventhubNamespaceInvalidCapacityRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermEventhubNamespaceInvalidCapacityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermEventhubNamespaceInvalidCapacityRule) Severity() string { +func (r *AzurermEventhubNamespaceInvalidCapacityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermEventhubNamespaceInvalidCapacityRule) Link() string { // Check checks the pattern is valid func (r *AzurermEventhubNamespaceInvalidCapacityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "capacity must be 0 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_eventhub_namespace_invalid_sku.go b/rules/apispec/azurerm_eventhub_namespace_invalid_sku.go index e80b690b..38e4f2f5 100644 --- a/rules/apispec/azurerm_eventhub_namespace_invalid_sku.go +++ b/rules/apispec/azurerm_eventhub_namespace_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermEventhubNamespaceInvalidSkuRule checks the pattern is valid type AzurermEventhubNamespaceInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermEventhubNamespaceInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermEventhubNamespaceInvalidSkuRule) Severity() string { +func (r *AzurermEventhubNamespaceInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermEventhubNamespaceInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermEventhubNamespaceInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermEventhubNamespaceInvalidSkuRule) Check(runner tflint.Runner) err } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_express_route_circuit_peering_invalid_peering_type.go b/rules/apispec/azurerm_express_route_circuit_peering_invalid_peering_type.go index 0ee46841..0ac0f04e 100644 --- a/rules/apispec/azurerm_express_route_circuit_peering_invalid_peering_type.go +++ b/rules/apispec/azurerm_express_route_circuit_peering_invalid_peering_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule checks the pattern is valid type AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Severity() string { +func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Link() string // Check checks the pattern is valid func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermExpressRouteCircuitPeeringInvalidPeeringTypeRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as peering_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_application_rule_collection_invalid_action.go b/rules/apispec/azurerm_firewall_application_rule_collection_invalid_action.go index bf76fb2d..38577481 100644 --- a/rules/apispec/azurerm_firewall_application_rule_collection_invalid_action.go +++ b/rules/apispec/azurerm_firewall_application_rule_collection_invalid_action.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallApplicationRuleCollectionInvalidActionRule checks the pattern is valid type AzurermFirewallApplicationRuleCollectionInvalidActionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Enabled() bo } // Severity returns the rule severity -func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Severity() string { +func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Link() strin // Check checks the pattern is valid func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermFirewallApplicationRuleCollectionInvalidActionRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as action`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_application_rule_collection_invalid_priority.go b/rules/apispec/azurerm_firewall_application_rule_collection_invalid_priority.go index 2412dcaf..aeb400e8 100644 --- a/rules/apispec/azurerm_firewall_application_rule_collection_invalid_priority.go +++ b/rules/apispec/azurerm_firewall_application_rule_collection_invalid_priority.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallApplicationRuleCollectionInvalidPriorityRule checks the pattern is valid type AzurermFirewallApplicationRuleCollectionInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermFirewallApplicationRuleCollectionInvalidPriorityRule) Enabled() } // Severity returns the rule severity -func (r *AzurermFirewallApplicationRuleCollectionInvalidPriorityRule) Severity() string { +func (r *AzurermFirewallApplicationRuleCollectionInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermFirewallApplicationRuleCollectionInvalidPriorityRule) Link() str // Check checks the pattern is valid func (r *AzurermFirewallApplicationRuleCollectionInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 65000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 100 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_action.go b/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_action.go index 50e0b570..d5e07bbe 100644 --- a/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_action.go +++ b/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_action.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallNatRuleCollectionInvalidActionRule checks the pattern is valid type AzurermFirewallNatRuleCollectionInvalidActionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Severity() string { +func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Link() string { // Check checks the pattern is valid func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermFirewallNatRuleCollectionInvalidActionRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as action`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_priority.go b/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_priority.go index 47f232a3..28c15f93 100644 --- a/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_priority.go +++ b/rules/apispec/azurerm_firewall_nat_rule_collection_invalid_priority.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallNatRuleCollectionInvalidPriorityRule checks the pattern is valid type AzurermFirewallNatRuleCollectionInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermFirewallNatRuleCollectionInvalidPriorityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFirewallNatRuleCollectionInvalidPriorityRule) Severity() string { +func (r *AzurermFirewallNatRuleCollectionInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermFirewallNatRuleCollectionInvalidPriorityRule) Link() string { // Check checks the pattern is valid func (r *AzurermFirewallNatRuleCollectionInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 65000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 100 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_network_rule_collection_invalid_action.go b/rules/apispec/azurerm_firewall_network_rule_collection_invalid_action.go index 4b908190..4f066213 100644 --- a/rules/apispec/azurerm_firewall_network_rule_collection_invalid_action.go +++ b/rules/apispec/azurerm_firewall_network_rule_collection_invalid_action.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallNetworkRuleCollectionInvalidActionRule checks the pattern is valid type AzurermFirewallNetworkRuleCollectionInvalidActionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Severity() string { +func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Link() string { // Check checks the pattern is valid func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermFirewallNetworkRuleCollectionInvalidActionRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as action`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_firewall_network_rule_collection_invalid_priority.go b/rules/apispec/azurerm_firewall_network_rule_collection_invalid_priority.go index 71284128..efc83d87 100644 --- a/rules/apispec/azurerm_firewall_network_rule_collection_invalid_priority.go +++ b/rules/apispec/azurerm_firewall_network_rule_collection_invalid_priority.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFirewallNetworkRuleCollectionInvalidPriorityRule checks the pattern is valid type AzurermFirewallNetworkRuleCollectionInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermFirewallNetworkRuleCollectionInvalidPriorityRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermFirewallNetworkRuleCollectionInvalidPriorityRule) Severity() string { +func (r *AzurermFirewallNetworkRuleCollectionInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermFirewallNetworkRuleCollectionInvalidPriorityRule) Link() string // Check checks the pattern is valid func (r *AzurermFirewallNetworkRuleCollectionInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 65000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "priority must be 100 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_custom_block_response_body.go b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_custom_block_response_body.go index a0e4fc91..4df640ab 100644 --- a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_custom_block_response_body.go +++ b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_custom_block_response_body.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule checks the pattern is valid type AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule) Enabl } // Severity returns the rule severity -func (r *AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule) Severity() string { +func (r *AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule) Link( // Check checks the pattern is valid func (r *AzurermFrontdoorFirewallPolicyInvalidCustomBlockResponseBodyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_mode.go b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_mode.go index 03ee8594..66ab73e1 100644 --- a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_mode.go +++ b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorFirewallPolicyInvalidModeRule checks the pattern is valid type AzurermFrontdoorFirewallPolicyInvalidModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Severity() string { +func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Link() string { // Check checks the pattern is valid func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidModeRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_resource_group_name.go b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_resource_group_name.go index 26b338ff..5c47c72e 100644 --- a/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_frontdoor_firewall_policy_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule checks the pattern is valid type AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule) Link() stri // Check checks the pattern is valid func (r *AzurermFrontdoorFirewallPolicyInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9_\-\(\)\.]*[^\.]$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_invalid_backend_pools_send_receive_timeout_seconds.go b/rules/apispec/azurerm_frontdoor_invalid_backend_pools_send_receive_timeout_seconds.go index b01bcc23..c811f162 100644 --- a/rules/apispec/azurerm_frontdoor_invalid_backend_pools_send_receive_timeout_seconds.go +++ b/rules/apispec/azurerm_frontdoor_invalid_backend_pools_send_receive_timeout_seconds.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule checks the pattern is valid type AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule struct { + tflint.DefaultRule + resourceType string attributeName string min int @@ -36,7 +38,7 @@ func (r *AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule) Enabl } // Severity returns the rule severity -func (r *AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule) Severity() string { +func (r *AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule) Severity() tflint.Severity { return tflint.ERROR } @@ -47,19 +49,37 @@ func (r *AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule) Link( // Check checks the pattern is valid func (r *AzurermFrontdoorInvalidBackendPoolsSendReceiveTimeoutSecondsRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "backend_pools_send_receive_timeout_seconds must be 16 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_invalid_name.go b/rules/apispec/azurerm_frontdoor_invalid_name.go index dfe7d986..bac5dbca 100644 --- a/rules/apispec/azurerm_frontdoor_invalid_name.go +++ b/rules/apispec/azurerm_frontdoor_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorInvalidNameRule checks the pattern is valid type AzurermFrontdoorInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermFrontdoorInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFrontdoorInvalidNameRule) Severity() string { +func (r *AzurermFrontdoorInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermFrontdoorInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermFrontdoorInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]+([-a-zA-Z0-9]?[a-zA-Z0-9])*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_frontdoor_invalid_resource_group_name.go b/rules/apispec/azurerm_frontdoor_invalid_resource_group_name.go index 90a79763..30aae83b 100644 --- a/rules/apispec/azurerm_frontdoor_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_frontdoor_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermFrontdoorInvalidResourceGroupNameRule checks the pattern is valid type AzurermFrontdoorInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermFrontdoorInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermFrontdoorInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermFrontdoorInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermFrontdoorInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermFrontdoorInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9_\-\(\)\.]*[^\.]$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_hadoop_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_hadoop_cluster_invalid_tier.go index 6a458287..f45a4297 100644 --- a/rules/apispec/azurerm_hdinsight_hadoop_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_hadoop_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightHadoopClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightHadoopClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightHadoopClusterInvalidTierRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_hbase_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_hbase_cluster_invalid_tier.go index 749b7283..83523f91 100644 --- a/rules/apispec/azurerm_hdinsight_hbase_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_hbase_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightHbaseClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightHbaseClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightHbaseClusterInvalidTierRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_interactive_query_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_interactive_query_cluster_invalid_tier.go index b33be8d8..22feb061 100644 --- a/rules/apispec/azurerm_hdinsight_interactive_query_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_interactive_query_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightInteractiveQueryClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightInteractiveQueryClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightInteractiveQueryClusterInvalidTierRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_kafka_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_kafka_cluster_invalid_tier.go index 9af8ba31..6272f802 100644 --- a/rules/apispec/azurerm_hdinsight_kafka_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_kafka_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightKafkaClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightKafkaClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightKafkaClusterInvalidTierRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_ml_services_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_ml_services_cluster_invalid_tier.go index c375190b..1545cb53 100644 --- a/rules/apispec/azurerm_hdinsight_ml_services_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_ml_services_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightMlServicesClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightMlServicesClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightMlServicesClusterInvalidTierRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_rserver_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_rserver_cluster_invalid_tier.go index 4b860855..057aaf08 100644 --- a/rules/apispec/azurerm_hdinsight_rserver_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_rserver_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightRserverClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightRserverClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightRserverClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightRserverClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightRserverClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightRserverClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightRserverClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightRserverClusterInvalidTierRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_spark_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_spark_cluster_invalid_tier.go index 24d45294..aa97a3af 100644 --- a/rules/apispec/azurerm_hdinsight_spark_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_spark_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightSparkClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightSparkClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightSparkClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightSparkClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightSparkClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightSparkClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightSparkClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightSparkClusterInvalidTierRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hdinsight_storm_cluster_invalid_tier.go b/rules/apispec/azurerm_hdinsight_storm_cluster_invalid_tier.go index 720c26bf..5f24e538 100644 --- a/rules/apispec/azurerm_hdinsight_storm_cluster_invalid_tier.go +++ b/rules/apispec/azurerm_hdinsight_storm_cluster_invalid_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHdinsightStormClusterInvalidTierRule checks the pattern is valid type AzurermHdinsightStormClusterInvalidTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermHdinsightStormClusterInvalidTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHdinsightStormClusterInvalidTierRule) Severity() string { +func (r *AzurermHdinsightStormClusterInvalidTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermHdinsightStormClusterInvalidTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermHdinsightStormClusterInvalidTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermHdinsightStormClusterInvalidTierRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_healthcare_service_invalid_cosmosdb_throughput.go b/rules/apispec/azurerm_healthcare_service_invalid_cosmosdb_throughput.go index b28e23c9..6330af1f 100644 --- a/rules/apispec/azurerm_healthcare_service_invalid_cosmosdb_throughput.go +++ b/rules/apispec/azurerm_healthcare_service_invalid_cosmosdb_throughput.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHealthcareServiceInvalidCosmosdbThroughputRule checks the pattern is valid type AzurermHealthcareServiceInvalidCosmosdbThroughputRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermHealthcareServiceInvalidCosmosdbThroughputRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHealthcareServiceInvalidCosmosdbThroughputRule) Severity() string { +func (r *AzurermHealthcareServiceInvalidCosmosdbThroughputRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermHealthcareServiceInvalidCosmosdbThroughputRule) Link() string { // Check checks the pattern is valid func (r *AzurermHealthcareServiceInvalidCosmosdbThroughputRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "cosmosdb_throughput must be 10000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "cosmosdb_throughput must be 400 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_healthcare_service_invalid_kind.go b/rules/apispec/azurerm_healthcare_service_invalid_kind.go index cf88c384..e6aa3792 100644 --- a/rules/apispec/azurerm_healthcare_service_invalid_kind.go +++ b/rules/apispec/azurerm_healthcare_service_invalid_kind.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHealthcareServiceInvalidKindRule checks the pattern is valid type AzurermHealthcareServiceInvalidKindRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermHealthcareServiceInvalidKindRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHealthcareServiceInvalidKindRule) Severity() string { +func (r *AzurermHealthcareServiceInvalidKindRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermHealthcareServiceInvalidKindRule) Link() string { // Check checks the pattern is valid func (r *AzurermHealthcareServiceInvalidKindRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermHealthcareServiceInvalidKindRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as kind`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_healthcare_service_invalid_resource_group_name.go b/rules/apispec/azurerm_healthcare_service_invalid_resource_group_name.go index fdfa287b..17283ed3 100644 --- a/rules/apispec/azurerm_healthcare_service_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_healthcare_service_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHealthcareServiceInvalidResourceGroupNameRule checks the pattern is valid type AzurermHealthcareServiceInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermHealthcareServiceInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHealthcareServiceInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermHealthcareServiceInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermHealthcareServiceInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermHealthcareServiceInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_hpc_cache_invalid_name.go b/rules/apispec/azurerm_hpc_cache_invalid_name.go index 5be16a44..46c980f2 100644 --- a/rules/apispec/azurerm_hpc_cache_invalid_name.go +++ b/rules/apispec/azurerm_hpc_cache_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermHpcCacheInvalidNameRule checks the pattern is valid type AzurermHpcCacheInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermHpcCacheInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermHpcCacheInvalidNameRule) Severity() string { +func (r *AzurermHpcCacheInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermHpcCacheInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermHpcCacheInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-0-9a-zA-Z_]{1,80}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_image_invalid_hyper_v_generation.go b/rules/apispec/azurerm_image_invalid_hyper_v_generation.go index 569d69b0..ad6a251c 100644 --- a/rules/apispec/azurerm_image_invalid_hyper_v_generation.go +++ b/rules/apispec/azurerm_image_invalid_hyper_v_generation.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermImageInvalidHyperVGenerationRule checks the pattern is valid type AzurermImageInvalidHyperVGenerationRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermImageInvalidHyperVGenerationRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermImageInvalidHyperVGenerationRule) Severity() string { +func (r *AzurermImageInvalidHyperVGenerationRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermImageInvalidHyperVGenerationRule) Link() string { // Check checks the pattern is valid func (r *AzurermImageInvalidHyperVGenerationRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermImageInvalidHyperVGenerationRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as hyper_v_generation`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iotcentral_application_invalid_sku.go b/rules/apispec/azurerm_iotcentral_application_invalid_sku.go index 2fb8d762..262faa15 100644 --- a/rules/apispec/azurerm_iotcentral_application_invalid_sku.go +++ b/rules/apispec/azurerm_iotcentral_application_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIotcentralApplicationInvalidSkuRule checks the pattern is valid type AzurermIotcentralApplicationInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermIotcentralApplicationInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermIotcentralApplicationInvalidSkuRule) Severity() string { +func (r *AzurermIotcentralApplicationInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermIotcentralApplicationInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermIotcentralApplicationInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermIotcentralApplicationInvalidSkuRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_batch_frequency_in_seconds.go b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_batch_frequency_in_seconds.go index d3c44464..c92c7947 100644 --- a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_batch_frequency_in_seconds.go +++ b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_batch_frequency_in_seconds.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule checks the pattern is valid type AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule } // Severity returns the rule severity -func (r *AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule) Severity() string { +func (r *AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule // Check checks the pattern is valid func (r *AzurermIothubEndpointStorageContainerInvalidBatchFrequencyInSecondsRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "batch_frequency_in_seconds must be 720 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "batch_frequency_in_seconds must be 60 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_encoding.go b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_encoding.go index d6ab52bf..f7b26803 100644 --- a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_encoding.go +++ b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_encoding.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubEndpointStorageContainerInvalidEncodingRule checks the pattern is valid type AzurermIothubEndpointStorageContainerInvalidEncodingRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Severity() string { +func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Link() string // Check checks the pattern is valid func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermIothubEndpointStorageContainerInvalidEncodingRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as encoding`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_max_chunk_size_in_bytes.go b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_max_chunk_size_in_bytes.go index 780d2ec5..8e584f1c 100644 --- a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_max_chunk_size_in_bytes.go +++ b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_max_chunk_size_in_bytes.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule checks the pattern is valid type AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule) En } // Severity returns the rule severity -func (r *AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule) Severity() string { +func (r *AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule) Li // Check checks the pattern is valid func (r *AzurermIothubEndpointStorageContainerInvalidMaxChunkSizeInBytesRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "max_chunk_size_in_bytes must be 524288000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "max_chunk_size_in_bytes must be 10485760 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_name.go b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_name.go index d0a61916..86b90fe1 100644 --- a/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_name.go +++ b/rules/apispec/azurerm_iothub_endpoint_storage_container_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubEndpointStorageContainerInvalidNameRule checks the pattern is valid type AzurermIothubEndpointStorageContainerInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermIothubEndpointStorageContainerInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermIothubEndpointStorageContainerInvalidNameRule) Severity() string { +func (r *AzurermIothubEndpointStorageContainerInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermIothubEndpointStorageContainerInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermIothubEndpointStorageContainerInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9-._]{1,64}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_route_invalid_name.go b/rules/apispec/azurerm_iothub_route_invalid_name.go index 3f666d84..f2ba83ee 100644 --- a/rules/apispec/azurerm_iothub_route_invalid_name.go +++ b/rules/apispec/azurerm_iothub_route_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubRouteInvalidNameRule checks the pattern is valid type AzurermIothubRouteInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermIothubRouteInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermIothubRouteInvalidNameRule) Severity() string { +func (r *AzurermIothubRouteInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermIothubRouteInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermIothubRouteInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[A-Za-z0-9-._]{1,64}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_iothub_route_invalid_source.go b/rules/apispec/azurerm_iothub_route_invalid_source.go index 77485db5..d954c78f 100644 --- a/rules/apispec/azurerm_iothub_route_invalid_source.go +++ b/rules/apispec/azurerm_iothub_route_invalid_source.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermIothubRouteInvalidSourceRule checks the pattern is valid type AzurermIothubRouteInvalidSourceRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermIothubRouteInvalidSourceRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermIothubRouteInvalidSourceRule) Severity() string { +func (r *AzurermIothubRouteInvalidSourceRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermIothubRouteInvalidSourceRule) Link() string { // Check checks the pattern is valid func (r *AzurermIothubRouteInvalidSourceRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermIothubRouteInvalidSourceRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as source`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_key_vault_invalid_name.go b/rules/apispec/azurerm_key_vault_invalid_name.go index f30a869e..09876315 100644 --- a/rules/apispec/azurerm_key_vault_invalid_name.go +++ b/rules/apispec/azurerm_key_vault_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKeyVaultInvalidNameRule checks the pattern is valid type AzurermKeyVaultInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermKeyVaultInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKeyVaultInvalidNameRule) Severity() string { +func (r *AzurermKeyVaultInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermKeyVaultInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermKeyVaultInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9-]{3,24}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_key_vault_invalid_sku_name.go b/rules/apispec/azurerm_key_vault_invalid_sku_name.go index f6ce5e68..63d5f608 100644 --- a/rules/apispec/azurerm_key_vault_invalid_sku_name.go +++ b/rules/apispec/azurerm_key_vault_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKeyVaultInvalidSkuNameRule checks the pattern is valid type AzurermKeyVaultInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermKeyVaultInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKeyVaultInvalidSkuNameRule) Severity() string { +func (r *AzurermKeyVaultInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermKeyVaultInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermKeyVaultInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermKeyVaultInvalidSkuNameRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_key_vault_key_invalid_curve.go b/rules/apispec/azurerm_key_vault_key_invalid_curve.go index d7b30cc0..80b15087 100644 --- a/rules/apispec/azurerm_key_vault_key_invalid_curve.go +++ b/rules/apispec/azurerm_key_vault_key_invalid_curve.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKeyVaultKeyInvalidCurveRule checks the pattern is valid type AzurermKeyVaultKeyInvalidCurveRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermKeyVaultKeyInvalidCurveRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKeyVaultKeyInvalidCurveRule) Severity() string { +func (r *AzurermKeyVaultKeyInvalidCurveRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermKeyVaultKeyInvalidCurveRule) Link() string { // Check checks the pattern is valid func (r *AzurermKeyVaultKeyInvalidCurveRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermKeyVaultKeyInvalidCurveRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as curve`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_key_vault_key_invalid_key_type.go b/rules/apispec/azurerm_key_vault_key_invalid_key_type.go index 1eb5d9b7..d5151106 100644 --- a/rules/apispec/azurerm_key_vault_key_invalid_key_type.go +++ b/rules/apispec/azurerm_key_vault_key_invalid_key_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKeyVaultKeyInvalidKeyTypeRule checks the pattern is valid type AzurermKeyVaultKeyInvalidKeyTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Severity() string { +func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermKeyVaultKeyInvalidKeyTypeRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as key_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kubernetes_cluster_default_node_pool_invalid_vm_size.go b/rules/apispec/azurerm_kubernetes_cluster_default_node_pool_invalid_vm_size.go index 5970712f..b5b9a6a5 100644 --- a/rules/apispec/azurerm_kubernetes_cluster_default_node_pool_invalid_vm_size.go +++ b/rules/apispec/azurerm_kubernetes_cluster_default_node_pool_invalid_vm_size.go @@ -3,13 +3,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule checks the pattern is valid type AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule struct { + tflint.DefaultRule + resourceType string blockType string attributeName string @@ -212,7 +214,7 @@ func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Severity() string { +func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -223,21 +225,32 @@ func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Link() string // Check checks whether ... func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceBlocks(r.resourceType, r.blockType, func(block *hcl.Block) error { - content, _, diags := block.Body.PartialContent(&hcl.BodySchema{ - Attributes: []hcl.AttributeSchema{ - {Name: r.attributeName}, + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Blocks: []hclext.BlockSchema{ + { + Type: r.blockType, + Body: &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, }, - }) - if diags.HasErrors() { - return diags - } + }, + }, nil) + if err != nil { + return err + } - if attribute, exists := content.Attributes[r.attributeName]; exists { + for _, resource := range resources.Blocks { + for _, inner := range resource.Body.Blocks { + attribute, exists := inner.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -245,16 +258,19 @@ func (r *AzurermKubernetesClusterDefaultNodePoolInvalidVMSizeRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as vm_size`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) + if err != nil { + return err + } } + } - return nil - }) + return nil } diff --git a/rules/apispec/azurerm_kubernetes_cluster_invalid_name.go b/rules/apispec/azurerm_kubernetes_cluster_invalid_name.go index 7314c8ef..4cb3abc3 100644 --- a/rules/apispec/azurerm_kubernetes_cluster_invalid_name.go +++ b/rules/apispec/azurerm_kubernetes_cluster_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKubernetesClusterInvalidNameRule checks the pattern is valid type AzurermKubernetesClusterInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermKubernetesClusterInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKubernetesClusterInvalidNameRule) Severity() string { +func (r *AzurermKubernetesClusterInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermKubernetesClusterInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermKubernetesClusterInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_disk_size_gb.go b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_disk_size_gb.go index 9b559c67..1df9c9b8 100644 --- a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_disk_size_gb.go +++ b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_disk_size_gb.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule checks the pattern is valid type AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule) Severity() string { +func (r *AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule) Link() string // Check checks the pattern is valid func (r *AzurermKubernetesClusterNodePoolInvalidOSDiskSizeGbRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "os_disk_size_gb must be 2048 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "os_disk_size_gb must be 0 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_type.go b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_type.go index 1935ee5b..c47dada5 100644 --- a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_type.go +++ b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_os_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKubernetesClusterNodePoolInvalidOSTypeRule checks the pattern is valid type AzurermKubernetesClusterNodePoolInvalidOSTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Severity() string { +func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermKubernetesClusterNodePoolInvalidOSTypeRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as os_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_vm_size.go b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_vm_size.go index 411f4142..9c60a0d9 100644 --- a/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_vm_size.go +++ b/rules/apispec/azurerm_kubernetes_cluster_node_pool_invalid_vm_size.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKubernetesClusterNodePoolInvalidVMSizeRule checks the pattern is valid type AzurermKubernetesClusterNodePoolInvalidVMSizeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -212,7 +214,7 @@ func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Severity() string { +func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -223,11 +225,24 @@ func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Link() string { // Check checks the pattern is valid func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -235,13 +250,18 @@ func (r *AzurermKubernetesClusterNodePoolInvalidVMSizeRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as vm_size`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kusto_database_principal_invalid_role.go b/rules/apispec/azurerm_kusto_database_principal_invalid_role.go index c094042b..7336506e 100644 --- a/rules/apispec/azurerm_kusto_database_principal_invalid_role.go +++ b/rules/apispec/azurerm_kusto_database_principal_invalid_role.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKustoDatabasePrincipalInvalidRoleRule checks the pattern is valid type AzurermKustoDatabasePrincipalInvalidRoleRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Severity() string { +func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Link() string { // Check checks the pattern is valid func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermKustoDatabasePrincipalInvalidRoleRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as role`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kusto_database_principal_invalid_type.go b/rules/apispec/azurerm_kusto_database_principal_invalid_type.go index ebde5f72..4a6da25c 100644 --- a/rules/apispec/azurerm_kusto_database_principal_invalid_type.go +++ b/rules/apispec/azurerm_kusto_database_principal_invalid_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKustoDatabasePrincipalInvalidTypeRule checks the pattern is valid type AzurermKustoDatabasePrincipalInvalidTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Severity() string { +func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermKustoDatabasePrincipalInvalidTypeRule) Check(runner tflint.Runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_kusto_eventhub_data_connection_invalid_data_format.go b/rules/apispec/azurerm_kusto_eventhub_data_connection_invalid_data_format.go index 7517f943..69f44c18 100644 --- a/rules/apispec/azurerm_kusto_eventhub_data_connection_invalid_data_format.go +++ b/rules/apispec/azurerm_kusto_eventhub_data_connection_invalid_data_format.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermKustoEventhubDataConnectionInvalidDataFormatRule checks the pattern is valid type AzurermKustoEventhubDataConnectionInvalidDataFormatRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -54,7 +56,7 @@ func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Severity() string { +func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Severity() tflint.Severity { return tflint.ERROR } @@ -65,11 +67,24 @@ func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Link() string // Check checks the pattern is valid func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -77,13 +92,18 @@ func (r *AzurermKustoEventhubDataConnectionInvalidDataFormatRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as data_format`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_invalid_sku.go b/rules/apispec/azurerm_lb_invalid_sku.go index 0ed58108..03509259 100644 --- a/rules/apispec/azurerm_lb_invalid_sku.go +++ b/rules/apispec/azurerm_lb_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbInvalidSkuRule checks the pattern is valid type AzurermLbInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbInvalidSkuRule) Severity() string { +func (r *AzurermLbInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbInvalidSkuRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_nat_pool_invalid_protocol.go b/rules/apispec/azurerm_lb_nat_pool_invalid_protocol.go index 93fb9dd7..f478f338 100644 --- a/rules/apispec/azurerm_lb_nat_pool_invalid_protocol.go +++ b/rules/apispec/azurerm_lb_nat_pool_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbNatPoolInvalidProtocolRule checks the pattern is valid type AzurermLbNatPoolInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbNatPoolInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbNatPoolInvalidProtocolRule) Severity() string { +func (r *AzurermLbNatPoolInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbNatPoolInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbNatPoolInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbNatPoolInvalidProtocolRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_nat_rule_invalid_protocol.go b/rules/apispec/azurerm_lb_nat_rule_invalid_protocol.go index 2842e989..091046ee 100644 --- a/rules/apispec/azurerm_lb_nat_rule_invalid_protocol.go +++ b/rules/apispec/azurerm_lb_nat_rule_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbNatRuleInvalidProtocolRule checks the pattern is valid type AzurermLbNatRuleInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbNatRuleInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbNatRuleInvalidProtocolRule) Severity() string { +func (r *AzurermLbNatRuleInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbNatRuleInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbNatRuleInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbNatRuleInvalidProtocolRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_outbound_rule_invalid_protocol.go b/rules/apispec/azurerm_lb_outbound_rule_invalid_protocol.go index e9ca9c57..9a00365f 100644 --- a/rules/apispec/azurerm_lb_outbound_rule_invalid_protocol.go +++ b/rules/apispec/azurerm_lb_outbound_rule_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbOutboundRuleInvalidProtocolRule checks the pattern is valid type AzurermLbOutboundRuleInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbOutboundRuleInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbOutboundRuleInvalidProtocolRule) Severity() string { +func (r *AzurermLbOutboundRuleInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbOutboundRuleInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbOutboundRuleInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbOutboundRuleInvalidProtocolRule) Check(runner tflint.Runner) e } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_probe_invalid_protocol.go b/rules/apispec/azurerm_lb_probe_invalid_protocol.go index ac153271..34b7d98f 100644 --- a/rules/apispec/azurerm_lb_probe_invalid_protocol.go +++ b/rules/apispec/azurerm_lb_probe_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbProbeInvalidProtocolRule checks the pattern is valid type AzurermLbProbeInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbProbeInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbProbeInvalidProtocolRule) Severity() string { +func (r *AzurermLbProbeInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbProbeInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbProbeInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbProbeInvalidProtocolRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_rule_invalid_load_distribution.go b/rules/apispec/azurerm_lb_rule_invalid_load_distribution.go index 9289ee36..c3a9922c 100644 --- a/rules/apispec/azurerm_lb_rule_invalid_load_distribution.go +++ b/rules/apispec/azurerm_lb_rule_invalid_load_distribution.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbRuleInvalidLoadDistributionRule checks the pattern is valid type AzurermLbRuleInvalidLoadDistributionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbRuleInvalidLoadDistributionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbRuleInvalidLoadDistributionRule) Severity() string { +func (r *AzurermLbRuleInvalidLoadDistributionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbRuleInvalidLoadDistributionRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbRuleInvalidLoadDistributionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbRuleInvalidLoadDistributionRule) Check(runner tflint.Runner) e } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as load_distribution`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_lb_rule_invalid_protocol.go b/rules/apispec/azurerm_lb_rule_invalid_protocol.go index 9da4529f..54c70772 100644 --- a/rules/apispec/azurerm_lb_rule_invalid_protocol.go +++ b/rules/apispec/azurerm_lb_rule_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLbRuleInvalidProtocolRule checks the pattern is valid type AzurermLbRuleInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLbRuleInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLbRuleInvalidProtocolRule) Severity() string { +func (r *AzurermLbRuleInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLbRuleInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermLbRuleInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLbRuleInvalidProtocolRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_linux_virtual_machine_invalid_eviction_policy.go b/rules/apispec/azurerm_linux_virtual_machine_invalid_eviction_policy.go index dcf655d9..eac136fa 100644 --- a/rules/apispec/azurerm_linux_virtual_machine_invalid_eviction_policy.go +++ b/rules/apispec/azurerm_linux_virtual_machine_invalid_eviction_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineInvalidEvictionPolicyRule checks the pattern is valid type AzurermLinuxVirtualMachineInvalidEvictionPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Severity() string { +func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Link() string { // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermLinuxVirtualMachineInvalidEvictionPolicyRule) Check(runner tflin } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as eviction_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_linux_virtual_machine_invalid_priority.go b/rules/apispec/azurerm_linux_virtual_machine_invalid_priority.go index 979dcc00..4429b2ca 100644 --- a/rules/apispec/azurerm_linux_virtual_machine_invalid_priority.go +++ b/rules/apispec/azurerm_linux_virtual_machine_invalid_priority.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineInvalidPriorityRule checks the pattern is valid type AzurermLinuxVirtualMachineInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Severity() string { +func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Link() string { // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLinuxVirtualMachineInvalidPriorityRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as priority`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_eviction_policy.go b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_eviction_policy.go index b6af0353..a6b02140 100644 --- a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_eviction_policy.go +++ b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_eviction_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule checks the pattern is valid type AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Enabled() } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() string { +func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Link() str // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as eviction_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_priority.go b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_priority.go index 34ddb5fd..57e91d5f 100644 --- a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_priority.go +++ b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_priority.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule checks the pattern is valid type AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Severity() string { +func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Link() string { // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidPriorityRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as priority`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_upgrade_mode.go b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_upgrade_mode.go index 63c547a8..e76b2d59 100644 --- a/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_upgrade_mode.go +++ b/rules/apispec/azurerm_linux_virtual_machine_scale_set_invalid_upgrade_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule checks the pattern is valid type AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Severity() string { +func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Link() string // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidUpgradeModeRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as upgrade_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_logic_app_trigger_recurrence_invalid_frequency.go b/rules/apispec/azurerm_logic_app_trigger_recurrence_invalid_frequency.go index 30a3d434..eef6257e 100644 --- a/rules/apispec/azurerm_logic_app_trigger_recurrence_invalid_frequency.go +++ b/rules/apispec/azurerm_logic_app_trigger_recurrence_invalid_frequency.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule checks the pattern is valid type AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -46,7 +48,7 @@ func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Severity() string { +func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -57,11 +59,24 @@ func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Link() string { // Check checks the pattern is valid func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -69,13 +84,18 @@ func (r *AzurermLogicAppTriggerRecurrenceInvalidFrequencyRule) Check(runner tfli } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as frequency`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_maintenance_configuration_invalid_scope.go b/rules/apispec/azurerm_maintenance_configuration_invalid_scope.go index c67b7019..caa219cc 100644 --- a/rules/apispec/azurerm_maintenance_configuration_invalid_scope.go +++ b/rules/apispec/azurerm_maintenance_configuration_invalid_scope.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMaintenanceConfigurationInvalidScopeRule checks the pattern is valid type AzurermMaintenanceConfigurationInvalidScopeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Severity() string { +func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Link() string { // Check checks the pattern is valid func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermMaintenanceConfigurationInvalidScopeRule) Check(runner tflint.Ru } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as scope`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_managed_application_definition_invalid_lock_level.go b/rules/apispec/azurerm_managed_application_definition_invalid_lock_level.go index a77695af..c8517476 100644 --- a/rules/apispec/azurerm_managed_application_definition_invalid_lock_level.go +++ b/rules/apispec/azurerm_managed_application_definition_invalid_lock_level.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermManagedApplicationDefinitionInvalidLockLevelRule checks the pattern is valid type AzurermManagedApplicationDefinitionInvalidLockLevelRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Severity() string { +func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Link() string // Check checks the pattern is valid func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermManagedApplicationDefinitionInvalidLockLevelRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as lock_level`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_managed_disk_invalid_create_option.go b/rules/apispec/azurerm_managed_disk_invalid_create_option.go index ecdc89a4..011826e0 100644 --- a/rules/apispec/azurerm_managed_disk_invalid_create_option.go +++ b/rules/apispec/azurerm_managed_disk_invalid_create_option.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermManagedDiskInvalidCreateOptionRule checks the pattern is valid type AzurermManagedDiskInvalidCreateOptionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermManagedDiskInvalidCreateOptionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermManagedDiskInvalidCreateOptionRule) Severity() string { +func (r *AzurermManagedDiskInvalidCreateOptionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermManagedDiskInvalidCreateOptionRule) Link() string { // Check checks the pattern is valid func (r *AzurermManagedDiskInvalidCreateOptionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermManagedDiskInvalidCreateOptionRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as create_option`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_managed_disk_invalid_os_type.go b/rules/apispec/azurerm_managed_disk_invalid_os_type.go index cdd8c8c7..ff3cfc2c 100644 --- a/rules/apispec/azurerm_managed_disk_invalid_os_type.go +++ b/rules/apispec/azurerm_managed_disk_invalid_os_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermManagedDiskInvalidOSTypeRule checks the pattern is valid type AzurermManagedDiskInvalidOSTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermManagedDiskInvalidOSTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermManagedDiskInvalidOSTypeRule) Severity() string { +func (r *AzurermManagedDiskInvalidOSTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermManagedDiskInvalidOSTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermManagedDiskInvalidOSTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermManagedDiskInvalidOSTypeRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as os_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_managed_disk_invalid_storage_account_type.go b/rules/apispec/azurerm_managed_disk_invalid_storage_account_type.go index b8b9398b..195767b4 100644 --- a/rules/apispec/azurerm_managed_disk_invalid_storage_account_type.go +++ b/rules/apispec/azurerm_managed_disk_invalid_storage_account_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermManagedDiskInvalidStorageAccountTypeRule checks the pattern is valid type AzurermManagedDiskInvalidStorageAccountTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Severity() string { +func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermManagedDiskInvalidStorageAccountTypeRule) Check(runner tflint.Ru } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as storage_account_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_maps_account_invalid_sku_name.go b/rules/apispec/azurerm_maps_account_invalid_sku_name.go index f716e57a..f9e3717c 100644 --- a/rules/apispec/azurerm_maps_account_invalid_sku_name.go +++ b/rules/apispec/azurerm_maps_account_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMapsAccountInvalidSkuNameRule checks the pattern is valid type AzurermMapsAccountInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermMapsAccountInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMapsAccountInvalidSkuNameRule) Severity() string { +func (r *AzurermMapsAccountInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermMapsAccountInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermMapsAccountInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermMapsAccountInvalidSkuNameRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mariadb_firewall_rule_invalid_end_ip_address.go b/rules/apispec/azurerm_mariadb_firewall_rule_invalid_end_ip_address.go index 096f8654..06eab2de 100644 --- a/rules/apispec/azurerm_mariadb_firewall_rule_invalid_end_ip_address.go +++ b/rules/apispec/azurerm_mariadb_firewall_rule_invalid_end_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMariadbFirewallRuleInvalidEndIPAddressRule checks the pattern is valid type AzurermMariadbFirewallRuleInvalidEndIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermMariadbFirewallRuleInvalidEndIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMariadbFirewallRuleInvalidEndIPAddressRule) Severity() string { +func (r *AzurermMariadbFirewallRuleInvalidEndIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermMariadbFirewallRuleInvalidEndIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermMariadbFirewallRuleInvalidEndIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mariadb_firewall_rule_invalid_start_ip_address.go b/rules/apispec/azurerm_mariadb_firewall_rule_invalid_start_ip_address.go index fdd30884..890aacc5 100644 --- a/rules/apispec/azurerm_mariadb_firewall_rule_invalid_start_ip_address.go +++ b/rules/apispec/azurerm_mariadb_firewall_rule_invalid_start_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMariadbFirewallRuleInvalidStartIPAddressRule checks the pattern is valid type AzurermMariadbFirewallRuleInvalidStartIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermMariadbFirewallRuleInvalidStartIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMariadbFirewallRuleInvalidStartIPAddressRule) Severity() string { +func (r *AzurermMariadbFirewallRuleInvalidStartIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermMariadbFirewallRuleInvalidStartIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermMariadbFirewallRuleInvalidStartIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mariadb_server_invalid_ssl_enforcement.go b/rules/apispec/azurerm_mariadb_server_invalid_ssl_enforcement.go index 15f5efe2..1eccec1b 100644 --- a/rules/apispec/azurerm_mariadb_server_invalid_ssl_enforcement.go +++ b/rules/apispec/azurerm_mariadb_server_invalid_ssl_enforcement.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMariadbServerInvalidSslEnforcementRule checks the pattern is valid type AzurermMariadbServerInvalidSslEnforcementRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermMariadbServerInvalidSslEnforcementRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMariadbServerInvalidSslEnforcementRule) Severity() string { +func (r *AzurermMariadbServerInvalidSslEnforcementRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermMariadbServerInvalidSslEnforcementRule) Link() string { // Check checks the pattern is valid func (r *AzurermMariadbServerInvalidSslEnforcementRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermMariadbServerInvalidSslEnforcementRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as ssl_enforcement`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mariadb_server_invalid_version.go b/rules/apispec/azurerm_mariadb_server_invalid_version.go index 9707436b..806d818b 100644 --- a/rules/apispec/azurerm_mariadb_server_invalid_version.go +++ b/rules/apispec/azurerm_mariadb_server_invalid_version.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMariadbServerInvalidVersionRule checks the pattern is valid type AzurermMariadbServerInvalidVersionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermMariadbServerInvalidVersionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMariadbServerInvalidVersionRule) Severity() string { +func (r *AzurermMariadbServerInvalidVersionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermMariadbServerInvalidVersionRule) Link() string { // Check checks the pattern is valid func (r *AzurermMariadbServerInvalidVersionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermMariadbServerInvalidVersionRule) Check(runner tflint.Runner) err } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as version`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_monitor_scheduled_query_rules_alert_invalid_severity.go b/rules/apispec/azurerm_monitor_scheduled_query_rules_alert_invalid_severity.go index 9a620d2a..e9642801 100644 --- a/rules/apispec/azurerm_monitor_scheduled_query_rules_alert_invalid_severity.go +++ b/rules/apispec/azurerm_monitor_scheduled_query_rules_alert_invalid_severity.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule checks the pattern is valid type AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Enabled() bo } // Severity returns the rule severity -func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Severity() string { +func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Link() strin // Check checks the pattern is valid func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermMonitorScheduledQueryRulesAlertInvalidSeverityRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as severity`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_connectivity_type.go b/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_connectivity_type.go index 13c92db7..72eca438 100644 --- a/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_connectivity_type.go +++ b/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_connectivity_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule checks the pattern is valid type AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Enabled() boo } // Severity returns the rule severity -func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Severity() string { +func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Link() string // Check checks the pattern is valid func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLConnectivityTypeRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sql_connectivity_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_license_type.go b/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_license_type.go index d68c6b77..2d45625d 100644 --- a/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_license_type.go +++ b/rules/apispec/azurerm_mssql_virtual_machine_invalid_sql_license_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule checks the pattern is valid type AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Severity() string { +func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermMssqlVirtualMachineInvalidSQLLicenseTypeRule) Check(runner tflin } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sql_license_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mysql_firewall_rule_invalid_end_ip_address.go b/rules/apispec/azurerm_mysql_firewall_rule_invalid_end_ip_address.go index 0dd788c5..ef1a562b 100644 --- a/rules/apispec/azurerm_mysql_firewall_rule_invalid_end_ip_address.go +++ b/rules/apispec/azurerm_mysql_firewall_rule_invalid_end_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMysqlFirewallRuleInvalidEndIPAddressRule checks the pattern is valid type AzurermMysqlFirewallRuleInvalidEndIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermMysqlFirewallRuleInvalidEndIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMysqlFirewallRuleInvalidEndIPAddressRule) Severity() string { +func (r *AzurermMysqlFirewallRuleInvalidEndIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermMysqlFirewallRuleInvalidEndIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermMysqlFirewallRuleInvalidEndIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mysql_firewall_rule_invalid_start_ip_address.go b/rules/apispec/azurerm_mysql_firewall_rule_invalid_start_ip_address.go index 5a23b673..5b4a4b96 100644 --- a/rules/apispec/azurerm_mysql_firewall_rule_invalid_start_ip_address.go +++ b/rules/apispec/azurerm_mysql_firewall_rule_invalid_start_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMysqlFirewallRuleInvalidStartIPAddressRule checks the pattern is valid type AzurermMysqlFirewallRuleInvalidStartIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermMysqlFirewallRuleInvalidStartIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMysqlFirewallRuleInvalidStartIPAddressRule) Severity() string { +func (r *AzurermMysqlFirewallRuleInvalidStartIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermMysqlFirewallRuleInvalidStartIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermMysqlFirewallRuleInvalidStartIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_mysql_server_invalid_ssl_enforcement.go b/rules/apispec/azurerm_mysql_server_invalid_ssl_enforcement.go deleted file mode 100644 index f4936436..00000000 --- a/rules/apispec/azurerm_mysql_server_invalid_ssl_enforcement.go +++ /dev/null @@ -1,75 +0,0 @@ -// This file generated by `tools/apispec-rule-gen/main.go`. DO NOT EDIT - -package apispec - -import ( - "fmt" - - hcl "github.com/hashicorp/hcl/v2" - "github.com/terraform-linters/tflint-plugin-sdk/tflint" - "github.com/terraform-linters/tflint-ruleset-azurerm/project" -) - -// AzurermMysqlServerInvalidSslEnforcementRule checks the pattern is valid -type AzurermMysqlServerInvalidSslEnforcementRule struct { - resourceType string - attributeName string - enum []string -} - -// NewAzurermMysqlServerInvalidSslEnforcementRule returns new rule with default attributes -func NewAzurermMysqlServerInvalidSslEnforcementRule() *AzurermMysqlServerInvalidSslEnforcementRule { - return &AzurermMysqlServerInvalidSslEnforcementRule{ - resourceType: "azurerm_mysql_server", - attributeName: "ssl_enforcement", - enum: []string{ - "Enabled", - "Disabled", - }, - } -} - -// Name returns the rule name -func (r *AzurermMysqlServerInvalidSslEnforcementRule) Name() string { - return "azurerm_mysql_server_invalid_ssl_enforcement" -} - -// Enabled returns whether the rule is enabled by default -func (r *AzurermMysqlServerInvalidSslEnforcementRule) Enabled() bool { - return true -} - -// Severity returns the rule severity -func (r *AzurermMysqlServerInvalidSslEnforcementRule) Severity() string { - return tflint.ERROR -} - -// Link returns the rule reference link -func (r *AzurermMysqlServerInvalidSslEnforcementRule) Link() string { - return project.ReferenceLink(r.Name()) -} - -// Check checks the pattern is valid -func (r *AzurermMysqlServerInvalidSslEnforcementRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { - var val string - err := runner.EvaluateExpr(attribute.Expr, &val, nil) - - return runner.EnsureNoError(err, func() error { - found := false - for _, item := range r.enum { - if item == val { - found = true - } - } - if !found { - runner.EmitIssueOnExpr( - r, - fmt.Sprintf(`"%s" is an invalid value as ssl_enforcement`, truncateLongMessage(val)), - attribute.Expr, - ) - } - return nil - }) - }) -} diff --git a/rules/apispec/azurerm_mysql_server_invalid_version.go b/rules/apispec/azurerm_mysql_server_invalid_version.go index eb628425..bdf90c95 100644 --- a/rules/apispec/azurerm_mysql_server_invalid_version.go +++ b/rules/apispec/azurerm_mysql_server_invalid_version.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermMysqlServerInvalidVersionRule checks the pattern is valid type AzurermMysqlServerInvalidVersionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermMysqlServerInvalidVersionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermMysqlServerInvalidVersionRule) Severity() string { +func (r *AzurermMysqlServerInvalidVersionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermMysqlServerInvalidVersionRule) Link() string { // Check checks the pattern is valid func (r *AzurermMysqlServerInvalidVersionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermMysqlServerInvalidVersionRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as version`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_nat_gateway_invalid_sku_name.go b/rules/apispec/azurerm_nat_gateway_invalid_sku_name.go index 4c98a5f4..d57c2bf2 100644 --- a/rules/apispec/azurerm_nat_gateway_invalid_sku_name.go +++ b/rules/apispec/azurerm_nat_gateway_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNatGatewayInvalidSkuNameRule checks the pattern is valid type AzurermNatGatewayInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermNatGatewayInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNatGatewayInvalidSkuNameRule) Severity() string { +func (r *AzurermNatGatewayInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermNatGatewayInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNatGatewayInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermNatGatewayInvalidSkuNameRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_account_invalid_resource_group_name.go b/rules/apispec/azurerm_netapp_account_invalid_resource_group_name.go index cd657dd0..69b26742 100644 --- a/rules/apispec/azurerm_netapp_account_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_netapp_account_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappAccountInvalidResourceGroupNameRule checks the pattern is valid type AzurermNetappAccountInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappAccountInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappAccountInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermNetappAccountInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappAccountInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappAccountInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_pool_invalid_name.go b/rules/apispec/azurerm_netapp_pool_invalid_name.go index cf770beb..4d954568 100644 --- a/rules/apispec/azurerm_netapp_pool_invalid_name.go +++ b/rules/apispec/azurerm_netapp_pool_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappPoolInvalidNameRule checks the pattern is valid type AzurermNetappPoolInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappPoolInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappPoolInvalidNameRule) Severity() string { +func (r *AzurermNetappPoolInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappPoolInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappPoolInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9\-_]{0,63}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_pool_invalid_resource_group_name.go b/rules/apispec/azurerm_netapp_pool_invalid_resource_group_name.go index 96b0f705..890e596c 100644 --- a/rules/apispec/azurerm_netapp_pool_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_netapp_pool_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappPoolInvalidResourceGroupNameRule checks the pattern is valid type AzurermNetappPoolInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappPoolInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappPoolInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermNetappPoolInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappPoolInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappPoolInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_pool_invalid_service_level.go b/rules/apispec/azurerm_netapp_pool_invalid_service_level.go index 26ef3e87..6a994b9f 100644 --- a/rules/apispec/azurerm_netapp_pool_invalid_service_level.go +++ b/rules/apispec/azurerm_netapp_pool_invalid_service_level.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappPoolInvalidServiceLevelRule checks the pattern is valid type AzurermNetappPoolInvalidServiceLevelRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermNetappPoolInvalidServiceLevelRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappPoolInvalidServiceLevelRule) Severity() string { +func (r *AzurermNetappPoolInvalidServiceLevelRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermNetappPoolInvalidServiceLevelRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappPoolInvalidServiceLevelRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermNetappPoolInvalidServiceLevelRule) Check(runner tflint.Runner) e } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as service_level`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_snapshot_invalid_resource_group_name.go b/rules/apispec/azurerm_netapp_snapshot_invalid_resource_group_name.go index 79005e64..062610e4 100644 --- a/rules/apispec/azurerm_netapp_snapshot_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_netapp_snapshot_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappSnapshotInvalidResourceGroupNameRule checks the pattern is valid type AzurermNetappSnapshotInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappSnapshotInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappSnapshotInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermNetappSnapshotInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappSnapshotInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappSnapshotInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_volume_invalid_name.go b/rules/apispec/azurerm_netapp_volume_invalid_name.go index 7e743a8a..fa867111 100644 --- a/rules/apispec/azurerm_netapp_volume_invalid_name.go +++ b/rules/apispec/azurerm_netapp_volume_invalid_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappVolumeInvalidNameRule checks the pattern is valid type AzurermNetappVolumeInvalidNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappVolumeInvalidNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappVolumeInvalidNameRule) Severity() string { +func (r *AzurermNetappVolumeInvalidNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappVolumeInvalidNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappVolumeInvalidNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z][a-zA-Z0-9\-_]{0,63}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_volume_invalid_pool_name.go b/rules/apispec/azurerm_netapp_volume_invalid_pool_name.go index fae6d5bf..c49f17fc 100644 --- a/rules/apispec/azurerm_netapp_volume_invalid_pool_name.go +++ b/rules/apispec/azurerm_netapp_volume_invalid_pool_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappVolumeInvalidPoolNameRule checks the pattern is valid type AzurermNetappVolumeInvalidPoolNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappVolumeInvalidPoolNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappVolumeInvalidPoolNameRule) Severity() string { +func (r *AzurermNetappVolumeInvalidPoolNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappVolumeInvalidPoolNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappVolumeInvalidPoolNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[a-zA-Z0-9][a-zA-Z0-9\-_]{0,63}$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_volume_invalid_resource_group_name.go b/rules/apispec/azurerm_netapp_volume_invalid_resource_group_name.go index 388583fc..81b9a43c 100644 --- a/rules/apispec/azurerm_netapp_volume_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_netapp_volume_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappVolumeInvalidResourceGroupNameRule checks the pattern is valid type AzurermNetappVolumeInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermNetappVolumeInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappVolumeInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermNetappVolumeInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermNetappVolumeInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappVolumeInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_netapp_volume_invalid_service_level.go b/rules/apispec/azurerm_netapp_volume_invalid_service_level.go index 12e0ada4..eee855f2 100644 --- a/rules/apispec/azurerm_netapp_volume_invalid_service_level.go +++ b/rules/apispec/azurerm_netapp_volume_invalid_service_level.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetappVolumeInvalidServiceLevelRule checks the pattern is valid type AzurermNetappVolumeInvalidServiceLevelRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermNetappVolumeInvalidServiceLevelRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetappVolumeInvalidServiceLevelRule) Severity() string { +func (r *AzurermNetappVolumeInvalidServiceLevelRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermNetappVolumeInvalidServiceLevelRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetappVolumeInvalidServiceLevelRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermNetappVolumeInvalidServiceLevelRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as service_level`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_network_packet_capture_invalid_maximum_capture_duration.go b/rules/apispec/azurerm_network_packet_capture_invalid_maximum_capture_duration.go index 699f826b..c547831d 100644 --- a/rules/apispec/azurerm_network_packet_capture_invalid_maximum_capture_duration.go +++ b/rules/apispec/azurerm_network_packet_capture_invalid_maximum_capture_duration.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule checks the pattern is valid type AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule) Enabled() } // Severity returns the rule severity -func (r *AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule) Severity() string { +func (r *AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule) Link() st // Check checks the pattern is valid func (r *AzurermNetworkPacketCaptureInvalidMaximumCaptureDurationRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "maximum_capture_duration must be 18000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "maximum_capture_duration must be 0 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_network_security_rule_invalid_access.go b/rules/apispec/azurerm_network_security_rule_invalid_access.go index 19a45837..a63dab03 100644 --- a/rules/apispec/azurerm_network_security_rule_invalid_access.go +++ b/rules/apispec/azurerm_network_security_rule_invalid_access.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetworkSecurityRuleInvalidAccessRule checks the pattern is valid type AzurermNetworkSecurityRuleInvalidAccessRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Severity() string { +func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermNetworkSecurityRuleInvalidAccessRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as access`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_network_security_rule_invalid_direction.go b/rules/apispec/azurerm_network_security_rule_invalid_direction.go index ba9405dd..98815ef4 100644 --- a/rules/apispec/azurerm_network_security_rule_invalid_direction.go +++ b/rules/apispec/azurerm_network_security_rule_invalid_direction.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetworkSecurityRuleInvalidDirectionRule checks the pattern is valid type AzurermNetworkSecurityRuleInvalidDirectionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Severity() string { +func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermNetworkSecurityRuleInvalidDirectionRule) Check(runner tflint.Run } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as direction`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_network_security_rule_invalid_protocol.go b/rules/apispec/azurerm_network_security_rule_invalid_protocol.go index dd08eec5..03caeed4 100644 --- a/rules/apispec/azurerm_network_security_rule_invalid_protocol.go +++ b/rules/apispec/azurerm_network_security_rule_invalid_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNetworkSecurityRuleInvalidProtocolRule checks the pattern is valid type AzurermNetworkSecurityRuleInvalidProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Severity() string { +func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Link() string { // Check checks the pattern is valid func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermNetworkSecurityRuleInvalidProtocolRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_notification_hub_namespace_invalid_namespace_type.go b/rules/apispec/azurerm_notification_hub_namespace_invalid_namespace_type.go index f466cd0a..b91647b2 100644 --- a/rules/apispec/azurerm_notification_hub_namespace_invalid_namespace_type.go +++ b/rules/apispec/azurerm_notification_hub_namespace_invalid_namespace_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNotificationHubNamespaceInvalidNamespaceTypeRule checks the pattern is valid type AzurermNotificationHubNamespaceInvalidNamespaceTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Severity() string { +func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Link() string // Check checks the pattern is valid func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermNotificationHubNamespaceInvalidNamespaceTypeRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as namespace_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_notification_hub_namespace_invalid_sku_name.go b/rules/apispec/azurerm_notification_hub_namespace_invalid_sku_name.go index 87aaab05..ad49fbfb 100644 --- a/rules/apispec/azurerm_notification_hub_namespace_invalid_sku_name.go +++ b/rules/apispec/azurerm_notification_hub_namespace_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermNotificationHubNamespaceInvalidSkuNameRule checks the pattern is valid type AzurermNotificationHubNamespaceInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Severity() string { +func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermNotificationHubNamespaceInvalidSkuNameRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_packet_capture_invalid_maximum_capture_duration.go b/rules/apispec/azurerm_packet_capture_invalid_maximum_capture_duration.go index b404d674..c2579fd5 100644 --- a/rules/apispec/azurerm_packet_capture_invalid_maximum_capture_duration.go +++ b/rules/apispec/azurerm_packet_capture_invalid_maximum_capture_duration.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPacketCaptureInvalidMaximumCaptureDurationRule checks the pattern is valid type AzurermPacketCaptureInvalidMaximumCaptureDurationRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermPacketCaptureInvalidMaximumCaptureDurationRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPacketCaptureInvalidMaximumCaptureDurationRule) Severity() string { +func (r *AzurermPacketCaptureInvalidMaximumCaptureDurationRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermPacketCaptureInvalidMaximumCaptureDurationRule) Link() string { // Check checks the pattern is valid func (r *AzurermPacketCaptureInvalidMaximumCaptureDurationRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "maximum_capture_duration must be 18000 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "maximum_capture_duration must be 0 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_postgresql_firewall_rule_invalid_end_ip_address.go b/rules/apispec/azurerm_postgresql_firewall_rule_invalid_end_ip_address.go index 685f4a26..0e137508 100644 --- a/rules/apispec/azurerm_postgresql_firewall_rule_invalid_end_ip_address.go +++ b/rules/apispec/azurerm_postgresql_firewall_rule_invalid_end_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule checks the pattern is valid type AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule) Severity() string { +func (r *AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermPostgresqlFirewallRuleInvalidEndIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_postgresql_firewall_rule_invalid_start_ip_address.go b/rules/apispec/azurerm_postgresql_firewall_rule_invalid_start_ip_address.go index f1935d2d..b9b5198a 100644 --- a/rules/apispec/azurerm_postgresql_firewall_rule_invalid_start_ip_address.go +++ b/rules/apispec/azurerm_postgresql_firewall_rule_invalid_start_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule checks the pattern is valid type AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule) Severity() string { +func (r *AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermPostgresqlFirewallRuleInvalidStartIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_postgresql_server_invalid_ssl_enforcement.go b/rules/apispec/azurerm_postgresql_server_invalid_ssl_enforcement.go index 6df5ff34..dfbd2bf6 100644 --- a/rules/apispec/azurerm_postgresql_server_invalid_ssl_enforcement.go +++ b/rules/apispec/azurerm_postgresql_server_invalid_ssl_enforcement.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPostgresqlServerInvalidSslEnforcementRule checks the pattern is valid type AzurermPostgresqlServerInvalidSslEnforcementRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Severity() string { +func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Link() string { // Check checks the pattern is valid func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermPostgresqlServerInvalidSslEnforcementRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as ssl_enforcement`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_postgresql_server_invalid_version.go b/rules/apispec/azurerm_postgresql_server_invalid_version.go index bbf54db0..22c9190e 100644 --- a/rules/apispec/azurerm_postgresql_server_invalid_version.go +++ b/rules/apispec/azurerm_postgresql_server_invalid_version.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPostgresqlServerInvalidVersionRule checks the pattern is valid type AzurermPostgresqlServerInvalidVersionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermPostgresqlServerInvalidVersionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPostgresqlServerInvalidVersionRule) Severity() string { +func (r *AzurermPostgresqlServerInvalidVersionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermPostgresqlServerInvalidVersionRule) Link() string { // Check checks the pattern is valid func (r *AzurermPostgresqlServerInvalidVersionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermPostgresqlServerInvalidVersionRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as version`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_public_ip_invalid_sku.go b/rules/apispec/azurerm_public_ip_invalid_sku.go index 561249c0..9e8a9712 100644 --- a/rules/apispec/azurerm_public_ip_invalid_sku.go +++ b/rules/apispec/azurerm_public_ip_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPublicIPInvalidSkuRule checks the pattern is valid type AzurermPublicIPInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermPublicIPInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPublicIPInvalidSkuRule) Severity() string { +func (r *AzurermPublicIPInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermPublicIPInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermPublicIPInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermPublicIPInvalidSkuRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_public_ip_prefix_invalid_sku.go b/rules/apispec/azurerm_public_ip_prefix_invalid_sku.go index 691613af..2ee23b4d 100644 --- a/rules/apispec/azurerm_public_ip_prefix_invalid_sku.go +++ b/rules/apispec/azurerm_public_ip_prefix_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermPublicIPPrefixInvalidSkuRule checks the pattern is valid type AzurermPublicIPPrefixInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermPublicIPPrefixInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermPublicIPPrefixInvalidSkuRule) Severity() string { +func (r *AzurermPublicIPPrefixInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermPublicIPPrefixInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermPublicIPPrefixInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermPublicIPPrefixInvalidSkuRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_recovery_services_vault_invalid_sku.go b/rules/apispec/azurerm_recovery_services_vault_invalid_sku.go index 987046d0..37565ae5 100644 --- a/rules/apispec/azurerm_recovery_services_vault_invalid_sku.go +++ b/rules/apispec/azurerm_recovery_services_vault_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRecoveryServicesVaultInvalidSkuRule checks the pattern is valid type AzurermRecoveryServicesVaultInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Severity() string { +func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermRecoveryServicesVaultInvalidSkuRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_redis_cache_invalid_family.go b/rules/apispec/azurerm_redis_cache_invalid_family.go index ead7bef7..f9b3f99b 100644 --- a/rules/apispec/azurerm_redis_cache_invalid_family.go +++ b/rules/apispec/azurerm_redis_cache_invalid_family.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRedisCacheInvalidFamilyRule checks the pattern is valid type AzurermRedisCacheInvalidFamilyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermRedisCacheInvalidFamilyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRedisCacheInvalidFamilyRule) Severity() string { +func (r *AzurermRedisCacheInvalidFamilyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermRedisCacheInvalidFamilyRule) Link() string { // Check checks the pattern is valid func (r *AzurermRedisCacheInvalidFamilyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermRedisCacheInvalidFamilyRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as family`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_redis_cache_invalid_minimum_tls_version.go b/rules/apispec/azurerm_redis_cache_invalid_minimum_tls_version.go index 5855e238..092db22e 100644 --- a/rules/apispec/azurerm_redis_cache_invalid_minimum_tls_version.go +++ b/rules/apispec/azurerm_redis_cache_invalid_minimum_tls_version.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRedisCacheInvalidMinimumTLSVersionRule checks the pattern is valid type AzurermRedisCacheInvalidMinimumTLSVersionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Severity() string { +func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Link() string { // Check checks the pattern is valid func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermRedisCacheInvalidMinimumTLSVersionRule) Check(runner tflint.Runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as minimum_tls_version`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_redis_cache_invalid_private_static_ip_address.go b/rules/apispec/azurerm_redis_cache_invalid_private_static_ip_address.go index 67d135bd..78a0c7db 100644 --- a/rules/apispec/azurerm_redis_cache_invalid_private_static_ip_address.go +++ b/rules/apispec/azurerm_redis_cache_invalid_private_static_ip_address.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRedisCacheInvalidPrivateStaticIPAddressRule checks the pattern is valid type AzurermRedisCacheInvalidPrivateStaticIPAddressRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermRedisCacheInvalidPrivateStaticIPAddressRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRedisCacheInvalidPrivateStaticIPAddressRule) Severity() string { +func (r *AzurermRedisCacheInvalidPrivateStaticIPAddressRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermRedisCacheInvalidPrivateStaticIPAddressRule) Link() string { // Check checks the pattern is valid func (r *AzurermRedisCacheInvalidPrivateStaticIPAddressRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^\d+\.\d+\.\d+\.\d+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_redis_cache_invalid_sku_name.go b/rules/apispec/azurerm_redis_cache_invalid_sku_name.go index 338c15b5..5081ca05 100644 --- a/rules/apispec/azurerm_redis_cache_invalid_sku_name.go +++ b/rules/apispec/azurerm_redis_cache_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRedisCacheInvalidSkuNameRule checks the pattern is valid type AzurermRedisCacheInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermRedisCacheInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRedisCacheInvalidSkuNameRule) Severity() string { +func (r *AzurermRedisCacheInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermRedisCacheInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermRedisCacheInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermRedisCacheInvalidSkuNameRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_redis_cache_invalid_subnet_id.go b/rules/apispec/azurerm_redis_cache_invalid_subnet_id.go index c0d9aee0..887fd2ac 100644 --- a/rules/apispec/azurerm_redis_cache_invalid_subnet_id.go +++ b/rules/apispec/azurerm_redis_cache_invalid_subnet_id.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRedisCacheInvalidSubnetIDRule checks the pattern is valid type AzurermRedisCacheInvalidSubnetIDRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermRedisCacheInvalidSubnetIDRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRedisCacheInvalidSubnetIDRule) Severity() string { +func (r *AzurermRedisCacheInvalidSubnetIDRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermRedisCacheInvalidSubnetIDRule) Link() string { // Check checks the pattern is valid func (r *AzurermRedisCacheInvalidSubnetIDRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]*/subnets/[^/]*$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_relay_namespace_invalid_sku_name.go b/rules/apispec/azurerm_relay_namespace_invalid_sku_name.go index baf35376..5246f302 100644 --- a/rules/apispec/azurerm_relay_namespace_invalid_sku_name.go +++ b/rules/apispec/azurerm_relay_namespace_invalid_sku_name.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRelayNamespaceInvalidSkuNameRule checks the pattern is valid type AzurermRelayNamespaceInvalidSkuNameRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermRelayNamespaceInvalidSkuNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRelayNamespaceInvalidSkuNameRule) Severity() string { +func (r *AzurermRelayNamespaceInvalidSkuNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermRelayNamespaceInvalidSkuNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermRelayNamespaceInvalidSkuNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermRelayNamespaceInvalidSkuNameRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku_name`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_route_invalid_next_hop_type.go b/rules/apispec/azurerm_route_invalid_next_hop_type.go index 578688d8..0cda32aa 100644 --- a/rules/apispec/azurerm_route_invalid_next_hop_type.go +++ b/rules/apispec/azurerm_route_invalid_next_hop_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermRouteInvalidNextHopTypeRule checks the pattern is valid type AzurermRouteInvalidNextHopTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermRouteInvalidNextHopTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermRouteInvalidNextHopTypeRule) Severity() string { +func (r *AzurermRouteInvalidNextHopTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermRouteInvalidNextHopTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermRouteInvalidNextHopTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermRouteInvalidNextHopTypeRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as next_hop_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_search_service_invalid_partition_count.go b/rules/apispec/azurerm_search_service_invalid_partition_count.go index a812dfe0..e852f048 100644 --- a/rules/apispec/azurerm_search_service_invalid_partition_count.go +++ b/rules/apispec/azurerm_search_service_invalid_partition_count.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSearchServiceInvalidPartitionCountRule checks the pattern is valid type AzurermSearchServiceInvalidPartitionCountRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermSearchServiceInvalidPartitionCountRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSearchServiceInvalidPartitionCountRule) Severity() string { +func (r *AzurermSearchServiceInvalidPartitionCountRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermSearchServiceInvalidPartitionCountRule) Link() string { // Check checks the pattern is valid func (r *AzurermSearchServiceInvalidPartitionCountRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "partition_count must be 12 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "partition_count must be 1 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_search_service_invalid_replica_count.go b/rules/apispec/azurerm_search_service_invalid_replica_count.go index 04d6e5bc..3e457731 100644 --- a/rules/apispec/azurerm_search_service_invalid_replica_count.go +++ b/rules/apispec/azurerm_search_service_invalid_replica_count.go @@ -4,13 +4,15 @@ package apispec import ( - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSearchServiceInvalidReplicaCountRule checks the pattern is valid type AzurermSearchServiceInvalidReplicaCountRule struct { + tflint.DefaultRule + resourceType string attributeName string max int @@ -38,7 +40,7 @@ func (r *AzurermSearchServiceInvalidReplicaCountRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSearchServiceInvalidReplicaCountRule) Severity() string { +func (r *AzurermSearchServiceInvalidReplicaCountRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,26 +51,44 @@ func (r *AzurermSearchServiceInvalidReplicaCountRule) Link() string { // Check checks the pattern is valid func (r *AzurermSearchServiceInvalidReplicaCountRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val int err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "replica_count must be 12 or less", - attribute.Expr, + attribute.Expr.Range(), ) } if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "replica_count must be 1 or higher", - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_search_service_invalid_sku.go b/rules/apispec/azurerm_search_service_invalid_sku.go index 8d8b4b84..1cc78f71 100644 --- a/rules/apispec/azurerm_search_service_invalid_sku.go +++ b/rules/apispec/azurerm_search_service_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSearchServiceInvalidSkuRule checks the pattern is valid type AzurermSearchServiceInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermSearchServiceInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSearchServiceInvalidSkuRule) Severity() string { +func (r *AzurermSearchServiceInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermSearchServiceInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermSearchServiceInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermSearchServiceInvalidSkuRule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_sentinel_alert_rule_ms_security_incident_invalid_product_filter.go b/rules/apispec/azurerm_sentinel_alert_rule_ms_security_incident_invalid_product_filter.go index c9a7dcdc..390575d2 100644 --- a/rules/apispec/azurerm_sentinel_alert_rule_ms_security_incident_invalid_product_filter.go +++ b/rules/apispec/azurerm_sentinel_alert_rule_ms_security_incident_invalid_product_filter.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule checks the pattern is valid type AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Ena } // Severity returns the rule severity -func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Severity() string { +func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Lin // Check checks the pattern is valid func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermSentinelAlertRuleMsSecurityIncidentInvalidProductFilterRule) Che } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as product_filter`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_service_fabric_cluster_invalid_reliability_level.go b/rules/apispec/azurerm_service_fabric_cluster_invalid_reliability_level.go index f3df2eeb..80e56df8 100644 --- a/rules/apispec/azurerm_service_fabric_cluster_invalid_reliability_level.go +++ b/rules/apispec/azurerm_service_fabric_cluster_invalid_reliability_level.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermServiceFabricClusterInvalidReliabilityLevelRule checks the pattern is valid type AzurermServiceFabricClusterInvalidReliabilityLevelRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Severity() string { +func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Link() string { // Check checks the pattern is valid func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermServiceFabricClusterInvalidReliabilityLevelRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as reliability_level`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_service_fabric_cluster_invalid_upgrade_mode.go b/rules/apispec/azurerm_service_fabric_cluster_invalid_upgrade_mode.go index 0fce0c10..9661f497 100644 --- a/rules/apispec/azurerm_service_fabric_cluster_invalid_upgrade_mode.go +++ b/rules/apispec/azurerm_service_fabric_cluster_invalid_upgrade_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermServiceFabricClusterInvalidUpgradeModeRule checks the pattern is valid type AzurermServiceFabricClusterInvalidUpgradeModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Severity() string { +func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Link() string { // Check checks the pattern is valid func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermServiceFabricClusterInvalidUpgradeModeRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as upgrade_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_servicebus_namespace_invalid_sku.go b/rules/apispec/azurerm_servicebus_namespace_invalid_sku.go index 5d5989d0..4678add7 100644 --- a/rules/apispec/azurerm_servicebus_namespace_invalid_sku.go +++ b/rules/apispec/azurerm_servicebus_namespace_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermServicebusNamespaceInvalidSkuRule checks the pattern is valid type AzurermServicebusNamespaceInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermServicebusNamespaceInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermServicebusNamespaceInvalidSkuRule) Severity() string { +func (r *AzurermServicebusNamespaceInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermServicebusNamespaceInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermServicebusNamespaceInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermServicebusNamespaceInvalidSkuRule) Check(runner tflint.Runner) e } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_servicebus_subscription_rule_invalid_filter_type.go b/rules/apispec/azurerm_servicebus_subscription_rule_invalid_filter_type.go index cf84c3ef..8adb5931 100644 --- a/rules/apispec/azurerm_servicebus_subscription_rule_invalid_filter_type.go +++ b/rules/apispec/azurerm_servicebus_subscription_rule_invalid_filter_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermServicebusSubscriptionRuleInvalidFilterTypeRule checks the pattern is valid type AzurermServicebusSubscriptionRuleInvalidFilterTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Severity() string { +func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermServicebusSubscriptionRuleInvalidFilterTypeRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as filter_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_servicebus_topic_invalid_status.go b/rules/apispec/azurerm_servicebus_topic_invalid_status.go index 4ef2bf4a..a0239640 100644 --- a/rules/apispec/azurerm_servicebus_topic_invalid_status.go +++ b/rules/apispec/azurerm_servicebus_topic_invalid_status.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermServicebusTopicInvalidStatusRule checks the pattern is valid type AzurermServicebusTopicInvalidStatusRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -47,7 +49,7 @@ func (r *AzurermServicebusTopicInvalidStatusRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermServicebusTopicInvalidStatusRule) Severity() string { +func (r *AzurermServicebusTopicInvalidStatusRule) Severity() tflint.Severity { return tflint.ERROR } @@ -58,11 +60,24 @@ func (r *AzurermServicebusTopicInvalidStatusRule) Link() string { // Check checks the pattern is valid func (r *AzurermServicebusTopicInvalidStatusRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -70,13 +85,18 @@ func (r *AzurermServicebusTopicInvalidStatusRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as status`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_shared_image_invalid_os_type.go b/rules/apispec/azurerm_shared_image_invalid_os_type.go index 34ee9bf7..b1733541 100644 --- a/rules/apispec/azurerm_shared_image_invalid_os_type.go +++ b/rules/apispec/azurerm_shared_image_invalid_os_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSharedImageInvalidOSTypeRule checks the pattern is valid type AzurermSharedImageInvalidOSTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermSharedImageInvalidOSTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSharedImageInvalidOSTypeRule) Severity() string { +func (r *AzurermSharedImageInvalidOSTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermSharedImageInvalidOSTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermSharedImageInvalidOSTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermSharedImageInvalidOSTypeRule) Check(runner tflint.Runner) error } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as os_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_snapshot_invalid_create_option.go b/rules/apispec/azurerm_snapshot_invalid_create_option.go index c6a23ec7..f6df332a 100644 --- a/rules/apispec/azurerm_snapshot_invalid_create_option.go +++ b/rules/apispec/azurerm_snapshot_invalid_create_option.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSnapshotInvalidCreateOptionRule checks the pattern is valid type AzurermSnapshotInvalidCreateOptionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -45,7 +47,7 @@ func (r *AzurermSnapshotInvalidCreateOptionRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSnapshotInvalidCreateOptionRule) Severity() string { +func (r *AzurermSnapshotInvalidCreateOptionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -56,11 +58,24 @@ func (r *AzurermSnapshotInvalidCreateOptionRule) Link() string { // Check checks the pattern is valid func (r *AzurermSnapshotInvalidCreateOptionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -68,13 +83,18 @@ func (r *AzurermSnapshotInvalidCreateOptionRule) Check(runner tflint.Runner) err } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as create_option`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_sql_database_invalid_create_mode.go b/rules/apispec/azurerm_sql_database_invalid_create_mode.go index 7beea8be..ae73bb1a 100644 --- a/rules/apispec/azurerm_sql_database_invalid_create_mode.go +++ b/rules/apispec/azurerm_sql_database_invalid_create_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermSQLDatabaseInvalidCreateModeRule checks the pattern is valid type AzurermSQLDatabaseInvalidCreateModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -48,7 +50,7 @@ func (r *AzurermSQLDatabaseInvalidCreateModeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermSQLDatabaseInvalidCreateModeRule) Severity() string { +func (r *AzurermSQLDatabaseInvalidCreateModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -59,11 +61,24 @@ func (r *AzurermSQLDatabaseInvalidCreateModeRule) Link() string { // Check checks the pattern is valid func (r *AzurermSQLDatabaseInvalidCreateModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -71,13 +86,18 @@ func (r *AzurermSQLDatabaseInvalidCreateModeRule) Check(runner tflint.Runner) er } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as create_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_storage_account_invalid_access_tier.go b/rules/apispec/azurerm_storage_account_invalid_access_tier.go index 2583c879..07c442aa 100644 --- a/rules/apispec/azurerm_storage_account_invalid_access_tier.go +++ b/rules/apispec/azurerm_storage_account_invalid_access_tier.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStorageAccountInvalidAccessTierRule checks the pattern is valid type AzurermStorageAccountInvalidAccessTierRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermStorageAccountInvalidAccessTierRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermStorageAccountInvalidAccessTierRule) Severity() string { +func (r *AzurermStorageAccountInvalidAccessTierRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermStorageAccountInvalidAccessTierRule) Link() string { // Check checks the pattern is valid func (r *AzurermStorageAccountInvalidAccessTierRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermStorageAccountInvalidAccessTierRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as access_tier`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_storage_account_invalid_account_kind.go b/rules/apispec/azurerm_storage_account_invalid_account_kind.go index 6e904f19..5b669bda 100644 --- a/rules/apispec/azurerm_storage_account_invalid_account_kind.go +++ b/rules/apispec/azurerm_storage_account_invalid_account_kind.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStorageAccountInvalidAccountKindRule checks the pattern is valid type AzurermStorageAccountInvalidAccountKindRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -43,7 +45,7 @@ func (r *AzurermStorageAccountInvalidAccountKindRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermStorageAccountInvalidAccountKindRule) Severity() string { +func (r *AzurermStorageAccountInvalidAccountKindRule) Severity() tflint.Severity { return tflint.ERROR } @@ -54,11 +56,24 @@ func (r *AzurermStorageAccountInvalidAccountKindRule) Link() string { // Check checks the pattern is valid func (r *AzurermStorageAccountInvalidAccountKindRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -66,13 +81,18 @@ func (r *AzurermStorageAccountInvalidAccountKindRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as account_kind`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_storage_account_invalid_resource_group_name.go b/rules/apispec/azurerm_storage_account_invalid_resource_group_name.go index 36afbb1b..2d7563bd 100644 --- a/rules/apispec/azurerm_storage_account_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_storage_account_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStorageAccountInvalidResourceGroupNameRule checks the pattern is valid type AzurermStorageAccountInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermStorageAccountInvalidResourceGroupNameRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermStorageAccountInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermStorageAccountInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermStorageAccountInvalidResourceGroupNameRule) Link() string { // Check checks the pattern is valid func (r *AzurermStorageAccountInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_storage_account_network_rules_invalid_default_action.go b/rules/apispec/azurerm_storage_account_network_rules_invalid_default_action.go index 972ed7fc..33e5bd61 100644 --- a/rules/apispec/azurerm_storage_account_network_rules_invalid_default_action.go +++ b/rules/apispec/azurerm_storage_account_network_rules_invalid_default_action.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStorageAccountNetworkRulesInvalidDefaultActionRule checks the pattern is valid type AzurermStorageAccountNetworkRulesInvalidDefaultActionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Enabled() bo } // Severity returns the rule severity -func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Severity() string { +func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Link() strin // Check checks the pattern is valid func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermStorageAccountNetworkRulesInvalidDefaultActionRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as default_action`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_storage_account_network_rules_invalid_resource_group_name.go b/rules/apispec/azurerm_storage_account_network_rules_invalid_resource_group_name.go index 60cf5d1b..8bea2821 100644 --- a/rules/apispec/azurerm_storage_account_network_rules_invalid_resource_group_name.go +++ b/rules/apispec/azurerm_storage_account_network_rules_invalid_resource_group_name.go @@ -6,13 +6,15 @@ import ( "fmt" "regexp" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule checks the pattern is valid type AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule struct { + tflint.DefaultRule + resourceType string attributeName string pattern *regexp.Regexp @@ -38,7 +40,7 @@ func (r *AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule) Enabled( } // Severity returns the rule severity -func (r *AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule) Severity() string { +func (r *AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule) Severity() tflint.Severity { return tflint.ERROR } @@ -49,19 +51,37 @@ func (r *AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule) Link() s // Check checks the pattern is valid func (r *AzurermStorageAccountNetworkRulesInvalidResourceGroupNameRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^[-\w\._\(\)]+$`), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_stream_analytics_job_invalid_compatibility_level.go b/rules/apispec/azurerm_stream_analytics_job_invalid_compatibility_level.go index 3803679d..8c0a159b 100644 --- a/rules/apispec/azurerm_stream_analytics_job_invalid_compatibility_level.go +++ b/rules/apispec/azurerm_stream_analytics_job_invalid_compatibility_level.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule checks the pattern is valid type AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -39,7 +41,7 @@ func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Severity() string { +func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Severity() tflint.Severity { return tflint.ERROR } @@ -50,11 +52,24 @@ func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Link() string { // Check checks the pattern is valid func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -62,13 +77,18 @@ func (r *AzurermStreamAnalyticsJobInvalidCompatibilityLevelRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as compatibility_level`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_stream_analytics_job_invalid_events_out_of_order_policy.go b/rules/apispec/azurerm_stream_analytics_job_invalid_events_out_of_order_policy.go index 17158804..3d716669 100644 --- a/rules/apispec/azurerm_stream_analytics_job_invalid_events_out_of_order_policy.go +++ b/rules/apispec/azurerm_stream_analytics_job_invalid_events_out_of_order_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule checks the pattern is valid type AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Severity() string { +func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Link() stri // Check checks the pattern is valid func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermStreamAnalyticsJobInvalidEventsOutOfOrderPolicyRule) Check(runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as events_out_of_order_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_stream_analytics_job_invalid_output_error_policy.go b/rules/apispec/azurerm_stream_analytics_job_invalid_output_error_policy.go index 57cd8570..082a4c83 100644 --- a/rules/apispec/azurerm_stream_analytics_job_invalid_output_error_policy.go +++ b/rules/apispec/azurerm_stream_analytics_job_invalid_output_error_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule checks the pattern is valid type AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Severity() string { +func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Link() string { // Check checks the pattern is valid func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermStreamAnalyticsJobInvalidOutputErrorPolicyRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as output_error_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_template_deployment_invalid_deployment_mode.go b/rules/apispec/azurerm_template_deployment_invalid_deployment_mode.go index 1e2ed1d4..c46fe982 100644 --- a/rules/apispec/azurerm_template_deployment_invalid_deployment_mode.go +++ b/rules/apispec/azurerm_template_deployment_invalid_deployment_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermTemplateDeploymentInvalidDeploymentModeRule checks the pattern is valid type AzurermTemplateDeploymentInvalidDeploymentModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Severity() string { +func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Link() string { // Check checks the pattern is valid func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermTemplateDeploymentInvalidDeploymentModeRule) Check(runner tflint } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as deployment_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_traffic_manager_endpoint_invalid_endpoint_status.go b/rules/apispec/azurerm_traffic_manager_endpoint_invalid_endpoint_status.go index 8c007f92..8872821a 100644 --- a/rules/apispec/azurerm_traffic_manager_endpoint_invalid_endpoint_status.go +++ b/rules/apispec/azurerm_traffic_manager_endpoint_invalid_endpoint_status.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermTrafficManagerEndpointInvalidEndpointStatusRule checks the pattern is valid type AzurermTrafficManagerEndpointInvalidEndpointStatusRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Severity() string { +func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Link() string { // Check checks the pattern is valid func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermTrafficManagerEndpointInvalidEndpointStatusRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as endpoint_status`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_traffic_manager_profile_invalid_profile_status.go b/rules/apispec/azurerm_traffic_manager_profile_invalid_profile_status.go index 8e4e9b8b..c0827d8a 100644 --- a/rules/apispec/azurerm_traffic_manager_profile_invalid_profile_status.go +++ b/rules/apispec/azurerm_traffic_manager_profile_invalid_profile_status.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermTrafficManagerProfileInvalidProfileStatusRule checks the pattern is valid type AzurermTrafficManagerProfileInvalidProfileStatusRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Severity() string { +func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Link() string { // Check checks the pattern is valid func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermTrafficManagerProfileInvalidProfileStatusRule) Check(runner tfli } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as profile_status`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_traffic_manager_profile_invalid_traffic_routing_method.go b/rules/apispec/azurerm_traffic_manager_profile_invalid_traffic_routing_method.go index 364073b4..79253ade 100644 --- a/rules/apispec/azurerm_traffic_manager_profile_invalid_traffic_routing_method.go +++ b/rules/apispec/azurerm_traffic_manager_profile_invalid_traffic_routing_method.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule checks the pattern is valid type AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -44,7 +46,7 @@ func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Enabled() } // Severity returns the rule severity -func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Severity() string { +func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Severity() tflint.Severity { return tflint.ERROR } @@ -55,11 +57,24 @@ func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Link() str // Check checks the pattern is valid func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -67,13 +82,18 @@ func (r *AzurermTrafficManagerProfileInvalidTrafficRoutingMethodRule) Check(runn } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as traffic_routing_method`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_caching.go b/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_caching.go index 5bc0f6b2..68929d92 100644 --- a/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_caching.go +++ b/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_caching.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule checks the pattern is valid type AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Enabled() bo } // Severity returns the rule severity -func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Severity() string { +func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Link() strin // Check checks the pattern is valid func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCachingRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as caching`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_create_option.go b/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_create_option.go index 1b31101a..5eb3d1ac 100644 --- a/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_create_option.go +++ b/rules/apispec/azurerm_virtual_machine_data_disk_attachment_invalid_create_option.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule checks the pattern is valid type AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Enabled } // Severity returns the rule severity -func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Severity() string { +func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Link() // Check checks the pattern is valid func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualMachineDataDiskAttachmentInvalidCreateOptionRule) Check(r } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as create_option`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_eviction_policy.go b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_eviction_policy.go index 6f920c7b..b3432b67 100644 --- a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_eviction_policy.go +++ b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_eviction_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule checks the pattern is valid type AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() string { +func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(runner tf } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as eviction_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_priority.go b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_priority.go index 2e8d4a22..7a0b9aca 100644 --- a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_priority.go +++ b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_priority.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineScaleSetInvalidPriorityRule checks the pattern is valid type AzurermVirtualMachineScaleSetInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Severity() string { +func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualMachineScaleSetInvalidPriorityRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as priority`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_upgrade_policy_mode.go b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_upgrade_policy_mode.go index 3a120674..dd6b7b9d 100644 --- a/rules/apispec/azurerm_virtual_machine_scale_set_invalid_upgrade_policy_mode.go +++ b/rules/apispec/azurerm_virtual_machine_scale_set_invalid_upgrade_policy_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule checks the pattern is valid type AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Enabled() bo } // Severity returns the rule severity -func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Severity() string { +func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Link() strin // Check checks the pattern is valid func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualMachineScaleSetInvalidUpgradePolicyModeRule) Check(runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as upgrade_policy_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_connection_protocol.go b/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_connection_protocol.go index babaac83..70f480c9 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_connection_protocol.go +++ b/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_connection_protocol.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule checks the pattern is valid type AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) En } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) Li // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidConnectionProtocolRule) Ch } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as connection_protocol`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_type.go b/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_type.go index d11dd2b1..53fcd25c 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_type.go +++ b/rules/apispec/azurerm_virtual_network_gateway_connection_invalid_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayConnectionInvalidTypeRule checks the pattern is valid type AzurermVirtualNetworkGatewayConnectionInvalidTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermVirtualNetworkGatewayConnectionInvalidTypeRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_invalid_generation.go b/rules/apispec/azurerm_virtual_network_gateway_invalid_generation.go index 28deb379..cf00235f 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_invalid_generation.go +++ b/rules/apispec/azurerm_virtual_network_gateway_invalid_generation.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayInvalidGenerationRule checks the pattern is valid type AzurermVirtualNetworkGatewayInvalidGenerationRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualNetworkGatewayInvalidGenerationRule) Check(runner tflint. } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as generation`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_invalid_sku.go b/rules/apispec/azurerm_virtual_network_gateway_invalid_sku.go index 638760b1..5d7816b3 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_invalid_sku.go +++ b/rules/apispec/azurerm_virtual_network_gateway_invalid_sku.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayInvalidSkuRule checks the pattern is valid type AzurermVirtualNetworkGatewayInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -55,7 +57,7 @@ func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -66,11 +68,24 @@ func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -78,13 +93,18 @@ func (r *AzurermVirtualNetworkGatewayInvalidSkuRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_invalid_type.go b/rules/apispec/azurerm_virtual_network_gateway_invalid_type.go index 5eca9ec7..f558955c 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_invalid_type.go +++ b/rules/apispec/azurerm_virtual_network_gateway_invalid_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayInvalidTypeRule checks the pattern is valid type AzurermVirtualNetworkGatewayInvalidTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermVirtualNetworkGatewayInvalidTypeRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_network_gateway_invalid_vpn_type.go b/rules/apispec/azurerm_virtual_network_gateway_invalid_vpn_type.go index b0936898..cadde97c 100644 --- a/rules/apispec/azurerm_virtual_network_gateway_invalid_vpn_type.go +++ b/rules/apispec/azurerm_virtual_network_gateway_invalid_vpn_type.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualNetworkGatewayInvalidVpnTypeRule checks the pattern is valid type AzurermVirtualNetworkGatewayInvalidVpnTypeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Severity() string { +func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermVirtualNetworkGatewayInvalidVpnTypeRule) Check(runner tflint.Run } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as vpn_type`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_virtual_wan_invalid_office365_local_breakout_category.go b/rules/apispec/azurerm_virtual_wan_invalid_office365_local_breakout_category.go index 10515c81..264de7e3 100644 --- a/rules/apispec/azurerm_virtual_wan_invalid_office365_local_breakout_category.go +++ b/rules/apispec/azurerm_virtual_wan_invalid_office365_local_breakout_category.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule checks the pattern is valid type AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -42,7 +44,7 @@ func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Severity() string { +func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Severity() tflint.Severity { return tflint.ERROR } @@ -53,11 +55,24 @@ func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Link() stri // Check checks the pattern is valid func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -65,13 +80,18 @@ func (r *AzurermVirtualWanInvalidOffice365LocalBreakoutCategoryRule) Check(runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as office365_local_breakout_category`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_windows_virtual_machine_invalid_eviction_policy.go b/rules/apispec/azurerm_windows_virtual_machine_invalid_eviction_policy.go index e82ca034..a869e5af 100644 --- a/rules/apispec/azurerm_windows_virtual_machine_invalid_eviction_policy.go +++ b/rules/apispec/azurerm_windows_virtual_machine_invalid_eviction_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineInvalidEvictionPolicyRule checks the pattern is valid type AzurermWindowsVirtualMachineInvalidEvictionPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Severity() string { +func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Link() string { // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermWindowsVirtualMachineInvalidEvictionPolicyRule) Check(runner tfl } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as eviction_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_windows_virtual_machine_invalid_priority.go b/rules/apispec/azurerm_windows_virtual_machine_invalid_priority.go index 629dae51..c4df99dd 100644 --- a/rules/apispec/azurerm_windows_virtual_machine_invalid_priority.go +++ b/rules/apispec/azurerm_windows_virtual_machine_invalid_priority.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineInvalidPriorityRule checks the pattern is valid type AzurermWindowsVirtualMachineInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Severity() string { +func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Link() string { // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermWindowsVirtualMachineInvalidPriorityRule) Check(runner tflint.Ru } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as priority`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_eviction_policy.go b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_eviction_policy.go index bfa6a728..3657718a 100644 --- a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_eviction_policy.go +++ b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_eviction_policy.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule checks the pattern is valid type AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -40,7 +42,7 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Enabled( } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() string { +func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Severity() tflint.Severity { return tflint.ERROR } @@ -51,11 +53,24 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Link() s // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -63,13 +78,18 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidEvictionPolicyRule) Check(ru } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as eviction_policy`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_priority.go b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_priority.go index f589123e..da0a4ae7 100644 --- a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_priority.go +++ b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_priority.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule checks the pattern is valid type AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Enabled() bool } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Severity() string { +func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Link() string // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidPriorityRule) Check(runner t } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as priority`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_upgrade_mode.go b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_upgrade_mode.go index 7bd0ae7f..d22a4d05 100644 --- a/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_upgrade_mode.go +++ b/rules/apispec/azurerm_windows_virtual_machine_scale_set_invalid_upgrade_mode.go @@ -5,13 +5,15 @@ package apispec import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule checks the pattern is valid type AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule struct { + tflint.DefaultRule + resourceType string attributeName string enum []string @@ -41,7 +43,7 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Enabled() b } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Severity() string { +func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -52,11 +54,24 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Link() stri // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range r.enum { if item == val { @@ -64,13 +79,18 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidUpgradeModeRule) Check(runne } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as upgrade_mode`, truncateLongMessage(val)), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/azurerm_linux_virtual_machine_invalid_size.go b/rules/azurerm_linux_virtual_machine_invalid_size.go index bb28d43b..14bc8617 100644 --- a/rules/azurerm_linux_virtual_machine_invalid_size.go +++ b/rules/azurerm_linux_virtual_machine_invalid_size.go @@ -3,13 +3,15 @@ package rules import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineInvalidSizeRule checks the pattern is valid type AzurermLinuxVirtualMachineInvalidSizeRule struct { + tflint.DefaultRule + resourceType string attributeName string } @@ -33,7 +35,7 @@ func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Severity() string { +func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -44,11 +46,23 @@ func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Link() string { // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range validMachineSizes { if item == val { @@ -56,13 +70,18 @@ func (r *AzurermLinuxVirtualMachineInvalidSizeRule) Check(runner tflint.Runner) } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as size`, val), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/azurerm_linux_virtual_machine_scale_set_invalid_sku.go b/rules/azurerm_linux_virtual_machine_scale_set_invalid_sku.go index d6a8fee5..508e6c12 100644 --- a/rules/azurerm_linux_virtual_machine_scale_set_invalid_sku.go +++ b/rules/azurerm_linux_virtual_machine_scale_set_invalid_sku.go @@ -3,13 +3,15 @@ package rules import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermLinuxVirtualMachineScaleSetInvalidSkuRule checks the pattern is valid type AzurermLinuxVirtualMachineScaleSetInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string } @@ -33,7 +35,7 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Severity() string { +func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -44,11 +46,23 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range validMachineSizes { if item == val { @@ -56,13 +70,18 @@ func (r *AzurermLinuxVirtualMachineScaleSetInvalidSkuRule) Check(runner tflint.R } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, val), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/azurerm_virtual_machine_invalid_vm_size.go b/rules/azurerm_virtual_machine_invalid_vm_size.go index 108cbefc..e8560276 100644 --- a/rules/azurerm_virtual_machine_invalid_vm_size.go +++ b/rules/azurerm_virtual_machine_invalid_vm_size.go @@ -3,13 +3,15 @@ package rules import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermVirtualMachineInvalidVMSizeRule checks the pattern is valid type AzurermVirtualMachineInvalidVMSizeRule struct { + tflint.DefaultRule + resourceType string attributeName string } @@ -33,7 +35,7 @@ func (r *AzurermVirtualMachineInvalidVMSizeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermVirtualMachineInvalidVMSizeRule) Severity() string { +func (r *AzurermVirtualMachineInvalidVMSizeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -44,11 +46,23 @@ func (r *AzurermVirtualMachineInvalidVMSizeRule) Link() string { // Check checks the pattern is valid func (r *AzurermVirtualMachineInvalidVMSizeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range validMachineSizes { if item == val { @@ -56,13 +70,18 @@ func (r *AzurermVirtualMachineInvalidVMSizeRule) Check(runner tflint.Runner) err } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as vm_size`, val), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/azurerm_windows_virtual_machine_invalid_size.go b/rules/azurerm_windows_virtual_machine_invalid_size.go index 598006a6..48d2b008 100644 --- a/rules/azurerm_windows_virtual_machine_invalid_size.go +++ b/rules/azurerm_windows_virtual_machine_invalid_size.go @@ -3,13 +3,15 @@ package rules import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineInvalidSizeRule checks the pattern is valid type AzurermWindowsVirtualMachineInvalidSizeRule struct { + tflint.DefaultRule + resourceType string attributeName string } @@ -33,7 +35,7 @@ func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Severity() string { +func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Severity() tflint.Severity { return tflint.ERROR } @@ -44,11 +46,23 @@ func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Link() string { // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range validMachineSizes { if item == val { @@ -56,13 +70,18 @@ func (r *AzurermWindowsVirtualMachineInvalidSizeRule) Check(runner tflint.Runner } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as size`, val), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/rules/azurerm_windows_virtual_machine_scale_set_invalid_sku.go b/rules/azurerm_windows_virtual_machine_scale_set_invalid_sku.go index bf4f43de..cb1285f1 100644 --- a/rules/azurerm_windows_virtual_machine_scale_set_invalid_sku.go +++ b/rules/azurerm_windows_virtual_machine_scale_set_invalid_sku.go @@ -3,13 +3,15 @@ package rules import ( "fmt" - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // AzurermWindowsVirtualMachineScaleSetInvalidSkuRule checks the pattern is valid type AzurermWindowsVirtualMachineScaleSetInvalidSkuRule struct { + tflint.DefaultRule + resourceType string attributeName string } @@ -33,7 +35,7 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Enabled() bool { } // Severity returns the rule severity -func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Severity() string { +func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Severity() tflint.Severity { return tflint.ERROR } @@ -44,11 +46,23 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Link() string { // Check checks the pattern is valid func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{{Name: r.attributeName}}, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + var val string err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { found := false for _, item := range validMachineSizes { if item == val { @@ -56,13 +70,18 @@ func (r *AzurermWindowsVirtualMachineScaleSetInvalidSkuRule) Check(runner tflint } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, fmt.Sprintf(`"%s" is an invalid value as sku`, val), - attribute.Expr, + attribute.Expr.Range(), ) } return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/tools/apispec-rule-gen/rule.go.tmpl b/tools/apispec-rule-gen/rule.go.tmpl index 7226eedb..897020b9 100644 --- a/tools/apispec-rule-gen/rule.go.tmpl +++ b/tools/apispec-rule-gen/rule.go.tmpl @@ -10,13 +10,15 @@ import ( "regexp" {{- end }} - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // {{ .RuleNameCC }}Rule checks the pattern is valid type {{ .RuleNameCC }}Rule struct { + tflint.DefaultRule + resourceType string attributeName string {{- if .SetMax }} @@ -68,7 +70,7 @@ func (r *{{ .RuleNameCC }}Rule) Enabled() bool { } // Severity returns the rule severity -func (r *{{ .RuleNameCC }}Rule) Severity() string { +func (r *{{ .RuleNameCC }}Rule) Severity() tflint.Severity { return tflint.ERROR } @@ -79,7 +81,21 @@ func (r *{{ .RuleNameCC }}Rule) Link() string { // Check checks the pattern is valid func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { - return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + attribute, exists := resource.Body.Attributes[r.attributeName] + if !exists { + continue + } + {{- if (or (.SetMax) (.SetMin)) }} var val int {{- else }} @@ -87,37 +103,37 @@ func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { {{- end }} err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { {{- if .SetMax }} if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "{{ .AttributeName }} must be {{ .Max }} or less", - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} {{- if .SetMin }} if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "{{ .AttributeName }} must be {{ .Min }} or higher", - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} {{- if ne .Pattern "" }} if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, {{- if .Sensitive }} `{{ .AttributeName }} does not match valid pattern {{ .Pattern }}`, {{- else }} fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `{{ .Pattern }}`), {{- end }} - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} @@ -130,18 +146,23 @@ func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, {{- if .Sensitive }} `{{ .AttributeName }} is an invalid value`, {{- else }} fmt.Sprintf(`"%s" is an invalid value as {{ .AttributeName }}`, truncateLongMessage(val)), {{- end }} - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} return nil }) - }) + if err != nil { + return err + } + } + + return nil } diff --git a/tools/apispec-rule-gen/rule_block.go.tmpl b/tools/apispec-rule-gen/rule_block.go.tmpl index 3970ab37..c9ebf2ff 100644 --- a/tools/apispec-rule-gen/rule_block.go.tmpl +++ b/tools/apispec-rule-gen/rule_block.go.tmpl @@ -8,13 +8,15 @@ import ( "regexp" {{- end }} - hcl "github.com/hashicorp/hcl/v2" + "github.com/terraform-linters/tflint-plugin-sdk/hclext" "github.com/terraform-linters/tflint-plugin-sdk/tflint" "github.com/terraform-linters/tflint-ruleset-azurerm/project" ) // {{ .RuleNameCC }}Rule checks the pattern is valid type {{ .RuleNameCC }}Rule struct { + tflint.DefaultRule + resourceType string blockType string attributeName string @@ -68,7 +70,7 @@ func (r *{{ .RuleNameCC }}Rule) Enabled() bool { } // Severity returns the rule severity -func (r *{{ .RuleNameCC }}Rule) Severity() string { +func (r *{{ .RuleNameCC }}Rule) Severity() tflint.Severity { return tflint.ERROR } @@ -79,17 +81,29 @@ func (r *{{ .RuleNameCC }}Rule) Link() string { // Check checks whether ... func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { - return runner.WalkResourceBlocks(r.resourceType, r.blockType, func(block *hcl.Block) error { - content, _, diags := block.Body.PartialContent(&hcl.BodySchema{ - Attributes: []hcl.AttributeSchema{ - {Name: r.attributeName}, + resources, err := runner.GetResourceContent(r.resourceType, &hclext.BodySchema{ + Blocks: []hclext.BlockSchema{ + { + Type: r.blockType, + Body: &hclext.BodySchema{ + Attributes: []hclext.AttributeSchema{ + {Name: r.attributeName}, + }, + }, }, - }) - if diags.HasErrors() { - return diags - } + }, + }, nil) + if err != nil { + return err + } + + for _, resource := range resources.Blocks { + for _, inner := range resource.Body.Blocks { + attribute, exists := inner.Body.Attributes[r.attributeName] + if !exists { + continue + } - if attribute, exists := content.Attributes[r.attributeName]; exists { {{- if (or (.SetMax) (.SetMin)) }} var val int {{- else }} @@ -97,37 +111,37 @@ func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { {{- end }} err := runner.EvaluateExpr(attribute.Expr, &val, nil) - return runner.EnsureNoError(err, func() error { + err = runner.EnsureNoError(err, func() error { {{- if .SetMax }} if val > r.max { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "{{ .AttributeName }} must be {{ .Max }} or less", - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} {{- if .SetMin }} if val < r.min { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, "{{ .AttributeName }} must be {{ .Min }} or higher", - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} {{- if ne .Pattern "" }} if !r.pattern.MatchString(val) { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, {{- if .Sensitive }} `{{ .AttributeName }} does not match valid pattern {{ .Pattern }}`, {{- else }} fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `{{ .Pattern }}`), {{- end }} - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} @@ -140,21 +154,24 @@ func (r *{{ .RuleNameCC }}Rule) Check(runner tflint.Runner) error { } } if !found { - runner.EmitIssueOnExpr( + runner.EmitIssue( r, {{- if .Sensitive }} `{{ .AttributeName }} is an invalid value`, {{- else }} fmt.Sprintf(`"%s" is an invalid value as {{ .AttributeName }}`, truncateLongMessage(val)), {{- end }} - attribute.Expr, + attribute.Expr.Range(), ) } {{- end }} return nil }) + if err != nil { + return err + } } + } - return nil - }) + return nil }