Creating infrastructure using terraform and ansible together into same pipeline

I am creating infrastructue using terraform and configure that machines with ansible ,i want to know is their anyway to check the infrastructure present or not using terraform if it exists then skip applying .else create infrastructure.

Hi @paragdubey369,

Terraform’s design expects that the configuration declares the expected state of the infrastructure. Terraform then will use the providers to create, update, and manage that infrastructure through it’s entire lifecycle. It’s not really designed to conditionally create infrastructure, nor to be run like a script to deploy something and then hand it off to another tool to manage.

@jbardin Thanks for your reply i really appreciate , but somehow i tried to manage that using the terraform http gitlab backend with the detailed exit code and plan code i tried it worked well also in the main.tf i introduced lifecycle ignore { disk, boot tags} so after configuration of the vms the terraform not really plan to change it exit as infrastructure already up to date. What to think is it a right approach to make the infrastructure production ready? Or if you can suggest me something that would be helpful. warm regards, Parag Dubey

Yes, you can use ignore_changes to avoid trying to manage certain attributes of your resource that might be modified externally. As long as you are expecting Terraform to maintain ownership over the resources then there should be no major problems. I can’t really make any more concrete suggestions without specific examples, but sometimes experimenting is the best way to figure it out.

@jbardin Thanks for your valuable suggestions.