這是模塊檔案夾結構
json 定義檔案 (machine_definition.json)
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Pass",
"Result": "Hello",
"Next": "World"
},
"World": {
"Type": "${var.test}",
"Result": "World",
"End": true
}
}
}
例如我想在這里輸入 var.test 。如何讓 json 檔案檢測到我的變數?
這是階躍函式定義
module "step-functions" {
source = "terraform-aws-modules/step-functions/aws"
name = "env-${var.environment}-state-machine"
definition = file("${path.module}/machine_definition.json")
tags = var.tags
service_integrations = {
xray = {
xray = true
}
}
cloudwatch_log_group_name = "env-${var.environment}-state-machine-logGroup"
attach_policies = true
number_of_policies = 2
policies = ["arn:aws:iam::aws:policy/AmazonS3FullAccess", "arn:aws:iam::aws:policy/AWSLambda_FullAccess"]
}
uj5u.com熱心網友回復:
不能以這種方式將變數添加到檔案中。為了實作你想要的,你需要使用templatefile[1] 內置函式。為此,您需要進行一些代碼更改:
definition = templatefile("${path.module}/machine_definition.json", {
type = var.test
})
然后,在 JSON 檔案中,您需要type像這樣參考模板化變數 ( ):
{
"Comment": "A Hello World example of the Amazon States Language using Pass states",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Pass",
"Result": "Hello",
"Next": "World"
},
"World": {
"Type": "${type}",
"Result": "World",
"End": true
}
}
}
這應該正確呈現檔案。
[1] https://developer.hashicorp.com/terraform/language/functions/templatefile
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/520440.html
