0

We have provisioned amazon resources (EC2, Loadbalancers, Target groups,...) using Terragrunt, when we re-apply EC2 Instances script it removes Target Groups associated to load balancer.

This is due to the dependencies we create in Target Groups scripts, but would like to understand the best practices to implement the loosely couple terraform/terragrunt scripts. I mean when we re-apply the .hcl file it shouldn't impact the other related resources. Please suggest.

1 Answers1

0

The way terraform/terragrunt know what to destroy is by referencing the state file (local, remote). When you run the terraform apply or terragrunt apply inside a folder, terraform looks at what is in AWS, what is in tfstate file on disk, what are your scripts asking you to do and it performs diffs on all three of those, figures out the delta and decides what to do. An important thing to know about terraform is that terraform is directory specific, any directory you run terraform, it creates a state file in the directory you are running in. There is also a concept of remote state using S3 alongwith DynamoDB so that multiple developers can share the state without stepping on each other toes

Piyush Mattoo
  • 15,454
  • 6
  • 47
  • 56