Terraform: Workspace referencing another via terraform remote state

Created on 27 Mar 2018  ยท  9Comments  ยท  Source: hashicorp/terraform

*Case:*
Working on migrating our code from _Terraform Enterprise Legacy_ to _Terraform Enterprise_. The old environments have been migrated to _Terraform Enterprise_ but I can not reference the new _workspaces_ via remote state.

Terraform Version

0.9.11

Terraform Configuration Files

data "terraform_remote_state" "skeleton" {
  workspace                      = ${terraform.workspace}
  backend                         = "atlas"
  config {
    name                          = "project/name-of-referenced-workspace"
  }
}

# Security Groups
resource "aws_security_group" "web_tier" {
  name                            = "ict_sg_${var.environment}_web"
  description                     = "Allow web traffic"
  vpc_id                          = "${data.terraform_remote_state.skeleton.vpc_id}"
  # HTTP access from anywhere
  ingress {
    from_port                       = 80
    to_port                           = 80
    protocol                          = "tcp"
    cidr_blocks                       = ["0.0.0.0/0"]
  }

  ingress {
    from_port                       = 443
    to_port                           = 443
    protocol                          = "tcp"
    cidr_blocks                       = ["0.0.0.0/0"]
  }
  egress {
    from_port                       = 0
    to_port                           = 0
    protocol                          = "-1"
    cidr_blocks                     = ["0.0.0.0/0"]
  }
}

Debug Output

Crash Output

Error: Error running plan: 1 error(s) occurred:

* aws_security_group.web_tier: 1 error(s) occurred:

* aws_security_group.web_tier: Resource 'data.terraform_remote_state.skeleton' does not have attribute 'vpc_id' for variable 'data.terraform_remote_state.skeleton.vpc_id'


Expected Behavior

Actual Behavior

Steps to Reproduce

  • check in code of both repos to VCS (github)
  • configure auth to terraform enterprise to yo have both workspace.
  • try and get one of the repos to reference the other.
  • Additional Context

    References

    Most helpful comment

    I'm confused, so does this work for non-enterprise or not? If we're using workspaces, how do we referenfe the remote state of another component in the same workspace?

    workspace = ${terraform.workspace}

    Doesn't work.

    All 9 comments

    Hi @im-dofoborh,

    This appears to be a question about Terraform Enterprise.
    A support ticket has been opened for you, and you can continue the discussion there.

    Thanks!

    Thanks @jbardin

    @im-dofoborh @jbardin

    I don't see a workspace argument in the documentation for terraform_remote_state

    https://www.terraform.io/docs/providers/terraform/d/remote_state.html

    Is this just undocumented?

    @thomasbiddle,

    It's documented, but unfortunately there's a bug in the documentation release process for that particular provider (the terraform provider is handled differently than all the others). We have an open issue over at #18430

    I'm confused, so does this work for non-enterprise or not? If we're using workspaces, how do we referenfe the remote state of another component in the same workspace?

    workspace = ${terraform.workspace}

    Doesn't work.

    Any word on this? I'm having the same issue as @stonefury . Unable to use terraform_remote_state with workspaces

    Just figured out a workaround cc @stonefury
    This works for the s3 backend at least.
    Look in s3 and find the tf state that your attempting to import, note the path then specify key accordingly. e.g.

    data "terraform_remote_state" "network" {
      backend = "s3"
    
      config {
        bucket = "mybucket"
        # key should be of the format <workspace_key_prefix>/<workspace>/<key>
        key                  = "nonprod/nonprod/state/foundation"
        ...
      }
    }
    

    I don't believe that this issue is limited to enterprise.

    There's a workaround but I expect the better answer would be that the config supports workspace

    I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

    If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

    Was this page helpful?
    0 / 5 - 0 ratings