How to Recreate the Resources/ Skip them if they already got created

Hi Team ,

I am Configuring Build & Release pipeline to Create Infrastructure on AWS using Terraform .
Whenever there is release failure happens due to some misconfigurations ,by that time most of the resources being created & when i rerun the pipeline , at Terraform Validate & Apply Step i am getting Error stating the " resources already created "& pipeline fails again .

Is there any way making terraform consider that it should skip the resources already created & need to create only those are pending to create?

Kindly let me know

Thanks
Nisha

Hi @NisharunnisaShaik,

Terraform’s default behavior is to remember what it created in the state and thus not recreate it on a future run. If you are seeing Terraform plan to re-create the same objects every time then it suggests that your state snapshots are not persisting between runs, and so Terraform is effectively “forgetting” everything each time.

If you are implementing an automated pipeline for running Terraform then I would suggest using remote state storage so that the state snapshots will be stored in a remote system outside of your automation workers, and can thus persist from one run to the next. Since you are using AWS, you might consider using the s3 backend, which stores state snapshots in Amazon S3 with optional locking in a DynamoDB table.

1 Like