Terraform plan and apply !!!

1,693 views
Skip to first unread message

Anand Sreenivasan

unread,
May 7, 2018, 8:22:29 AM5/7/18
to Terraform
Hello,
      I have two terraform main.tf files which are creating 2 different set of resources in the same VPC !! When I did terraform apply on the first main.tf, All resources were created without issues but when I try to execute the second one, It is destroying the first set of resources. How can I make terraform execute the second script and just make it add the resources and not touch anything created by the first script?. Any help would be highly appreciated !! Thanks.

S Anandd

laxman Singh Rathore

unread,
May 7, 2018, 8:55:05 AM5/7/18
to terrafo...@googlegroups.com
Hi Anand, 

All these resource on both tf file are same ? share you both tf file as well as your execution output. because terraform plan & terraform apply not destroying any resource. only terraform destory  delete all resource that is available on terraform.tfstate.

Regards,
Laxman Singh


--
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/3c217465-d3f3-4eb3-839d-2252925f731e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Thanks & Regards
Laxman Singh Mandloi

Anand Sreenivasan

unread,
May 7, 2018, 10:11:23 AM5/7/18
to Terraform
Hello Laxman,
        Thanks for responding. The first TF file creates 3 SG's and 3 instances and the second TF creates one new SG's and 2 new instances on the same VPC !!  Here is the output from the second script,

Plan: 3 to add, 0 to change, 5 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

David Adams

unread,
May 7, 2018, 11:41:23 AM5/7/18
to terrafo...@googlegroups.com
Sounds like they are both pointed at the same tfstate file, but they will need to point to different ones. You can use `-state=filename.tfstate` on the command line along with plan or apply to specify different files. But I'm curious what the rest of the filesystem looks like that you are getting this result.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/5089e010-2132-42ef-bd55-711b5ad5775a%40googlegroups.com.

Anand Sreenivasan

unread,
May 7, 2018, 11:46:39 AM5/7/18
to Terraform
Hey David,
      I think that is my issue but how do I point to a different tfstate file ?. meaning, Does this not get created only after running through init and plan and apply ?. The real filesystem should look like a total of 3 SG's and 5 instances under one VPC !!! Right now, When I execute these 2 different scripts, It destroys each other and I am ending up with only one set of resources defined in the script file whichever is executed last !!!

S Anandd

David Adams

unread,
May 7, 2018, 12:20:18 PM5/7/18
to terrafo...@googlegroups.com
Can you share the exact commands you are running and the filesystem structure you are working with?

Anand Sreenivasan

unread,
May 7, 2018, 12:23:21 PM5/7/18
to Terraform
Hey David,
     I figured out it !! Thanks much for your help !! 

S Anandd

On Monday, May 7, 2018 at 11:41:23 AM UTC-4, David Adams wrote:

crunchy...@gmail.com

unread,
Jun 15, 2018, 9:09:19 AM6/15/18
to Terraform
Hi Anand

Since terraform creates immutable infrastructure, it will destroy the old one and create new. Looks like both your .tf files are pointing to same .tfstate. That is why it is  doing so. You will have to check around this and see if you can debug further.

For further help share your .tf files and the commnds you are using to run it,

Thanks
Shashank
Reply all
Reply to author
Forward
0 new messages