Skip to content

Terraform import for Microsoft.Communication/communicationServices/smtpUsernames@2025-09-01 uses incorrect API version #1043

@trs1991

Description

@trs1991

When attempting to import a SMTP username resource the provider by default is trying to use an incorrect API version that doesn't exist for this resource which is api version 2025-05-01-preview:

terraform import 'azapi_resource.smtp_username[0]' "/subscriptions/[REDACTED]/resourceGroups/[REDACTED]/providers/Microsoft.Communication/communicationServices/[REDACTED]/smtpUsernames/smtp-user"

│ Error: Failed to retrieve resource
│
│ reading Resource: (ResourceId
│ "/subscriptions/[REDACTED]/resourceGroups/[REDACTED]/providers/Microsoft.Communication/communicationServices/[REDACTED]/smtpUsernames/smtp-user"
│ / Api Version "2025-05-01-preview"): GET
│https://management.azure.com/subscriptions/[REDACTED]/resourceGroups/[REDACTED]/providers/Microsoft.Communication/communicationServices/[REDACTED]/smtpUsernames/smtp-user"
│ --------------------------------------------------------------------------------
│ RESPONSE 400: 400 Bad Request
│ ERROR CODE: NoRegisteredProviderFound
│ --------------------------------------------------------------------------------
│ {
│   "error": {
│     "code": "NoRegisteredProviderFound",
│     "message": "No registered resource provider found for location 'global' and API version '2025-05-01-preview' for type 'CommunicationServices/SmtpUsernames'. The supported api-versions are '2024-09-01-preview, 2025-01-25-preview, 2025-09-01, 2025-09-01-preview'. The supported locations are 'global'."
│   }
│ }
│ --------------------------------------------------------------------------------

When passing in a valid API version, in this case 2025-09-01, the import is a success

terraform import 'azapi_resource.smtp_username[0]' "/subscriptions/[REDACTED]/resourceGroups/[REDACTED]/providers/Microsoft.Communication/communicationServices/[REDACTED]/smtpUsernames/smtp-user?api-version=2025-09-01"

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

This is the terraform code used for the import:

resource "azapi_resource" "smtp_username" {
  count                     = 1
  type                      = "Microsoft.Communication/communicationServices/smtpUsernames@2025-09-01"
  location                  = "global"
  parent_id                 = azurerm_communication_service.acs.id
  name                      = "smtp-user"
  schema_validation_enabled = false
  body = {
    properties = {
      entraApplicationId = azuread_application.app.client_id
      tenantId           = data.azurerm_client_config.current.tenant_id
      username           = "smtp"
    }
  }
  depends_on = [azurerm_email_communication_service_domain_sender_username.sender-username]
}

Ideally the import would use the latest stable version of the API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions