My remote state for two of my projects automatically stores in env:/dev/state_path
However for two other projects, it is omitting the env:/dev/, I have had to manually add that env specification. These two projects didn’t need this, and then one day (after an update?) each eventually required me to manually add that.
Here is an example of one of the projects that has been affected by this
the second service that began to exhibit this behavior relies on the output of this. That’s one of the key frustrations: when it’s outputting to remote state it knows to add the env:/dev/, however on the inputs it’s requiring me to add them manually
Are you using terraform workspaces? You don’t state if this is running locally or via some sort of CI/CD pipeline. If the latter is something setting (or stopped setting) workspaces?
While I’m not familiar with the S3 backend however in the Azure backend when you use a workspace it adds an affix similar to what you show:
In the image below the state file at the top is after a terraform init without setting workspace (so the workspace = ‘default’)
The state file at the bottom is after a terraform init after issuing terraform workspace new dev which creates and changes into a workspace called dev.
I’ve also tried manually setting the TF_ENV variable which didn’t change anything either
Since it affixes the env:/dev/ when saving to the remote state, but not when reading from the remote state, it keeps making me think that it knows it’s supposed to use that environment but is omitting when retrieving state for other projects
The remote state data source that you are using has a workspace argument which you don’t appear to be using:
But you are passing the workspace_key_prefix parameter as part of the config block which should do the same job (at least for the s3 backend)
May be worth testing using the data source argument instead of the config parameter and see if that solve it. Although an unexpected change in behaviour is a bit concerning.
I’m not sure why since 1/2 of my TF projects require neither the Workspace data value, nor workspace_key_prefix (I had attempted this when things stopped working)
I’m not going to look a gift-horse in the mouth though since this fixed my problem
that being said however it’s concerning that out of 4 projects with near identical configs, 2 of them -one after another- began omitting that affix