Azure触发器链接模板defaultValue

时间:2017-12-10 07:51:27

标签: json azure arm-template

我在Azure ARM模板中使用链接模板。我在尝试使用子模板的默认值但仍在父模板中维护对参数的引用时遇到问题。

parent.json

...
parameters: {
  bar: {
    type: "string",
    allowedValues: ["larry", "moe", "curly"],
    defaultValue: "curly"
  }
}
...

sub.json

The value of deployment parameter 'foo' is null

不幸的是,在父模板中传递foo的 null 值将导致错误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'。如果我为foo传递一个空字符串,它将会出错... resources: [{ type: "Microsoft.Resources/deployments" properties: { ... parameters: { bar: { value: "[if(empty(parameters('foo')), json('null'), parameters('foo'))]" } } } }] ...

我尝试输入parent.json

aws::NoValue

但它只是给出相同的值为null。我知道这可以使用值{{1}}在AWS嵌套堆栈中完成,但无法在azure中找到任何等效项。有人会知道其他任何事情吗?

2 个答案:

答案 0 :(得分:0)

只是不传递任何东西,甚至不指定参数名称。所以传入:

parameters: {}

我从来没有尝试过,但你可以通过以下方式达到预期的效果:

parameters: "[variables('passMe')]"

对于变量值,您可以使用以下内容:

passMe: {
    bar: {
         value: "bla-bla-bla"
    }
}

您显然需要动态构建这些变量,或者至少部分动态构建这些变量。

答案 1 :(得分:0)

为了帮助将来的其他人......扩展@ 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')]"
  }
}]
...