Destroying resources by removing .tf.json files

204 views
Skip to first unread message

kau...@gmail.com

unread,
Mar 16, 2017, 10:38:38 AM3/16/17
to Terraform
Hello,

We have tooling that adds/removes specific ".tf.json" files and then runs "terraform apply" to create/destroy resources. This behavior works well until we remove the last ".tf.json" file.

In v0.8.7 a message like the following is shown:

    # terraform plan
    Error loading config: No Terraform configuration files found in directory: /tmp/files

And in v0.9.0:

    # terraform apply
    No configuration files found!

    Apply requires configuration to be present. Applying without a configuration
    would mark everything for destruction, which is normally not what is desired.
    If you would like to destroy everything, please run 'terraform destroy' instead
    which does not require any configuration files.

I have a few questions on this:

1. Is simply removing a ".tf.json" file a valid and recommended way to remove a the resource (assuming that the associated resource is in the "terraform.tfstate" file)?
2. It seems like we can still use this approach for removing the last resources IF we simply create a file like "empty.tf.json" with only "{}"; is this safe? It appears that terraform simply requires at least a single .tf.json file -- once we add an empty file then we can remove the last .tf.json that represents the last resource in the state file.

Thanks!
Steven Kaufer


David Adams

unread,
Mar 16, 2017, 11:16:38 AM3/16/17
to terrafo...@googlegroups.com
I think this is a valid workflow. The failure when no config files are present is mainly just a sanity check to make sure you aren't running terraform from the wrong directory. So just keeping an empty tf.json file in the directory seems like the easiest solution.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/4e3b83e6-0180-4f79-ae24-1f09e593ff2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cunningham

unread,
Mar 16, 2017, 11:23:39 AM3/16/17
to terrafo...@googlegroups.com
Don't you need at least one config file to specify your credentials?

David Adams

unread,
Mar 16, 2017, 11:30:28 AM3/16/17
to terrafo...@googlegroups.com
Depends on the provider. For AWS, you can specify it all from environment variables.

kau...@gmail.com

unread,
Mar 16, 2017, 12:19:11 PM3/16/17
to Terraform
Thanks for the replies! We will go ahead and create a "empty.tf.json" file so that we can clean up the last node.

Steven Kaufer
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages