hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.5k stars 4.59k forks source link

eventhub_namespace public_network_access_enabled not working as documented #18678

Open Gerrit-K opened 1 year ago

Gerrit-K commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.2

AzureRM Provider Version

3.26.0

Affected Resource(s)/Data Source(s)

azurerm_eventhub_namespace

Terraform Configuration Files

"azurerm_eventhub_namespace": {
      "eventhub_namespace": {
        "auto_inflate_enabled": false,
        "capacity": 1,
        "lifecycle": {
          "ignore_changes": [
            "tags"
          ]
        },
        "location": "${var.location}",
        "maximum_throughput_units": 0,
        "name": "[REDACTED]",
        "network_rulesets": [
          {
            "default_action": "Deny",
            "ip_rule": [
              {
                "action": "Allow",
                "ip_mask": "[REDACTED]"
              }
            ],
            "trusted_service_access_enabled": null,
            "virtual_network_rule": null
          }
        ],
        "resource_group_name": "${var.resource_group_name}",
        "sku": "Standard"
      }
    }

Debug Output/Panic Output

Error: Incorrect attribute value type

  on cdk.tf.json line 443, in resource.azurerm_eventhub_namespace.eventhub_namespace:
 443:         "network_rulesets": [
 444:           {
 445:             "default_action": "Deny",
 446:             "ip_rule": [
 459:               {
 460:                 "action": "Allow",
 461:                 "ip_mask": "[REDACTED]"
 462:               }
 463:             ],
 464:             "trusted_service_access_enabled": null,
 465:             "virtual_network_rule": null
 466:           }
 467:         ],

Inappropriate value for attribute "network_rulesets": element 0: attribute
"public_network_access_enabled" is required.

Expected Behaviour

No error, since the documentation states that public_network_access_enabled should be optional on both, the root resource and network_rulesets block levels.

Actual Behaviour

Error, see "Debug output".

Steps to Reproduce

No response

Important Factoids

No response

References

No response

xiaxyi commented 1 year ago

@Gerrit-K I didn't get any error about public_network_access_enabled property. The network config is created as what's defined in config. Can you share your tf config with me?

public_network_access_enabled is defined as optional + default and the default value is true. So, in theory, there won't be any error when creating the ehn.

Gerrit-K commented 1 year ago

@xiaxyi Thanks for your reply. I just played around with this a little bit and extracted an MRE from my (rather large and also partly confidential) tf file.

main.tf.json ```json { "provider": { "azurerm": [ { "features": { } } ] }, "resource": { "azurerm_resource_group": { "resource_group": { "location": "westeurope", "name": "testing-public-access" } }, "azurerm_eventhub_namespace": { "eventhub_namespace": { "auto_inflate_enabled": false, "capacity": 1, "lifecycle": { "ignore_changes": [ "tags" ] }, "location": "${azurerm_resource_group.resource_group.location}", "maximum_throughput_units": 0, "name": "${azurerm_resource_group.resource_group.name}", "network_rulesets": [ { "default_action": "Deny", "ip_rule": [ { "action": "Allow", "ip_mask": "1.2.3.4" } ], "trusted_service_access_enabled": null, "virtual_network_rule": null } ], "resource_group_name": "${azurerm_resource_group.resource_group.name}", "sku": "Standard" } } }, "terraform": { "required_providers": { "azurerm": { "source": "azurerm", "version": "3.26.0" } } } } ```

Some notes/observations:

sreekanth3107 commented 1 year ago

I am facing the same issue with latest version and i created a issues - 18485, followed with suggestions but still having same issues

Gerrit-K commented 1 year ago

@sreekanth3107 no I don't think your issue is connected to this one. Yes, it's the same property, but most likely it was just the wrong property name in your tf file. For me it works with a HCL (not JSON!) file and public_network_access_enabled.

thrubovc commented 1 year ago

this discrepancy between the documentation and azurerm provider behavior has been present since v3.21.0 edit: here's some HCL code from my eventhub_namespace resource

  network_rulesets = [
    {
      default_action                 = "Deny"
      trusted_service_access_enabled = false
      ip_rule                        = null
      virtual_network_rule           = null
    }
  ]

this is correctly configured according to the documentation, but as of v3.21.0, it no longer works. It works when I add public_network_access_enabled = null but that's not clear from the documentation. Or am I missing something?