Answers: <p>This is possible and I just completed a migration at my company. We originally had all our state for all workspaces in a centralized s3 bucket.</p>
  <p>We now have a separate s3 bucket per workspace, and in our case each workspace is tied directly to an aws account.</p>
  <p>To do this you have to pass in back end settings dynamically at the time of terraform init. We do this in a centralized pipeline template so it is handled for the developers automatically and it goes to the correct location.</p>
  <p>Here is the docs on how to pass in these settings at the time of terraform init.</p>
  <p><a href="https://www.terraform.io/language/settings/backends/configuration#command-line-key-value-pairs" rel="nofollow noreferrer">https://www.terraform.io/language/settings/backends/configuration#command-line-key-value-pairs</a></p>
  <p>Let me know if you have any questions on this.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-11-22T19:19:59.903Z
Answers: This is encouraging! Out of curiosity, do you still wind up with a subdirectory for each workspace (e.g. env:/stage and end:/prod) in the separate S3 buckets?
Answers: pdoherty926
Answers: CC BY-SA 4.0
Answers: 2022-01-23T19:30:26.890Z
Answers: 2022-01-23T19:30:26.890Z
Answers: Brittan DeYoung
Body: <p>Let's say I have a terraform project with a production and development workspace. Is it possible to store the development workspace elsewhere so I don't have to give the admin the ability to run commands that mess up production?</p>
  <p>I'm basing this question on the <a href="https://www.oreilly.com/library/view/terraform-up/9781492046899/" rel="nofollow noreferrer"><em>&quot;Terraform: Up &amp; Running, 2nd Edition&quot;</em> book by Yevgeniy Brikman</a> which calls this a &quot;drawback&quot;. From Page 93,</p>
  <blockquote>
  <p>The state files for all of your workspaces are stored in the same backend (e.g., the same S3 bucket). That means you use the same authentication and access controls for all the workspaces, which is one major reason workspaces are an unsuitable mechanism for isolating environments (e.g., isolating staging from production).</p>
  </blockquote>
  <p>Are there any tools to help address this following with the above quote, is there anyway to store the state for different workspaces in different S3 buckets? Or, is the only option to forgo Terraform workspaces entirely.</p>
  
Tags: <terraform><terraform-workspace>
Title: Is it possible to store your state for different Terraform Workspaces separately?
UserDisplayName: Evan Carroll
ThreadText: # Is it possible to store your state for different Terraform Workspaces separately?
  
  (Asked by: username_0 on 2022-01-23)
  
  Let's say I have a terraform project with a production and development workspace. Is it possible to store the development workspace elsewhere so I don't have to give the admin the ability to run commands that mess up production?
  
  I'm basing this question on the [*"Terraform: Up & Running, 2nd Edition"* book by Yevgeniy Brikman](https://www.oreilly.com/library/view/terraform-up/9781492046899/) which calls this a "drawback". From Page 93,
  
  > The state files for all of your workspaces are stored in the same backend (e.g., the same S3 bucket). That means you use the same authentication and access controls for all the workspaces, which is one major reason workspaces are an unsuitable mechanism for isolating environments (e.g., isolating staging from production).
  
  Are there any tools to help address this following with the above quote, is there anyway to store the state for different workspaces in different S3 buckets? Or, is the only option to forgo Terraform workspaces entirely.
  
  **Tags:** terraform, terraform-workspace
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-23. Score: 3
  
  This is possible and I just completed a migration at my company. We originally had all our state for all workspaces in a centralized s3 bucket.
  
  We now have a separate s3 bucket per workspace, and in our case each workspace is tied directly to an aws account.
  
  To do this you have to pass in back end settings dynamically at the time of terraform init. We do this in a centralized pipeline template so it is handled for the developers automatically and it goes to the correct location.
  
  Here is the docs on how to pass in these settings at the time of terraform init.
  
  <https://www.terraform.io/language/settings/backends/configuration#command-line-key-value-pairs>
  
  Let me know if you have any questions on this.
  
  > **Comments:**
  > **username_2**: This is encouraging! Out of curiosity, do you still wind up with a subdirectory for each workspace (e.g. env:/stage and end:/prod) in the separate S3 buckets?  
  
  ---
  
  