[英]Terraform - Optional SSM parameter lookup
I'm doing a lookup for an SSM parameter which may or may not exist depending on a variable passed in:我正在查找 SSM 参数,该参数可能存在也可能不存在,具体取决于传入的变量:
data "aws_ssm_parameter" "server_tags" {
name = "/${var.env_number}/server_tags"
}
I am then using it like below in my locals and passing to my module:然后我在我的本地人中使用它并传递给我的模块:
locals {
server_tags = data.aws_ssm_parameter.server_tags != null ? jsondecode(data.aws_ssm_parameter.server_tags.value) : {}
instance_tags = merge(var.instance_tags, local.server_tags)
}
This works fine when my parameter exists, but if I pass in a value where my parameter doesn't exist, I get an error:当我的参数存在时,这可以正常工作,但是如果我传入一个我的参数不存在的值,我会收到一个错误:
Error describing SSM parameter (/997/server_tags): ParameterNotFound:
Is there anyway I can do a pre-check to see if the parameter exists or make it optional somehow?无论如何我可以进行预检查以查看参数是否存在或以某种方式使其成为可选参数?
Thanks谢谢
Sadly you can't do this .可悲的是你不能这样做。 There is no way build-on mechanism for TF to check if a data source exists or not.
TF 没有任何构建机制来检查数据源是否存在。 But you can program your own logic for that using External Data Source .
但是您可以使用External Data Source 编写自己的逻辑。
Since you program the external data source, you can create a logic for checking if a resource exists or not.由于您对外部数据源进行了编程,因此您可以创建一个逻辑来检查资源是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.