Skip to content
This repository has been archived by the owner on Nov 14, 2020. It is now read-only.

tf destroy fails when nothing to destroy #136

Open
ryan-dyer-sp opened this issue May 5, 2020 · 1 comment
Open

tf destroy fails when nothing to destroy #136

ryan-dyer-sp opened this issue May 5, 2020 · 1 comment

Comments

@ryan-dyer-sp
Copy link

ryan-dyer-sp commented May 5, 2020

Use case

As part of our tf testing infrastructure we initiate a terraform destroy to ensure any residual resources from previous runs are gone. This does not seem to work properly with the postgresql module. This may be related to the fact the provider section for our module obtains the info/credentials via ssm as a data source.

Terraform Version

terraform -v
Terraform v0.12.20

  • provider.aws v2.60.0
  • provider.postgresql v1.5.0
  • provider.random v2.2.1

Affected Resource(s)

  • postgresql_*

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

provider "postgresql" {
  host = data.aws_ssm_parameter.db_host.value
  port = 5432
  username = data.aws_ssm_parameter.db_admin_user.value
  password = data.aws_ssm_parameter.db_admin_pass.value
  superuser = false
}

provider "aws" {
  region  = "us-east-1"
}

data "aws_ssm_parameter" "db_host" {
  name = "/writer_endpoint"
}

data "aws_ssm_parameter" "db_admin_user" {
  name = "/admin_user"
}

data "aws_ssm_parameter" "db_admin_pass" {
  name = "/admin_pass"
}

resource "random_password" "db_pass" {
  length           = 12
  special          = true
  override_special = "!#$%&*()-_=+[]{}<>:?"
}

resource "postgresql_role" "customer_admin" {
  name     = var.customer_db_admin
  login    = true
  password = random_password.db_pass.result
  skip_reassign_owned = true
}

resource "postgresql_database" "db" {
  name = "${var.subdomain}-db"
  owner = postgresql_role.customer_admin.name
  lc_collate = "en_US.UTF-8"
  lc_ctype = "en_US.UTF-8"
}

variable "subdomain" {
  description = "The subdomain of the customer."
  type = string
  default = "testinstance"
}

variable "customer_db_admin" {
  description = "The role created in the postgresdb which allows a customer access to their dbs."
  type = string
  default = "testinstance_admin"
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.
https://gist.github.com/ryan-dyer-sp/0b3e46d27c0dd88ab8bcfc7d1801114e

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?
terraform destroy should work successfully when there is nothing to destroy, not throw an error.

Actual Behavior

What actually happened?

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan
  2. ensure no existing resources and everything should need to be added
  3. terraform destroy
@cyrilgdn
Copy link
Contributor

cyrilgdn commented May 6, 2020

Hi,

Thanks for opening this issue.

This is a known bug, we'll work on it but it needs important modifications.
Meanwhile, a workaround is to set the expected_version setting in the provider block to your server version. Thanks to that it will not try to detect the version and will not fail.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants