-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data source - return "null" if the source does not have the specified value #11782
Comments
Hi @w32-blaster! Thanks for this feature request. I'd like to try to understand better what you're dealing with here. I think you are trying to retrieve the outputs of a cloudformation stack using the data "aws_cloudformation_stack" "example" {
name = "some-example-stack"
}
resource "something_else" "example" {
some_attribute = "${data.aws_cloudformation_stack.example.outputs["foobarbaz"]}"
} The above would fail if the map retrieved from the Cloudformation API did not include an output named "foobarbaz". I think this issue could be avoided by using the resource "something_else" "example" {
some_attribute = "${lookup(data.aws_cloudformation_stack.example.outputs, "foobarbaz", "default-foobarbaz")}"
} Does that help you achieve the result you were looking for here, or is there something different going on? |
OK, somehow I didn't get that the |
Great, @w32-blaster! I'm glad that works for you. I'm going to close this issue, since it seems like this will be a workable approach for you. |
I'm wondering how I can get around an empty datasource also. My issue seems slightly different. ${lookup(data.oci_core_subnets.sub.subnets[count.index],"id","dummy")}
however, if the template just started running (or was run previously), this wouldn't be empty. |
Is anyone using a workaround for this? |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
I'm trying to solve a problem where a cloudformation stack output value is used.
I'm getting a key does not exist using the aws_cloudformation_stack data source which is expected because the specified key is not set in the CF template.
I'm wondering if it would make sense in general in all data sources to return a null value or empty string if the key does not exist in the source, so we can handle this situation using the function
coalesce
to return a default value.That would allow us to set a default value like in a variable and use that instead. Or going back to my original problem, we would be able to return a default cloudformation output if the first key does not return anything.
The text was updated successfully, but these errors were encountered: