Azure 触发器链接模板 defaultValue
Azure trigger linked template defaultValue
我在 Azure ARM 模板中使用链接模板。我在尝试使用子模板的默认值时遇到问题,但仍然在父模板中维护对参数的引用。
parent.json
...
parameters: {
foo: {
type: "string"
}
},
resources: [{
type: "Microsoft.Resources/deployments",
properties: {
templateLink: {
uri: "sub.json",
contentVersion: "1.0.0.0"
},
parameters: {
bar: {
value: "[parameters('foo')]"
}
}
}
}]
...
sub.json
...
parameters: {
bar: {
type: "string",
allowedValues: ["larry", "moe", "curly"],
defaultValue: "curly"
}
}
...
不幸的是,在父模板中为 foo 传递 null 值将出错 The value of deployment parameter 'foo' is null
。如果我为 foo 传递一个空字符串,它将出错 The provided value '' for the template parameter 'bar' is not valid. The parameter value is not part of the allowed value(s): 'larry,moe,curly'
.
我试着输入 parent.json
...
resources: [{
type: "Microsoft.Resources/deployments"
properties: {
...
parameters: {
bar: {
value: "[if(empty(parameters('foo')), json('null'), parameters('foo'))]"
}
}
}
}]
...
但它只会给出相同的值 is null。我知道这可以在 AWS 嵌套堆栈中使用值 aws::NoValue
完成,但在 azure 中找不到任何等效项。有人知道还有什么可以尝试的吗?
只是不要传递任何东西,甚至不要指定参数名称。所以传入:
parameters: {}
我从未尝试过,但您可以通过以下方式实现预期的结果:
parameters: "[variables('passMe')]"
对于变量值,您可以使用类似的东西:
passMe: {
bar: {
value: "bla-bla-bla"
}
}
您显然需要即时或至少部分即时构建这些变量。
为了将来帮助其他人...扩展 @4c74356b41 的回复。创建可以在运行时动态生成链接模板参数的变量。
这是一个工作示例:
...
parameters: {
foo: {
type: "string"
}
},
variables: {
emptyObject: {},
subParameterBar: {
bar: {
value: "[parameters('foo')]"
}
},
hasSubParameterBar: "[if(empty(parameters('foo')), variables('emptyObject'), variables('subParameterBar'))]",
subProperties: "unionvariables('HasSubParameterBar'), ...<any other parameter variables>)]"
},
resources: [{
type: "Microsoft.Resources/deployments",
name: "sub",
properties: {
templateLink: {
uri: "sub.json",
contentVersion: "1.0.0.0"
},
parameters: "[variables('barProperties')]"
}
}]
...
我在 Azure ARM 模板中使用链接模板。我在尝试使用子模板的默认值时遇到问题,但仍然在父模板中维护对参数的引用。
parent.json
...
parameters: {
foo: {
type: "string"
}
},
resources: [{
type: "Microsoft.Resources/deployments",
properties: {
templateLink: {
uri: "sub.json",
contentVersion: "1.0.0.0"
},
parameters: {
bar: {
value: "[parameters('foo')]"
}
}
}
}]
...
sub.json
...
parameters: {
bar: {
type: "string",
allowedValues: ["larry", "moe", "curly"],
defaultValue: "curly"
}
}
...
不幸的是,在父模板中为 foo 传递 null 值将出错 The value of deployment parameter 'foo' is null
。如果我为 foo 传递一个空字符串,它将出错 The provided value '' for the template parameter 'bar' is not valid. The parameter value is not part of the allowed value(s): 'larry,moe,curly'
.
我试着输入 parent.json
...
resources: [{
type: "Microsoft.Resources/deployments"
properties: {
...
parameters: {
bar: {
value: "[if(empty(parameters('foo')), json('null'), parameters('foo'))]"
}
}
}
}]
...
但它只会给出相同的值 is null。我知道这可以在 AWS 嵌套堆栈中使用值 aws::NoValue
完成,但在 azure 中找不到任何等效项。有人知道还有什么可以尝试的吗?
只是不要传递任何东西,甚至不要指定参数名称。所以传入:
parameters: {}
我从未尝试过,但您可以通过以下方式实现预期的结果:
parameters: "[variables('passMe')]"
对于变量值,您可以使用类似的东西:
passMe: {
bar: {
value: "bla-bla-bla"
}
}
您显然需要即时或至少部分即时构建这些变量。
为了将来帮助其他人...扩展 @4c74356b41 的回复。创建可以在运行时动态生成链接模板参数的变量。
这是一个工作示例:
...
parameters: {
foo: {
type: "string"
}
},
variables: {
emptyObject: {},
subParameterBar: {
bar: {
value: "[parameters('foo')]"
}
},
hasSubParameterBar: "[if(empty(parameters('foo')), variables('emptyObject'), variables('subParameterBar'))]",
subProperties: "unionvariables('HasSubParameterBar'), ...<any other parameter variables>)]"
},
resources: [{
type: "Microsoft.Resources/deployments",
name: "sub",
properties: {
templateLink: {
uri: "sub.json",
contentVersion: "1.0.0.0"
},
parameters: "[variables('barProperties')]"
}
}]
...