VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

Errors displayed for conflicting resource attributes even if one of them is marked null #318

Closed 9numbernine9 closed 3 years ago

9numbernine9 commented 3 years ago

Prerequisites

Installation details

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 2.38.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  location = "East US"
  name     = "test"
}

resource "azurerm_network_security_group" "nsg" {
  name                = "test_nsg"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_network_security_rule" "rule" {
  access                      = "Deny"
  direction                   = "Inbound"
  name                        = "TestRule"
  network_security_group_name = azurerm_network_security_group.nsg.name
  priority                    = 1000
  protocol                    = "tcp"
  resource_group_name         = azurerm_resource_group.test.name

  source_port_range      = "*"
  destination_port_range = "*"
  source_address_prefix  = "*"

  # Here's where things go wrong - these will both be highlighted as being errors,
  # even if one of them is marked null and therefore doesn't really 'exist'.
  destination_address_prefix   = "10.0.0.100"
  destination_address_prefixes = null
}

Exception

None.

Expected Behavior

Actual Behavior

Two problems are listed in 'Problems' view:

Steps to Reproduce

  1. Place above sample code in an editor window.
  2. Observe red underlines. :smiley:

Hello!

I noticed a seemingly incorrect behaviour with the HCL plugin today. In cases where two attributes of a resource are mutually exclusive, the plugin will show those attributes as being in error even if one is marked null. In my example above, it's worth noting that terraform plan and terraform apply are fine with this configuration but the plugin thinks it's a problem.

In the example above, the azurerm_network_security_rule resource has several attribute pairs that are mutually exclusive and the same behaviour is observed for all of them:

Also, my usage of azurerm_network_security_rule above is a trivial example and should never be used this way. :smile: My actual use case is to conditionally use one of the attributes and mark the other one as null when not being used depending on the condition being evaluated.

Thanks for taking the time to read this!

VladRassokhin commented 3 years ago

Fixed in 0.7.13