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.61k stars 4.65k forks source link

[azurerm_iothub] IoTHub provisioning not possible with version 1.42.0 #5609

Closed tobiasschueler closed 4 years ago

tobiasschueler commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform 0.12.20 azurerm 1.42.0

Affected Resource(s)

Terraform Configuration Files

resource "azurerm_iothub" "iothub" {
  name                = local.iothub-name
  resource_group_name = azurerm_resource_group.iothub.name
  location            = azurerm_resource_group.iothub.location

  sku {
    name     = "S1"
    capacity = "1"
  }

  endpoint {
    type                       = "AzureIotHub.StorageContainer"
    connection_string          = azurerm_storage_account.vaillantiothub.primary_blob_connection_string
    name                       = "cold-storage"
    batch_frequency_in_seconds = 60
    max_chunk_size_in_bytes    = 104857600
    container_name             = azurerm_storage_container.iothub.name
    file_name_format           = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"
    encoding                   = "Avro"
  }

  endpoint {
    type              = "AzureIotHub.EventHub"
    connection_string = azurerm_eventhub_authorization_rule.eventhubauth.primary_connection_string
    name              = "iot-eventhub"
  }

  route {
    name           = "eventhub-queue"
    source         = "DeviceMessages"
    condition      = "true"
    endpoint_names = ["iot-eventhub"]
    enabled        = true
  }

  route {
    name           = "device-twin-changed-eventhub-queue"
    source         = "TwinChangeEvents"
    condition      = "true"
    endpoint_names = ["iot-eventhub"]
    enabled        = true
  }

  route {
    name           = "cold-storage"
    source         = "DeviceMessages"
    condition      = "true"
    endpoint_names = ["cold-storage"]
    enabled        = true
  }

  tags = {
    purpose = var.namespace
    owner = local.tags-owner
  }
}

Expected Behavior

Actual Behavior

While updating the ressource, an API error appears: Error: Error creating/updating IotHub "vg-iothub-dev" (Resource Group "iothub-dev"): devices.IotHubResourceClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="Failed" Message="The async operation failed." InnerError={"unmarshalError":"json: cannot unmarshal number into Go struct field serviceError2.code of type string"} AdditionalInfo=[{"code":404010,"httpStatusCode":"NotFound","message":"Default eventHub endpoint 'operationsMonitoringEvents' is missing from the EventHub Endpoints. If you contact a support representative please include this correlation identifier: ea2ef0f2-87e9-44d2-bae5-f0b940640841, timestamp: 2020-02-04 09:16:59Z, errorcode: IH404010."}]

Steps to Reproduce

  1. terraform apply

Important Factoids

Azure Germany, location westeurope.

Own Investigations

The operationsMonitoringEvents endpoint is no longer supported by Azure (03/2019). It seems that the provider is using an outdated API to create/updating IoTHub ressources.

hassant commented 4 years ago

failing back to working version azurerm 1.41.0 for iothub

tobiasschueler commented 4 years ago

Fallback to azurerm 1.41.0 or to azurerm 1.40.0 did not work as well, same error.

hassant commented 4 years ago

I tested with 1.40.0 and later 1.41.0 both worked deploying against existing iothub as well as creating new...

tobiasschueler commented 4 years ago

Okay, get it working too with 1.41.0. But it should be fixed in a future version as well.

KamalAman commented 4 years ago

I am experiencing the same issue updating iot hub with provider azurerm 2.3.0 as well.

mluker commented 4 years ago

I am experiencing the same issue updating iot hub with provider azurerm 2.1.0

mguirao commented 4 years ago

With provider 2.6.0 initial deployment is ok but any update produce the same error.

maxbog commented 4 years ago

Is anybody working on this? This bug basically breaks the provider when using iothub

mguirao commented 4 years ago

I've open a separate issue for version 2.x few weeks ago : https://github.com/terraform-providers/terraform-provider-azurerm/issues/6595 My PR that fix this using the latest api version was merged, so it should be good in 2.10

neil-yechenwei commented 4 years ago

Thanks for opening this issue. I assume this issue has been fixed since I cannot repro it with latest azurerm and below tfconfig. Could you have a try to check whether the issue still exists? Thanks.

First apply:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-iothub-test03"
  location = "eastus2"
}

resource "azurerm_storage_account" "test" {
  name                     = "acctestsatest03"
  resource_group_name      = azurerm_resource_group.test.name
  location                 = azurerm_resource_group.test.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_container" "test" {
  name                  = "testsc03"
  storage_account_name  = azurerm_storage_account.test.name
  container_access_type = "private"
}

resource "azurerm_eventhub_namespace" "test" {
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  name                = "acctest-test03"
  sku                 = "Basic"
}

resource "azurerm_eventhub" "test" {
  name                = "acctest03"
  resource_group_name = azurerm_resource_group.test.name
  namespace_name      = azurerm_eventhub_namespace.test.name
  partition_count     = 2
  message_retention   = 1
}

resource "azurerm_eventhub_authorization_rule" "test" {
  resource_group_name = azurerm_resource_group.test.name
  namespace_name      = azurerm_eventhub_namespace.test.name
  eventhub_name       = azurerm_eventhub.test.name
  name                = "acctest"
  send                = true
}

resource "azurerm_iothub" "test" {
  name                = "acctestIoTHub-test03"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location

  sku {
    name     = "S1"
    capacity = "1"
  }

  event_hub_retention_in_days = 7
  event_hub_partition_count   = 77

  endpoint {
    type                       = "AzureIotHub.StorageContainer"
    connection_string          = azurerm_storage_account.test.primary_blob_connection_string
    name                       = "export"
    batch_frequency_in_seconds = 60
    max_chunk_size_in_bytes    = 10485760
    container_name             = azurerm_storage_container.test.name
    encoding                   = "Avro"
    file_name_format           = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"
  }

  endpoint {
    type              = "AzureIotHub.EventHub"
    connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string
    name              = "export2"
  }

  route {
    name           = "export"
    source         = "DeviceMessages"
    condition      = "true"
    endpoint_names = ["export"]
    enabled        = true
  }

  route {
    name           = "device-twin-changed-eventhub-queue"
    source         = "TwinChangeEvents"
    condition      = "true"
    endpoint_names = ["export2"]
    enabled        = true
  }

  route {
    name           = "export2"
    source         = "DeviceMessages"
    condition      = "true"
    endpoint_names = ["export2"]
    enabled        = true
  }

  file_upload {
    connection_string  = azurerm_storage_account.test.primary_blob_connection_string
    container_name     = azurerm_storage_container.test.name
    notifications      = true
    max_delivery_count = 12
    sas_ttl            = "PT2H"
    default_ttl        = "PT3H"
    lock_duration      = "PT5M"
  }

  tags = {
    purpose = "testing"
  }
}

Second apply:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-iothub-test03"
  location = "eastus2"
}

resource "azurerm_storage_account" "test" {
  name                     = "acctestsatest03"
  resource_group_name      = azurerm_resource_group.test.name
  location                 = azurerm_resource_group.test.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_container" "test" {
  name                  = "testsc03"
  storage_account_name  = azurerm_storage_account.test.name
  container_access_type = "private"
}

resource "azurerm_eventhub_namespace" "test" {
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  name                = "acctest-test03"
  sku                 = "Basic"
}

resource "azurerm_eventhub" "test" {
  name                = "acctest03"
  resource_group_name = azurerm_resource_group.test.name
  namespace_name      = azurerm_eventhub_namespace.test.name
  partition_count     = 2
  message_retention   = 1
}

resource "azurerm_eventhub_authorization_rule" "test" {
  resource_group_name = azurerm_resource_group.test.name
  namespace_name      = azurerm_eventhub_namespace.test.name
  eventhub_name       = azurerm_eventhub.test.name
  name                = "acctest"
  send                = true
}

resource "azurerm_iothub" "test" {
  name                = "acctestIoTHub-test03"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location

  sku {
    name     = "S1"
    capacity = "1"
  }

  event_hub_retention_in_days = 7
  event_hub_partition_count   = 77

  endpoint {
    type                       = "AzureIotHub.StorageContainer"
    connection_string          = azurerm_storage_account.test.primary_blob_connection_string
    name                       = "export"
    batch_frequency_in_seconds = 60
    max_chunk_size_in_bytes    = 10485760
    container_name             = azurerm_storage_container.test.name
    encoding                   = "Avro"
    file_name_format           = "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"
  }

  endpoint {
    type              = "AzureIotHub.EventHub"
    connection_string = azurerm_eventhub_authorization_rule.test.primary_connection_string
    name              = "export2"
  }

  route {
    name           = "device-twin-changed-eventhub-queue"
    source         = "TwinChangeEvents"
    condition      = "true"
    endpoint_names = ["export2"]
    enabled        = true
  }

  tags = {
    purpose = "testing"
  }
}
tombuildsstuff commented 4 years ago

👋

Since we've not heard back from you here I'm going to close this issue for the moment - but please let us know if you're able to take a look at the comment above and confirm if this is still an issue and we'll take another look.

Thanks!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!