terraform destroy should ignore output variables

Created on 30 Oct 2014  ยท  20Comments  ยท  Source: hashicorp/terraform

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)

bug core

Most helpful comment

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

All 20 comments

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

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

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.

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?

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

This doesn't appear to have made it into 0.3.6

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'

With #1010 this no longer happens.

Note @radeksimko that #497 still exists.

Agreed, this is now fixed.

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?

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'

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.

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

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'

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'

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'

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

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings