Closed
Description
Terraform Version
Terraform v0.12.29
+ provider.aws v3.1.0
Terraform Configuration Files
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"]}"
}
Debug Output
Crash Output
$ 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.
Expected Behavior
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.
Actual Behavior
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.
Steps to Reproduce
terraform init
terraform apply
terraform destroy