简体   繁体   English

Terraform - 可选 SSM 参数查找

[英]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.

相关问题 Cloudformation 到 terraform 转换 SSM 参数 - Cloudformation to terraform conversion of SSM parameter 如何从 Terraform 创建 AWS SSM 参数 - How to create AWS SSM Parameter from Terraform 如何隐藏 terraform aws_ssm_parameter 值 - How to hide terraform aws_ssm_parameter values 如何将变量的 terraform 输出导出/发布到 AWS SSM 参数存储 - how to export / post terraform output of variables to AWS SSM parameter store 我需要一个策略来处理 CDK 中的可选 SSM Parameter Store 参数 - I need a strategy for handling optional SSM Parameter Store parameters in CDK Terraform 调用SSM文档 - Terraform to call an SSM document 如何使用 Terraform 在 AWS SSM 参数中存储三元素元组? - How can I store a three element tuple in AWS SSM parameter with Terraform? 如何在Terraform中使用aws_ssm_parameter在'values'参数中输入字典结构? - How to input the dictionary structure in 'values' argument using the aws_ssm_parameter in terraform? 从 terraform 调用 SSM 文档 - Call an SSM document from terraform 将 AWS SSM 参数存储中的加密数据提取到 terraform var 文件中并将其加密传递,直到在 terraform 代码中调用它 - Pull encrypted data from AWS SSM Parameter store into terraform var file and pass it encrypted till it is called inside the terraform code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM