title: Ephemeral environments using GCP, Cloud Build and Terraform workspaces
body: <p>As the title says, trying to leverage Cloud Build and Terraform workspaces to create arbitrary ephemeral environments in the same GCP project, mapping to a branch.</p>
  <p>My Cloud Build pipeline works but <code>terraform apply</code> doesn't seem to be honouring the workspace I'm trying to set, in that resources from the previous builds are destroyed, even if they were supposed to be in another workspace.</p>
  <p>cloud_build.yaml</p>
  <pre><code>  - id: 'tf workspace'
      name: 'hashicorp/terraform:1.0.2'
      args: ['workspace','new',$BRANCH_NAME]
  
    - id: 'tf workspace'
      name: 'hashicorp/terraform:1.0.2'
      args: ['workspace','select',$BRANCH_NAME]
  
    - id: 'tf init'
      name: 'hashicorp/terraform:1.0.2'
      args: ['init']
  
    - id: 'tf plan'
      name: 'hashicorp/terraform:1.0.2'
      args: ['plan',&quot;-var&quot;,&quot;branch_name=$BRANCH_NAME&quot;,&quot;-var&quot;,&quot;project_id=$PROJECT_ID&quot;]
  
    - id: 'tf apply'
      name: 'hashicorp/terraform:1.0.0'
      args: ['apply',&quot;-auto-approve&quot;,&quot;-var&quot;,&quot;branch_name=$BRANCH_NAME&quot;,&quot;-var&quot;,&quot;project_id=$PROJECT_ID&quot;]
  
  </code></pre>
  <p>The backend is simply:</p>
  <pre><code>terraform {
    backend &quot;gcs&quot; {
      bucket = &quot;my-tfstate-bucket&quot;
    }
  }
  </code></pre>
  <p>Am I missing something about workspaces? It would seem they're not really being reflected in the remote state. I know you're able to specify a specific workspace in the tf backend config, but since these workspaces are dynamic, I'd been hoping that setting the workspace via the CLI would set some kind of namespace in the uploaded remote state and take care of the separation.</p>
  <p><strong>EDIT</strong> Just to confirm that I am naming all of my components differently, with the current branch name as a suffix, but TF will still destroy components created when a different branch was run.</p>