Skip to content

Specified workspace "name" conflicts with TF_WORKSPACE environment variable #508

@unkinected

Description

@unkinected

I'm not quite sure when this started, but all of a sudden I'm receiving an error when trying to import resources into Terraform.

I've essentially followed the Azure guide: https://learn.microsoft.com/en-us/azure/developer/terraform/azure-export-for-terraform/export-advanced-scenarios. To reproduce

  1. Run: aztfexport resource -o tempdir --non-interactive --hcl-only
  2. This successfully generates files in a new directory called "tempdir." I go through these files and tweak names to better match our naming scheme.
  3. Run: aztfexport map --non-interactive --append './tempdir/aztfexportResourceMapping.json'
  4. Error

Error: error running terraform init for the output directory: exit status 1

Error: Invalid workspaces configuration

Specified workspace "name" conflicts with TF_WORKSPACE environment variable.

The 'workspaces' block configures how Terraform CLI maps its workspaces for
this single
configuration to workspaces within a Terraform Cloud organization. Two
strategies are available:

tags - A set of tags used to select remote Terraform Cloud
workspaces to be used for this single
configuration. New workspaces will automatically be tagged with these tag
values. Generally, this
is the primary and recommended strategy to use. This option conflicts with
"name".

name - The name of a single Terraform Cloud workspace to be used
with this configuration.
When configured, only the specified workspace can be used. This option
conflicts with "tags"
and with the TF_WORKSPACE environment variable.

This has worked fine up til now, though I'll admit it has been a little while since I've needed to do this. My terraform file hasn't changed:

terraform {
cloud {
organization = "My Company"
workspaces {
name = "Azure"
}
}

I've tried setting a TF_WORKSPACE environment variable but that doesn't do anything. If I remove the workspaces block from terraform.tf I get a new error:

Error: error running terraform init for the output directory: exit status 1

Error: Invalid command-line option

The -force-copy option is for migration between state backends only, and is
not applicable when using Terraform Cloud.

State storage is handled automatically by Terraform Cloud and so the state
storage location is not configurable.

I was on an older version of aztfexport and just upgraded to 0.14.0, no change.
I was on terraform 1.6.6 and upgraded to 1.7.4, no change.

Any ideas? Generating the resource files works, but importing them into terraform state does not.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions