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

terraform destroy doesn't initialize provider correctly if it's using data source #24055

Closed
bkabrda opened this issue Feb 7, 2020 · 2 comments
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@bkabrda
Copy link

bkabrda commented Feb 7, 2020

Terraform Version

Terraform v0.12.20
+ provider.datadog v2.6.0
+ provider.local v1.4.0

Terraform Configuration Files

data "local_file" "api" {
  filename="api"
}

data "local_file" "app" {
  filename="app"
}

provider "datadog" {
    api_url = "https://api.datadoghq.com"
    api_key = trimspace(data.local_file.api.content)
    app_key = trimspace(data.local_file.app.content)
}

# Create a new Datadog monitor
resource "datadog_monitor" "foo" {
  name               = "Name for monitor foo"
  type               = "metric alert"
  message            = "Monitor triggered. Notify: @hipchat-channel"

  query = "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 4"

  thresholds = {
    warning           = 3
    critical          = 4
  }

  new_host_delay = 300

  tags = ["foo:bar", "baz"]
  notify_no_data = true
}

Debug Output

https://gist.github.com/bkabrda/c565ac6677167f8c43b103691b985c5c

Crash Output

N/A

Expected Behavior

Should have passed without an error

Actual Behavior

Plan: 0 to add, 0 to change, 0 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes


Error: Invalid or missing credentials provided to the Datadog Provider. Please confirm your API and APP keys are valid and see https://terraform.io/docs/providers/datadog/index.html for more information on providing credentials for the Datadog Provider

  on example.tf line 10, in provider "datadog":
  10: provider "datadog" {

Steps to Reproduce

  1. terraform init
  2. terraform destroy

Additional Context

This seems to only occur when there is at least one resource defined in the terraform config, but the terraform statefile is empty.

References

This happened to a user of Datadog Provider who initializes the provider with values from Amazon SSM data source: https://github.com/terraform-providers/terraform-provider-datadog/issues/360#issuecomment-582450080

@jbardin
Copy link
Member

jbardin commented Oct 29, 2020

The method for handling dependencies during destroy has been improved significantly since 0.13, and I have confirmed this is working in the latest 0.14 release.

Thanks!

@jbardin jbardin closed this as completed Oct 29, 2020
@ghost
Copy link

ghost commented Nov 29, 2020

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 Nov 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug core v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

3 participants