How to disable parts of resources in terraform?

7,996 views
Skip to first unread message

egul...@gmail.com

unread,
Sep 23, 2016, 1:25:01 PM9/23/16
to Terraform
Hello everyone,

Is it possible to disable parts of infrastructure in terraform without actually destroying resources?

Commenting out items in .ml files doesn't work because 'tf plan' & 'tf apply' will destroy resources.


Have someone resolved similar issue in different way? Modifying state file maybe?



If we split our infrastructure into using modules, can we turn off some modules from terraform (so state doesn't see it) temporarily and later enable them?



Any advice appreciated,
Thank you

Lowe Schmidt

unread,
Sep 24, 2016, 4:56:21 AM9/24/16
to terrafo...@googlegroups.com
In what provider? And how would you accomplish this without terraform? 

--
Lowe Schmidt | +46 723 867 157

--
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/bab1997f-b7c0-4ef3-9e47-a4adf8d9758c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Atkins

unread,
Sep 25, 2016, 5:37:26 PM9/25/16
to Terraform
I'm not 100% sure what you're asking here, but I think what you're getting at is that you want Terraform to temporarily ignore certain resources while still keeping track of them so you can continue using them in Terraform later.

If so, the closest feature to that today is the -target argument accepted on the terraform plan and terraform apply (with no arguments) commands. This actually does the opposite of what I think you want here: it asks Terraform to focus its attention only on the resources that are targeted:

terraform plan -out=tfplan -target=aws_instance.foo -target=aws_route53_record.foo

When using -target, Terraform will not do any semantic validation, refreshing, planning or applying on any resource except those that you explicitly name and any resources that are dependencies of those targets.

ja...@fpcomplete.com

unread,
Sep 26, 2016, 12:47:38 AM9/26/16
to Terraform


On Friday, September 23, 2016 at 1:25:01 PM UTC-4, egul...@gmail.com wrote:
Hello everyone,

Is it possible to disable parts of infrastructure in terraform without actually destroying resources?

Commenting out items in .ml files doesn't work because 'tf plan' & 'tf apply' will destroy resources.


It sounds like you are looking for the `-target` parameter, were the `tf plan` and `tf apply` will focus on specific resources. It would work for most cases, at least. I find `-target` fails to work properly in some cases, particularly with modules. Specifying one or more resources within a module sometimes works for me, targeting an entire module fails to work as expected, and sometimes using target seems to confuse Terraform's understanding of variables.. but those issues that aside, `-target` works really great.

In regards to refactoring and modules and that sort of thing.. you are sometimes better off removing and recreating the resources, but you might also be able to remove the resources from your TF state and then import the existing (but now "unknown") resource into a specific location within a module, though I haven't tested or used that extensively.

pau...@gliffy.com

unread,
Jan 20, 2017, 6:52:12 PM1/20/17
to Terraform
I think what you're looking for is the `terraform state rm` command: https://www.terraform.io/docs/commands/state/rm.html.


On Friday, September 23, 2016 at 10:25:01 AM UTC-7, egul...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages