Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http 400 code BadRequest error while trying to update tags on azurerm_notification_hub #23043

Open
1 task done
rem-aj opened this issue Aug 22, 2023 · 4 comments
Open
1 task done

Comments

@rem-aj
Copy link

rem-aj commented Aug 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.0.8

AzureRM Provider Version

3.39.0

Affected Resource(s)/Data Source(s)

azurerm_notification_hub_namespace

Terraform Configuration Files

resource "azurerm_notification_hub_namespace" "hub_ns" {
  name = format(
    "%spsc-%snotif-hub-ns",
    var.region_codes[var.location],
    substr(var.environment, 0, 1),
  )
  resource_group_name = var.resource_group
  location            = var.location
  namespace_type      = var.hubnotification_namespacetype
  sku_name            = var.hubnotification_sku
  tags = merge(
    var.common_tags,
    {
      "Role" = "Notification Hub Namespace"
    },
  )
  # https://github.com/hashicorp/terraform-provider-azurerm/issues/14541 and
  # https://github.com/Azure/azure-rest-api-specs/issues/17277
  # Azure API is not returning the namespace_type, so terraform keeps wanting to add it.
  lifecycle {
    ignore_changes = [
      namespace_type
    ]
  }
}


The corresponding plan looks like this

~ update in-place

Terraform will perform the following actions:

  # module.namespacehub.azurerm_notification_hub.staging_psc will be updated in-place
  ~ resource "azurerm_notification_hub" "staging_psc" {
        id                  = "/subscriptions/XXXXXXXXXX/resourceGroups/UE2pscDcommon/providers/Microsoft.NotificationHubs/namespaces/ue2psc-dnotif-hub-ns/notificationHubs/ue2psc-dnotif-hub"
        name                = "ue2psc-dnotif-hub"
      ~ tags                = {
          + "businesscontact" = "XXXXXX"
          + "engcontact"      = "XXXXXX"
          + "project"         = "XXXXXX"
            # (4 unchanged elements hidden)
        }
        # (3 unchanged attributes hidden)

      - timeouts {}

        # (2 unchanged blocks hidden)
    }

Debug Output/Panic Output

module.namespacehub.azurerm_notification_hub_namespace.hub_ns: Modifying... 
╷
│ Error: creating/updating Namespace (Subscription: "XXXXXXXX"
│ Resource Group Name: "UE2pscDcommon"
│ Namespace Name: "ue2psc-dnotif-hub-ns"): namespaces.NamespacesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="The JSON value could not be converted to System.Nullable`1[Microsoft.NotificationHubs.Contracts.Arm.NamespaceType]. Path: $.properties.namespaceType | LineNumber: 0 | BytePositionInLine: 69."

│   with module.namespacehub.azurerm_notification_hub_namespace.hub_ns,
│   on ../modules/namespace_hub/main.tf line 1, in resource "azurerm_notification_hub_namespace" "hub_ns":
│    1: resource "azurerm_notification_hub_namespace" "hub_ns" {

Expected Behaviour

The code change was one line invoking a terraform module to add a new set of tags to to common_tags variable

common_tags = merge(var.common_tags, local.project_tags_essentials)

All should have happened is that the 2 extra value tags should have been merged with common_tags variable and the notification would then contain a couple of extra tags.

Actual Behaviour

module.namespacehub.azurerm_notification_hub_namespace.hub_ns: Modifying...

│ Error: creating/updating Namespace (Subscription: "XXXXXXXX"
│ Resource Group Name: "UE2pscDcommon"
│ Namespace Name: "ue2psc-dnotif-hub-ns"): namespaces.NamespacesClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="The JSON value could not be converted to System.Nullable`1[Microsoft.NotificationHubs.Contracts.Arm.NamespaceType]. Path: $.properties.namespaceType | LineNumber: 0 | BytePositionInLine: 69."

│ with module.namespacehub.azurerm_notification_hub_namespace.hub_ns,
│ on ../modules/namespace_hub/main.tf line 1, in resource "azurerm_notification_hub_namespace" "hub_ns":
│ 1: resource "azurerm_notification_hub_namespace" "hub_ns" {

Steps to Reproduce

Create a notification hub with a set of tags, try to append extra tags to those existing tags.

Important Factoids

No response

References

No response

@sinbai
Copy link
Contributor

sinbai commented Aug 23, 2023

Hi @rem-aj thanks for opening this issue. Could you please provide the value of namespace_type while updating the tags of azurerm_notification_hub? Also, Since I could not reproduce this issue using the following tf config and steps, is it possible to provide the repro steps and terraform log to help reproduce/troubleshoot ?

  1. Create a notification hub with the following tf config.
provider "azurerm" {
  features {}
}

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.39.0"
    }
  }
}
resource "azurerm_resource_group" "test" {
  name     = "acctestRGpol-0823"
  location = "eastus"
}

resource "azurerm_notification_hub_namespace" "test" {
  name                = "acctestnhn-0823"
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location
  namespace_type      = "NotificationHub"
  sku_name            = "Free"
}

resource "azurerm_notification_hub" "test" {
  name                = "acctestnh-0823"
  namespace_name      = azurerm_notification_hub_namespace.test.name
  resource_group_name = azurerm_resource_group.test.name
  location            = azurerm_resource_group.test.location

  tags = {
    env = "Test"
  }
}
  1. Update tags of azurerm_notification_hub with follows, then run terraform apply
  tags = {
    env = "Test"
    engcontact = "test2"
  }

Result:

image

@rem-aj
Copy link
Author

rem-aj commented Aug 24, 2023

Hi @sinbai here's the value of the namespace type.

"NotificationHub"

By the way this value was already there, it wasn't added as part of this change, this change was simply a tag update. I provided the error logs earlier, are you looking for something different?

Thanks!

@rem-aj rem-aj changed the title Http 400 code BadRequest error while trying to update tags on azurerm_notification_hub_namespace Http 400 code BadRequest error while trying to update tags on azurerm_notification_hub Aug 24, 2023
@sinbai
Copy link
Contributor

sinbai commented Aug 24, 2023

Hi @rem-aj thanks for the reply. Per the provided error logs, It seems that the value of namespace_type that is actually passed to the API is not "NotificationHub". So, is it possible to provide the Terraform Log to help with troubleshooting? Also, could you reproduce this issue with the tf configuration and steps I provided above?

@rem-aj
Copy link
Author

rem-aj commented Aug 24, 2023

Hi @sinbai if you observe the comments in the code, the namespace attribute is actually set to be ignored using lifecycle flag due to the github issues mentioned there which I will post again below. These issues have not been resolved, so by using ignore lifecycle we are able to workaround those specific issues.

#14541 and

Azure/azure-rest-api-specs#17277

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants