[英]How to set an escaped json for AWS DMS with Terraform?
Terraform 的示例是Resource: aws_dms_replication_task我創建了一個測試資源作為
resource "aws_dms_replication_task" "test" {
migration_type = "full-load"
replication_instance_arn = aws_dms_replication_instance.test-dms-replication-instance-tf.replication_instance_arn
replication_task_id = "test-dms-replication-task-tf"
source_endpoint_arn = aws_dms_endpoint.test-dms-source-endpoint-tf.endpoint_arn
table_mappings = jsonencode(file("${path.module}/test.json"))
tags = {
Name = "test"
}
target_endpoint_arn = aws_dms_endpoint.test-dms-target-endpoint-tf.endpoint_arn
}
test.json 文件是
{
"rules": [
{
"rule-type": "transformation",
"rule-id": "1",
"rule-name": "Rule name 1",
"rule-action": "rename",
"rule-target": "schema",
"object-locator": {
"schema-name": "SCHEMA_1",
"table-name": "TABLE_1"
},
"value": "main"
}
]
}
運行 terraform 應用程序時,出現此錯誤
Error: InvalidParameterValueException: Invalid Table Mappings document. Invalid json Invalid json object
如果使用格式作為示例可能沒問題
table_mappings = "{\"rules\":[{\"rule-type\":\"selection\",\"rule-id\":\"1\",\"rule-name\":\"1\",\"object-locator\":{\"schema-name\":\"%\",\"table-name\":\"%\"},\"rule-action\":\"include\"}]}"
如果使用 Terraform 的 function 如何實現相同的結果?
要獲得轉義的 json 字符串,您可以執行以下操作:
table_mappings = jsonencode(jsondecode(file("${path.module}/test.json")))
這有效地從您的test.json
中刪除\n
並生成單行 json 轉義字符串。
例子:
"{\"rules\":[{\"object-locator\":{\"schema-name\":\"SCHEMA_1\",\"table-name\":\"TABLE_1\"},\"rule-action\":\"rename\",\"rule-id\":\"1\",\"rule-name\":\"Rule name 1\",\"rule-target\":\"schema\",\"rule-type\":\"transformation\",\"value\":\"main\"}]}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.