terraform_remote_state as data source not working as expected in 0.7-rc1

1,849 views
Skip to first unread message

cha...@workmarket.com

unread,
Jun 1, 2016, 1:35:59 PM6/1/16
to Terraform
Not sure I am implementing this correctly but assumed it would work pretty much like resource remote state.  But when i update the syntax to use the new data source functionality, none of the outputs are being pulled in.

I have two terraform states vpc and subnet.  Vpc is set up with a remote config of s3.  Subnet is referencing that remote state to get one of its outputs (vpc_id).

Here is my vpc tf file:

variable "region" {
    default = "us-west-2"
}

provider "aws" {
    region = "${var.region}"
}

resource "aws_vpc" "vpc" {
  cidr_block           = "10.130.0.0/16"
  enable_dns_support   = true
  enable_dns_hostnames = true

  tags      { Name = "test-vpc-v7" }
  lifecycle { create_before_destroy = true }
}

output "vpc_id"   { value = "${aws_vpc.vpc.id}" }
output "vpc_cidr" { value = "${aws_vpc.vpc.cidr_block}" }


I set up the remote config as such

terraform remote config -backend=s3 -backend-config="bucket=wm-tfstate" -backend-config="key=terraform-v7-test-vpc.tfstate" -backend-config="region=us-east-1"

I run the apply and vpc is created, remote tfstate file exists.

I now go to my subnet state which is referencing this remote state.  Based on the example listed here https://github.com/hashicorp/terraform/blob/master/website/source/docs/providers/terraform/d/remote_state.html.md I set up the file as follows

variable "region" {
    default = "us-west-2"
}

provider "aws" {
    region = "${var.region}"
}

data "terraform_remote_state" "vpc" {
    backend = "s3"
    config {
        bucket = "wm-tfstate"
        key = "terraform-v7-test-vpc.tfstate"
        region = "us-east-1"
    }
}

resource "aws_subnet" "public" {
  vpc_id            = "${data.terraform_remote_state.vpc.id}"
  count             = "1"

  cidr_block        = "10.130.0.0/24"
  availability_zone = "us-west-2a"

  map_public_ip_on_launch = true

  tags { 
    Name  = "test-subnet-us-west-2a"
    Terraform = "true"
  }
}


When I do a terraform show, it does not list any of the outputs from above.  Obviously when I do an apply it fails.  Here is the output from show:

$ terraform show
data.terraform_remote_state.vpc:
  id = 2016-06-01 14:57:13.738455992 +0000 UTC
  backend = s3
  config.# = 3
  config.bucket = wm-tfstate
  config.key = terraform-v7-test-vpc.tfstate
  config.region = us-east-1
  output.# = 0


I have tested other providers like the aws one to call "data "aws_availability_zones" "zones" {}" and it will resolve those.  The remote state one does not seem to work.  Before I file a bug just wanted to make sure I was attempting to implement this correctly.

Thanks,
Chris

cha...@workmarket.com

unread,
Jun 1, 2016, 6:08:56 PM6/1/16
to Terraform
Sorry, just to clarify I pasted in the wrong interpolation variable.  It should be 

    vpc_id            = "${data.terraform_remote_state.vpc.output.vpc_id}"

But it still fails as it doesn't find the outputs from the remote state anyways

James Nugent

unread,
Jun 2, 2016, 12:57:12 PM6/2/16
to Terraform
Hi Chris,

Thanks for the report. This doesn't sound great! I'll try to reproduce and back to you. If I can reproduce I'll move this to a GitHub issue and post a link to it here.

Regards,


James

cha...@workmarket.com

unread,
Jun 9, 2016, 9:25:12 AM6/9/16
to Terraform
Hey James,

Any update on this?  I found this comment which seems to be alluding to the broken code.  


I can file it as a bug if you haven't already.

Thanks,
Chris

James Nugent

unread,
Jun 9, 2016, 10:45:34 AM6/9/16
to Terraform
Hi Chris,

I'm working on that one right now - the actual bug is fixed (locally) but the test coverage is also being improved to reduce the chance of future regressions here.

Thanks,


James

cha...@workmarket.com

unread,
Jun 9, 2016, 10:52:47 AM6/9/16
to Terraform
awesome, thank you!

James Nugent

unread,
Jun 11, 2016, 8:43:18 AM6/11/16
to Terraform
Hi all,

Thanks for your patience on this issue. There is now a pull request open (awaiting review) that fixes this issue: it turned out to not be as simple as it first looked!

If anyone is interested in reviewing, it is available here: https://github.com/hashicorp/terraform/pull/7127/commits

One point of note (which will be noted in the CHANGELOG): the syntax for outputs has changed from ${terraform_remote_state.name.output.outputname} to simply ${terraform_remote_state.name.outputname} - you can then use indexing operations on complex types.

Thanks,


James

Robert Ford

unread,
Oct 11, 2016, 4:50:03 PM10/11/16
to Terraform
It would be nice if someone updated the upgrade guide at https://www.terraform.io/upgrade-guides/0-7.html to note that you also need to remove the .output part.  It still says

Migrating to the equivalent Data Source is as simple as changing the resource keyword to data in your declaration and prepending data. to attribute references elsewhere in your config.

After reading the upgrade doc like everyone points too I wasted a good 45 mins trying to figure this one out before I found this post and actually read the last comment at that time.

Thanks,

robo

Lowe Schmidt

unread,
Oct 12, 2016, 5:50:36 AM10/12/16
to terrafo...@googlegroups.com
Hey Robert,

the homepage is available on github, please open a ticket or PR with the necessary changes. 

br

--
Lowe Schmidt | +46 723 867 157

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f3e8a8e0-7e30-4869-8439-381520e585ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ni...@nicksantamaria.net

unread,
Oct 12, 2016, 11:08:16 PM10/12/16
to Terraform
I have created a pull request which adds documentation to the 0.7 upgrade guide detailing changes to remote state references.

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages