Terraform Remote State Concurrency

Hi all,

I have a problem with how Remote States are handled which are stored in Artifactory. Running terraform v0.14.5.

Setup:

  1. I have 2 VMs using a single remote tfstate file in Artifactory and two copies of the same terraform files in two different directories on the local filesystem.
  2. Running terraform apply in a loop in one directory with a pause between the runs
  3. Running terraform taint on demand in the other directory
  4. In both directories the same remote tfstate file is referenced

Good case:

  1. terraform taint VM1
  2. terraform apply is running recreating VM1
  3. terraform apply is finished
  4. terraform taint VM2
  5. terraform apply is running recreating VM2

Bad case:

  1. terraform taint VM1
  2. terraform apply is running recreating VM1
  3. terraform taint VM2
  4. terraform apply is finished
  5. pause
  6. terraform apply is not recreating VM2

Seems the tfstate gets overwritten after terraform apply is finished even though VM2 has been tainted in the meantime. Any way to prevent this apart from running terraform taint only when terraform apply is not running?

Thanks for your help, really appreciated,
Martin