favoretti / terraform-provider-adx

Mozilla Public License 2.0
14 stars 5 forks source link

Error refreshing resource state in v0.0.14 #20

Closed andrewmcharg closed 1 year ago

andrewmcharg commented 1 year ago

After upgrading from v0.0.13 to v0.0.14 of the provider, the following error occurs when Terraform attempts to refresh the state of the resource:


Error: error checking if table exists in database (logs): error executing adx mgmt query(.show tables (Table1) details) database("logs"): Op(OpMgmt): Kind(KHTTPError): error from Kusto endpoint for query ".show tables (Table1) details": (400 BadRequest):

{

    "error": {

        "code": "BadRequest_SyntaxError",

        "message": "Request is invalid and cannot be executed.",

        "@type": "Kusto.Data.Exceptions.SyntaxException",

        "@message": "Syntax error: ",

        "@context": {

            "timestamp": "2022-11-22T11:07:58.2751522Z",

            "serviceAlias": "INGEST-[ClusterName]",

            "machineName": "KDATAMANA000000",

            "processName": "Kusto.WinSvc.DM.Svc",

            "processId": 5852,

            "threadId": 7232,

            "clientRequestId": "KGC.execute;560145ce-b45b-4ca3-868e-b3a4fefe76de",

            "activityId": "08a04356-b476-42a1-b763-80012f8e12b5",

            "subActivityId": "89b78ea7-2e41-429d-9a63-d79583daf154",

            "activityType": "P.Grpc.Service.ExecuteControlCommand2",

            "parentActivityId": "77d375ce-290b-4930-9fd7-1f8182389c25",

            "activityStack": "(Activity stack: CRID=<null> ARID=9248b07c-b484-417c-913f-db161d2b2296 > WinSvc.OnStart/9248b07c-b484-417c-913f-db161d2b2296 > DN.Admin.Client.ExecuteControlCommand/77d375ce-290b-4930-9fd7-1f8182389c25 > P.Grpc.Service.ExecuteControlCommand2/89b78ea7-2e41-429d-9a63-d79583daf154)"

        },

        "@permanent": true

    }

}

I've tried using TF_LOG='TRACE' but the provider doesn't seem to surface any additional (useful) logs with this set. Looking at the serviceAlias line it seems as though the Ingest URL is being used here instead of the Cluster URL, causing the control command to fail?

slwbuild commented 1 year ago

Hi andrewmcharg, thanks for submitting this. I agree "INGEST-[ClusterName]" is a strange serviceAlias.

Can you let me know a bit more about how you are configuring the provider and defining the table? Some code examples would be very useful in reproducing this one.

andrewmcharg commented 1 year ago

Hi @slwbuild, Just to be clear [ClusterName] was me sanitising the log to remove our cluster name!

The provider is configured by setting ADX_CLIENT_ID, ADX_CLIENT_SECRET and ADX_TENANT_ID as environment variables. The adx_endpoint is set inside the provider block in Terraform:

locals {
  kusto_cluster_name = "our0cluster0name"
  adx_url            = "https://private-${local.kusto_cluster_name}.ukwest.kusto.windows.net"
}

provider "adx" {
  adx_endpoint = local.adx_url
}

The table is defined in HCL:

resource "adx_table" "raw" {
  name          = "Table1Raw"
  database_name = azurerm_kusto_database.main.name

  column {
    name = "Records"
    type = "dynamic"
  }
}
slwbuild commented 1 year ago

I've confirmed that sending a .show command to the ingestion endpoint results in a syntax exception like you are seeing. Also the exception contained machine name "KDATAMANA000000" which should be something like "KCOMPUTE000000"

Nothing within the v0.0.14 upgrade should have caused your connections to be made to the ingestion endpoint instead of compute.

Can you post some additional details about your network setup?

  1. Are you using private endpoints w/ private DNS zones and what is their configuration?
  2. Are you using a vnet-injected or managed-vnet cluster?
  3. Have you tried using the non-private endpoint url? https://${local.kusto_cluster_name}.ukwest.kusto.windows.net
andrewmcharg commented 1 year ago

@slwbuild, fixed this by using the public endpoint URL, thanks for your help!