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 should ignore output variables #522

Closed
gigablah opened this issue Oct 30, 2014 · 20 comments
Closed

terraform destroy should ignore output variables #522

gigablah opened this issue Oct 30, 2014 · 20 comments
Assignees

Comments

@gigablah
Copy link

For example, I have something like this:

resource "aws_vpc" "vpc" {
  cidr_block = "10.0.0.0/16"
}

resource "aws_internet_gateway" "gateway" {
  vpc_id = "${aws_vpc.vpc.id}"
}

resource "aws_elb" "elb" {
  ...
}

output "elb" {
  value = "${aws_elb.elb.dns_name}"
}

If terraform destroy removes the ELB but fails at the VPC (related: #497), I cannot get it to run another time unless I remove the output variable (since the resource it references is gone). I get an error like:

aws_vpc.vpc: Refreshing state... (ID: vpc-xxxxxxxx)
aws_internet_gateway.gateway: Refreshing state... (ID: igw-xxxxxxxx)
Error creating plan: Resource 'aws_elb.elb' not found for variable 'aws_elb.elb.dns_name'

After removing the output variable, terraform destroy completes successfully.

(Using version 0.3.1 on OSX)

@kief
Copy link

kief commented Nov 13, 2014

+1 to this. I've also run into this when "terraform apply" fails, leaving only some resources created.

It gets even messier when using modules. I have a template that uses an input variable that references a resource created in a module, but if that resource doesn't exist in the state file, then I can't destroy the infrastructure. In this case, it's not a simple matter of commenting out an output variable, because the reference is used in other resources. My only alternative when this happens is to hunt and delete everything in the web console.

@sethvargo sethvargo added the bug label Nov 19, 2014
@errordeveloper
Copy link

Unless output becomes more then printing to stdout, it should be completely ignored when destroying resources.

@mitchellh
Copy link
Contributor

This might actually be fixed in master, I just haven't had a chance to check yet. But we did fix a lot of issues around this.

@mitchellh mitchellh added the core label Jan 6, 2015
@errordeveloper
Copy link

It gets even messier when using modules.

Ah, I didn't realise it's also used with modules already, I haven't got to modularise my code yet.

This might actually be fixed in master, I just haven't had a chance to check yet. But we did fix a lot of issues around this.

Sounds like 0.3.6 is in to come out any day now?

@mitchellh
Copy link
Contributor

@errordeveloper Yeah I'm cutting the release now, but depending on internet speeds might not make it to release until tomorrow since I have to step out of the office soon. (Matters if the upload finishes before I get out or not)

@blakeblackshear
Copy link

This doesn't appear to have made it into 0.3.6

@radeksimko
Copy link
Member

This problem still exists in the very latest version (v0.3.7.dev (26156981d7b67dce7a033ffea94aea5370c09c58), here's how to replicate it:

provider "aws" {
  region = "eu-west-1"
}

resource "aws_vpc" "default" {
  cidr_block = "10.12.0.0/16"
}

resource "aws_internet_gateway" "default" {
  vpc_id = "${aws_vpc.default.id}"
}

resource "aws_subnet" "public" {
  vpc_id = "${aws_vpc.default.id}"
  cidr_block = "10.12.0.0/24"
  availability_zone = "eu-west-1a"
}

resource "aws_instance" "nat" {
  ami = "ami-14913f63"
  availability_zone = "eu-west-1a"
  instance_type = "t2.micro"
  key_name = "coreos-test"
  subnet_id = "${aws_subnet.public.id}"
  associate_public_ip_address = true
}

output "instance_id" {
  value = "${aws_instance.nat.id}"
}

The example above will fail as mentioned in #497 so as long as #497 persists, it helps reproducing this issue too.

terraform apply
terraform destroy
terraform destroy
Error creating plan: Resource 'aws_instance.nat' not found for variable 'aws_instance.nat.id'

@mitchellh
Copy link
Contributor

With #1010 this no longer happens.

Note @radeksimko that #497 still exists.

@mitchellh mitchellh self-assigned this Feb 20, 2015
@radeksimko
Copy link
Member

Agreed, this is now fixed.

@FrenchBen
Copy link

Why is this still happening? It's been marked as "fixed" in a couple of different PRs. Why are we looking at the output, when taking action such as destroy -force?

@jsi-p
Copy link

jsi-p commented Jun 25, 2018

We're also seeing this with TF version 0.11.7:

...
aws_iam_role_policy_attachment.lambda_poc_role_exec_attachment: Destruction complete after 1s

Error: Error applying plan:

1 error(s) occurred:

* output.sign_in_url: Resource 'aws_cognito_user_pool_client.poc' does not have attribute 'id' for variable 'aws_cognito_user_pool_client.poc.id'

@developerinlondon
Copy link

yes i can confirm this is still happening, specially when my terraform project contains modules and i am running a terraform apply on a destroy it complains when it cant find the resources.

@doanduyhai
Copy link

I confirm the issue is still there, I'm using Terraform v0.11.8 :(

@gupta-alok
Copy link

Still getting the issue with Terraform v0.11.8 while executing terraform destroy:

* module.module-name.output.address: Resource 'aws_instance.rhel-instance' does not have attribute 'private_ip' for variable 'aws_instance.rhel-instance.private_ip'

@andreichernov
Copy link

with v0.11.9 the same issue
* module.acroplia-stack.module.redis.output.redis_internal_lb_dns: Resource 'aws_lb.redis_internal_lb' does not have attribute 'dns_name' for variable 'aws_lb.redis_internal_lb.dns_name'

@ghost
Copy link

ghost commented Oct 30, 2018

with v0.11.10 the same issue

  • module.webserver_cluster.output.elb_dns_name: Resource 'aws_elb.example' does not have attribute 'dns_name' for variable 'aws_elb.example.dns_name'

@aleybovich
Copy link

@mitchellh are you guys looking into this issue? It's still happening on the latest version of terraform

@Jamie-BitFlight
Copy link

Guys, if you run terraform with this environment variable, it will change the hard errors for outputs into warnings:

export TF_WARN_OUTPUT_ERRORS=1

@ghost
Copy link

ghost commented Dec 5, 2018

@Jamie-BitFlight wonderful. Exactly what I needed. Put it into my destroy.sh script and worked like a charm. ENV is your friend and my preferred way to manipulate things like output. +1.

It didn't come up in my searches: https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md#0111-november-30-2017

See above ^^^. Looks like it's still "undocumented" from google search.

@ghost
Copy link

ghost commented Mar 30, 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 Mar 30, 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