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

Can't destroy using modules on 0.7rc01 #7047

Closed
dbcoliveira opened this issue Jun 7, 2016 · 5 comments
Closed

Can't destroy using modules on 0.7rc01 #7047

dbcoliveira opened this issue Jun 7, 2016 · 5 comments
Assignees

Comments

@dbcoliveira
Copy link

Hi there,

I am currently using terraform 0.7rc01 and I can't destroy something that have been applied using modules (docker provider) just seconds before.

A snippet of the module source goes like:

variable docker_host {}
variable container_name {}
variable servers {}
variable arguments {}

provider "docker" {
    host = "tcp://${var.docker_host}:2375/"
}
.
.
.

A snippet of the module goes as:

variable "ipaddress" {
        default = "10.64.78.75,10.64.78.76,10.64.78.77"
}

module "etcd01" {
  source = "module/etcd/"
  docker_host = "${element(split(",",var.ipaddress),0)}"
  container_name = "${var.cname}"
  servers = "${var.servers}"
  arguments = ""
}
.
.
.

So applying with:

terraform apply -target=module.etcd01 -target=module.etcd02 -target=module.etcd03 -var-file=secret.tfvars

module.etcd02.docker_container.etcd-viewer: Creation complete
module.etcd03.docker_container.etcd-viewer: Creation complete

Apply complete! Resources: 9 added, 0 changed, 0 destroyed.

Everything goes well and confirmed that it really applies.
On the destroy part it fails big:

terraform destroy -target=module.etcd01 -target=module.etcd02 -target=module.etcd03 -var-file=secret.tfvars

Do you really want to destroy?
  Terraform will delete the following infrastructure:
    module.etcd01
    module.etcd02
    module.etcd03
  There is no undo. Only 'yes' will be accepted to confirm

  Enter a value: yes

.........
Error applying plan:

3 error(s) occurred:

* 1:9: unknown variable accessed: var.docker_host in:

tcp://${var.docker_host}:2375/
* 1:9: unknown variable accessed: var.docker_host in:

tcp://${var.docker_host}:2375/
* 1:9: unknown variable accessed: var.docker_host in:

tcp://${var.docker_host}:2375/

Note that I know the variable list declaration implementation was introduced on 0.7 so I've actually try to perform the same code without the ipaddress list but using the actual ips. the result is the same.

Any ideas ?

Thank you for the feedback

@phinze
Copy link
Contributor

phinze commented Jun 10, 2016

Hi @dbcoliveira - thanks for the report, and sorry for the trouble!

Here is a full repro config that I have confirmed works in 0.6.16 and does not work on 0.7.0-rc1 or master:

Config

# main.tf
module "foo" {
  source = "./foo"
  in = "1"
}
# foo/foo.tf
variable "in" { }

provider "aws" {
  region = "us-east-${var.in}"
}

resource "aws_security_group" "bar" { }

Steps

terraform apply
terraform destroy -force

Expected

Happy destroy

Got

Error applying plan:

1 error(s) occurred:

* 1:11: unknown variable accessed: var.in in:

us-east-${var.in}

@phinze
Copy link
Contributor

phinze commented Jun 10, 2016

Just confirmed the list is not required - simplifying the example above to reflect that.

@phinze
Copy link
Contributor

phinze commented Jun 10, 2016

cc @jen20 FYI - planning on digging into this later but in case you get to it first. 👍

@phinze phinze self-assigned this Jun 11, 2016
phinze added a commit that referenced this issue Jun 12, 2016
For `terraform destroy`, we currently build up the same graph we do for
`plan` and `apply` and we do a walk with a special Diff that says
"destroy everything".

We have fought the interpolation subsystem time and again through this
code path. Beginning in #2775 we gained a new feature to selectively
prune out problematic graph nodes. The past chain of destroy fixes I
have been involved with (#6557, #6599, #6753) have attempted to massage
the "noop" definitions to properly handle the edge cases reported.

"Variable is depended on by provider config" is another edge case we add
here and try to fix.

This dive only makes me more convinced that the whole `terraform
destroy` code path needs to be reworked.

For now, I went with a "surgical strike" approach to the problem
expressed in #7047. I found a couple of issues with the existing
Noop and DestroyEdgeInclude logic, especially with regards to
flattening, but I'm explicitly ignoring these for now so we can get this
particular bug fixed ahead of the 0.7 release. My hope is that we can
circle around with a fully specced initiative to refactor `terraform
destroy`'s graph to be more state-derived than config-derived.

Until then, this fixes #7407
@phinze
Copy link
Contributor

phinze commented Jun 12, 2016

Fixed in #7131 👍

@phinze phinze closed this as completed Jun 12, 2016
@ghost
Copy link

ghost commented Apr 25, 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 and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants