# Trying to access output from remote state

**URL:** <https://discuss.hashicorp.com/t/trying-to-access-output-from-remote-state/69798>\
**Category:** Terraform\
**Created:** [September 6, 2024, 4:01pm UTC](https://discuss.hashicorp.com/t/trying-to-access-output-from-remote-state/69798 "2024-09-06T16:01:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![v123](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/v123/32/41856_2.png) [@v123](https://discuss.hashicorp.com/u/v123)\
**Post date:** [September 6, 2024, 4:01pm UTC](https://discuss.hashicorp.com/t/trying-to-access-output-from-remote-state/69798/1 "2024-09-06T16:01:44Z")

</div>

Hey all,  
Want to be able to get remote state output ( instance ids )and use that in a custom module that creates an ALB .  
Existing code works - I can add multiple members with multiple data blocks defined

> data “terraform\_remote\_state” “mydata” {  
> backend = “s3”  
> config = {  
> region = var.region  
> bucket = “abc-{var.region}-{xxx}-tf-states”  
> key = “env:/${var.environment}-abc/terraform.tfstate”  
> }  
> }
> 
> module “mymodule” {
> 
> members = [  
> data.terraform\_remote\_state.mydata.outputs.instance-id
> 
> ]
> 
> }

Refactored code throws an error on plan - This object does not have an attribute named instance-id .

> locals {  
> members = {  
> default = [“env:/{var.environment}-xxx/terraform.tfstate", "env:/{var.environment}-xxy/terraform.tfstate”,]  
> dev = [“env:/{var.environment}-xxx/terraform.tfstate", "env:/{var.env2}-xxc/terraform.tfstate”]
> 
> }  
> }
> 
> data “terraform\_remote\_state” “mydata” {  
> for\_each = lookup(local.members, var.env2, “default”)  
> backend = “s3”  
> config = {  
> region = var.region  
> bucket = “abc-{var.region}-{xxx}-tf-states”  
> key = each.value  
> }  
> }
> 
> module “mymodule” {
> 
> members = [for outputs in data.terraform\_remote\_state.mydata : outputs.instance-id]
> 
> }

---

<div class="post-metadata">

**Author:** ![v123](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/v123/32/41856_2.png) [@v123](https://discuss.hashicorp.com/u/v123)\
**Post date:** [September 6, 2024, 5:26pm UTC](https://discuss.hashicorp.com/t/trying-to-access-output-from-remote-state/69798/2 "2024-09-06T17:26:18Z")

</div>

I messed around with it and got it to work - just posting here if it helps. Since the custom module accepts a list for members - I used this

members = tolist([for outputs,state in data.terraform\_remote\_state.mydata : state.outputs.instance-id])

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/hashicorp/original/1X/79bf76adfd92a75631996933098f9ce29d37abf3.svg) [@system](https://discuss.hashicorp.com/u/system)\
**Post date:** [March 5, 2025, 5:26pm UTC](https://discuss.hashicorp.com/t/trying-to-access-output-from-remote-state/69798/3 "2025-03-05T17:26:19Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
