Terraform v0.12.29
+ provider.aws v3.1.0
provider "aws" {
# ...
}
resource "aws_cloudformation_stack" "failing_resource" {
name = "FailingResource"
template_body = jsonencode({
AWSTemplateFormatVersion = "2010-09-09"
Resources = {
FailingResource = {
Type = "Custom::FailingResource"
Properties = {
ServiceToken = "112233445566778899"
}
}
}
Outputs = {
MissingOutput = {
Value = "MissingValue"
}
}
})
}
data "aws_cloudformation_stack" "missing_stack" {
name = "TheStack${aws_cloudformation_stack.failing_resource.outputs["MissingOutput"]}"
}
output "missing_output" {
value = "The the result is: ${aws_cloudformation_stack.failing_resource.outputs["MissingOutput"]}"
}
$ terraform destroy
aws_cloudformation_stack.failing_resource: Refreshing state... [id=arn:aws:cloudformation:us-east-1:************:stack/FailingResource/aeb06230-daf1-11ea-b81c-0a34514375d1]
Error: Invalid index
on main.tf line 70, in data "aws_cloudformation_stack" "missing_stack":
70: name = "TheStack${aws_cloudformation_stack.failing_resource.outputs["MissingOutput"]}"
|----------------
| aws_cloudformation_stack.failing_resource.outputs is empty map of string
The given key does not identify an element in this collection value.
Error: Invalid index
on main.tf line 74, in output "missing_output":
74: value = "The the result is: ${aws_cloudformation_stack.failing_resource.outputs["MissingOutput"]}"
|----------------
| aws_cloudformation_stack.failing_resource.outputs is empty map of string
The given key does not identify an element in this collection value.
Outputs and data sources should not be resolved as its dependencies are not in a valid state.
I should be able to destroy the my state and underlying resources.
The failure on executing the cloud formation stack cause its state to contains an empty map of outputs instead of the expected map.
It is causing the output and data source evaluation to fail, preventing it from destroying the invalid state.
terraform initterraform applyterraform destroy@mikhasd as a short-term workaround in case you're blocked ont his, you can use a terraform config with just your aws provider block to set the region and run a destroy just with that and your state.
I have "this code" wrapped into a module, and just noticed that the output is being refreshed before the cloudfomation stack is createad.
Most helpful comment
@mikhasd as a short-term workaround in case you're blocked ont his, you can use a terraform config with just your aws provider block to set the region and run a destroy just with that and your state.