No data was found for preview

Exie 6 Reputation points
2021-07-02T11:43:13.493+00:00

Using terraform, I've created an IoT hub and a Stream analytics job.

The input verifies correctly, the IoT hub shows data coming in.
111364-screen-shot-2021-07-02-at-93544-pm.png

However when I select Query to test my streaming job, it always says there is no data available in the input.
111385-image.png

When I manually created everything via the UI, it was working. So I am confident the JSON payload is correct and the device is registered correctly.

What am I missing ?

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,133 questions
Azure Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
333 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Exie 6 Reputation points
    2021-07-02T12:02:21.957+00:00

    Here's the terraform script to show what I've configured so far.

    # Configure the Azure provider
    terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "~> 2.65"
        }
      }
    
      required_version = ">= 0.14.9"
    }
    
    provider "azurerm" {
      features {}
    }
    
    locals {
      tags = {
        Owner  = "Me"
      }
    }
    
    //--------------------------------------
    //  Resource Group
    //
    resource "azurerm_resource_group" "rg" {
      name     = "MyRG"
      location = "australiaeast"
      tags = local.tags
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    }
    
    //--------------------------------------
    //  IoT Hub
    //
    resource "azurerm_iothub" "iothub" {
      name                = "My-IoTHub"
      resource_group_name = azurerm_resource_group.rg.name
      location            = azurerm_resource_group.rg.location
    
      sku {
        name     = "B1"
        capacity = "1"
      }
    
      tags = local.tags
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    }
    
    //--------------------------------------
    //  Database Server
    //
    resource "azurerm_mssql_server" "sqlserver" {
      name                         = "my-sql-server"
      resource_group_name          = azurerm_resource_group.rg.name
      location                     = azurerm_resource_group.rg.location
      version                      = "12.0"
      administrator_login          = var.administrator_login
      administrator_login_password = var.administrator_password
      minimum_tls_version          = "1.2"
    
      tags = local.tags
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    }
    
    resource "azurerm_mssql_firewall_rule" "example" {
      name             = "FirewallRule1"
      server_id        = azurerm_mssql_server.sqlserver.id
      start_ip_address = "0.0.0.0"
      end_ip_address   = "0.0.0.0"
    }
    
    //--------------------------------------
    //  Database
    //
    resource "azurerm_mssql_database" "database" {
      name           = "my-db"
      server_id      = azurerm_mssql_server.sqlserver.id
      collation      = "SQL_Latin1_General_CP1_CI_AS"
      max_size_gb    = 1
      read_scale     = false
      sku_name       = "Basic"
      zone_redundant = false
    
      tags = local.tags
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    }
    
    //--------------------------------------
    //  Streaming job - Output (to database)
    //
    resource "azurerm_stream_analytics_output_mssql" "output" {
      name                      = "my-job-output"
      stream_analytics_job_name = azurerm_stream_analytics_job.iot-to-db.name
      resource_group_name       = azurerm_stream_analytics_job.iot-to-db.resource_group_name
    
      server   = azurerm_mssql_server.sqlserver.fully_qualified_domain_name
      user     = azurerm_mssql_server.sqlserver.administrator_login
      password = azurerm_mssql_server.sqlserver.administrator_login_password
      database = azurerm_mssql_database.database.name
      table    = "MyTable"
    }
    
    //--------------------------------------
    //  Streaming job - Input (from MQTT)
    //
    resource "azurerm_stream_analytics_stream_input_iothub" "input" {
      name                         = "my-input"
      stream_analytics_job_name    = azurerm_stream_analytics_job.iot-to-db.name
      resource_group_name          = azurerm_stream_analytics_job.iot-to-db.resource_group_name
      endpoint                     = "messages/events"
      eventhub_consumer_group_name = "$Default"
      iothub_namespace             = azurerm_iothub.iothub.name
      shared_access_policy_key     = azurerm_iothub.iothub.shared_access_policy[0].primary_key
      shared_access_policy_name    = "iothubowner"
    
      serialization {
        type     = "Json"
        encoding = "UTF8"
      }
    }
    
    //--------------------------------------
    //  Streaming job
    //
    resource "azurerm_stream_analytics_job" "my-job" {
      name                                     = "my-job"
      resource_group_name                      = azurerm_resource_group.rg.name
      location                                 = azurerm_resource_group.rg.location
      compatibility_level                      = "1.2"
      data_locale                              = "en-AU"
      events_late_arrival_max_delay_in_seconds = 60
      events_out_of_order_max_delay_in_seconds = 50
      events_out_of_order_policy               = "Adjust"
      output_error_policy                      = "Stop"
      streaming_units                          = 1
    
      tags = local.tags
      lifecycle {
        ignore_changes = [
          tags
        ]
      }
    
      transformation_query = <<QUERY
        SELECT *
        INTO [output]
        FROM [input]
    QUERY
    
    }
    
    0 comments No comments

  2. HimanshuSinha-msft 19,381 Reputation points Microsoft Employee
    2021-07-02T22:41:29.387+00:00

    Hello @Exie ,
    Thanks for the ask and using the Microsoft Q&A platform .
    I am not terrform literate but then I have a hypothesis that may the message coming in are having a different serialization format . At this time its is set to

    serialization {
    type = "Json"
    encoding = "UTF8"
    }

    This what i tried on my side I have a working ASA with EH with serialization format as JSON , I update the serialization of somethig else . The message stopped showing up on the ASA query .

    You can test serialization from the portal UI .

    111436-image.png

    Please do let me know how it goes .
    Thanks
    Himanshu
    Please do consider clicking on "Accept Answer" and "Up-vote" on the post that helps you, as it can be beneficial to other community members


  3. Bilal Malik 1 Reputation point
    2021-12-30T14:49:26.763+00:00

    @Exie did you find the solution, if yes please share here, I am also facing the same issue via terraform