Skip to content
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

Failure on resolving output and data source due to missing map entry prevents state destruction #25784

Closed
mikhasd opened this issue Aug 10, 2020 · 3 comments · Fixed by #28017
Labels
bug confirmed a Terraform Core team member has reproduced this issue v0.12 Issues (primarily bugs) reported against v0.12 releases v0.13 Issues (primarily bugs) reported against v0.13 releases

Comments

@mikhasd
Copy link

mikhasd commented Aug 10, 2020

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

  1. terraform init
  2. terraform apply
  3. terraform destroy

Additional Context

References

@mikhasd mikhasd added bug new new issue not yet triaged labels Aug 10, 2020
@danieldreier danieldreier added confirmed a Terraform Core team member has reproduced this issue and removed new new issue not yet triaged labels Aug 10, 2020
@danieldreier
Copy link
Contributor

@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.

@jbardin jbardin added v0.12 Issues (primarily bugs) reported against v0.12 releases v0.13 Issues (primarily bugs) reported against v0.13 releases labels Aug 11, 2020
@mikhasd
Copy link
Author

mikhasd commented Aug 17, 2020

I have "this code" wrapped into a module, and just noticed that the output is being refreshed before the cloudfomation stack is createad.

@ghost
Copy link

ghost commented Apr 9, 2021

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.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue v0.12 Issues (primarily bugs) reported against v0.12 releases v0.13 Issues (primarily bugs) reported against v0.13 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants