Apply process with objective maintain state is core part of philosophy of the terraform, and i think if there necessary this usage, you have other problem in your use case. If you explain a use case more, i will help you better.
Without seeing what you modified, its hard to tell.
Basically, what is in your terraform files is what terraform will try and do. So if you want terraform to add and not delete, then you need to add to the file. If you modify something, it MAY need to be deleted and created.
Terraform will look at the desired state or “resources in the file” ( web and web-1) compare it to the current state ( web ), and plan the actions to bring the current state to the desired state ( create web-1 ). Each resources has its own “rules” on when to update and when to delete/create. One jkey element often overlooked is the name of the resource is the “index in the state file”.
So if I decide to make things consistent, and change my file to :
Thank you very much for responding me. Ill present my scenario. I wrote the below code to create ‘Lambda layer’ only. The Lambda layer has this option of versioning, for example we create a lambda layer called ‘xyz’ with runtime python3.8 and it will be created as ‘version 1’. I can update the runtime to python3.9 for the same Lambda layer ‘xyz’ and it becomes ‘version 2’. In AWS Lambda layer I get to see both the version 1 and 2, depending on my test case I have the option to call any of the layers in my Lambda Function.
The issue I am facing is with the below terraform code, the existing layer is getting destroyed. In the above example terraform is destroying version 1 and creating version 2.