I'm doing a lookup for an SSM parameter which may or may not exist depending on a variable passed in:
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. But you can program your own logic for that using External Data Source.
Since you program the external data source, you can create a logic for checking if a resource exists or not.