gpt4 book ai didi

azure - 解析 JSON 时出错 : invalid character 'Â' looking for beginning of value while creating azure data factory source dataset

转载 作者:行者123 更新时间:2023-12-03 06:56:51 24 4
gpt4 key购买 nike

我试图创建一个源数据集,该数据集应使用 terraform 指向数据湖第 2 代中的文件之一。我正在使用下面的 terraform 代码。

resource "azurerm_resource_group" "myresourcegroup" {
name = "${var.applicationName}-${var.environment}-rg"
location = var.location
tags = {
environment = var.environment
}
}

ADLS gen 2 的链接服务

resource "azurerm_data_factory_linked_custom_service" "storagels" {
name = "${var.applicationName}-${var.environment}-storagels"
data_factory_id = azurerm_data_factory.adf.id
type = "AzureBlobFS"
description = "storage connection linked service"
integration_runtime {
name = azurerm_data_factory_integration_runtime_self_hosted.ir.name
}
type_properties_json = <<JSON
{
"url": "https://cdfstagesrg.dfs.core.windows.net",
"accountKey": {
"type": "AzureKeyVaultSecret",
"store": {
"referenceName": "${azurerm_data_factory_linked_service_key_vault.akvls.name}",
"type": "LinkedServiceReference"
},
"secretName": "storageaccesskey"
}
},
"connectVia":{
"referenceName": "${azurerm_data_factory_integration_runtime_self_hosted.ir.name}",
"type": "IntegrationRuntimeReference"
}
JSON

depends_on = [azurerm_data_factory_integration_runtime_self_hosted.ir]
}

数据集创建

resource "azurerm_data_factory_custom_dataset" "datalakelookup" {
name = "${var.dataset_name}-datalakelkp"
data_factory_id = azurerm_data_factory.adf.id
type = "LinkedServiceReference"

linked_service {
name = "${var.applicationName}-${var.environment}-storagels"

}
type_properties_json = <<JSON
{
"properties": {
"linkedServiceName": {
"referenceName": "${var.applicationName}-${var.environment}-storagels",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "Excel",
"typeProperties": {
"sheetName": "Datalake",
"location": {
"type": "AzureBlobFSLocation",
"fileName": "tablesnames.xlsx",
"folderPath": "caseact/Input",
"fileSystem": "cdfstage"
},
"firstRowAsHeader": true
},
"schema": []
}
}
JSON

depends_on = [azurerm_resource_group.myresourcegroup,azurerm_data_factory.adf,azurerm_data_factory_integration_runtime_self_hosted.ir,azurerm_data_factory_linked_custom_service.clihive-linked-service]
}

我的所有资源都创建得很好,但在创建数据集时出现错误:解析 JSON 时出错:查找值开头的字符“无效”。

更新我使用了 jsonencode 函数然后收到不同的错误。 enter image description here

最佳答案

最好使用 jsonencode [1],而不是对 JSON 使用heredoc 语法。以下是如何更改第一个 type_properties_json 的示例:

type_properties_json = jsonencode(
"url" = "https://cdfstagesrg.dfs.core.windows.net"
"accountKey" = {
"type" = "AzureKeyVaultSecret"
"store" = {
"referenceName" = "${azurerm_data_factory_linked_service_key_vault.akvls.name}",
"type" = "LinkedServiceReference"
}
"secretName" = "storageaccesskey"
}
"connectVia" = {
"referenceName" = "${azurerm_data_factory_integration_runtime_self_hosted.ir.name}"
"type" = "IntegrationRuntimeReference"
}
)

或者,我建议使用 templatefile 内置函数 [2],以确保您使用 Terraform 插值语法提供正确的值。因此,来自 jsonencode 函数调用的这部分将转到模板文件(我们称之为 storagels.tpl):

  "url" = "https://cdfstagesrg.dfs.core.windows.net"
"accountKey" = {
"type" = "AzureKeyVaultSecret"
"store" = {
"referenceName" = "${account_key_reference_name}",
"type" = "LinkedServiceReference"
}
"secretName" = "storageaccesskey"
}
"connectVia" = {
"referenceName" = "${connect_via_reference_name}"
"type" = "IntegrationRuntimeReference"
}

然后,在 type_properties_json 中,templatefile 函数调用将位于 jsonencode 函数调用内部:

type_properties_json = jsonencode(templatefile("${path.root}/storagels.tpl",
account_key_reference_name = azurerm_data_factory_linked_service_key_vault.akvls.name
connect_via_reference_name = azurerm_data_factory_integration_runtime_self_hosted.ir.name
))

path.root 意味着模板文件 storagels.tpl 必须与 terraform 代码位于同一目录中。有关 path 变量的更多信息可以在 [3] 中找到。

注意:您必须对问题中的第二个 JSON 执行类似的操作。

<小时/>

[1] https://www.terraform.io/language/functions/jsonencode

[2] https://www.terraform.io/language/functions/templatefile

[3] https://www.terraform.io/language/expressions/references

关于azure - 解析 JSON 时出错 : invalid character 'Â' looking for beginning of value while creating azure data factory source dataset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72869497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com