Data.terraform_remote_state.<data_source>.outputs is object with no attributes

I have been unable to pull state information from my terraform_remote_state source. I continue to get the error that 'outputs has no attributes.

This is the configuration of my remote_states.tf file;

data "terraform_remote_state" "core-ca" {

  backend = "s3"

  config           = {

    bucket         = "terraform-state-xxxxxxxxx"

    region         = "us-east-1"

    key            = "terraform-core-ca-state"

    profile        = "xxxxxx"

    dynamodb_table = "terraform-state-lock-dynamo"

    encrypt        = true

    role_arn       = "xxxxxx"

  }

}

This is my call to terraform_remote_states;

destination_cidr_block         = data.terraform_remote_state.core-ca.outputs.cidr_block

Along with all of my other output I get this error from a terraform plan;

  90:   destination_cidr_block         = data.terraform_remote_state.core-ca.outputs.cidr_block
    |----------------
    | data.terraform_remote_state.core-ca.outputs is object with no attributes

This object does not have an attribute named "cidr_block".

I am running terraform version v0.14.7

The data source is from another module so I have also been unable to call the module to get the information and I believe that the only to get information from the other module is to query the terraform_remote_state.

Be aware that I have also tried to configure a local version of the data as follows;

data "terraform_remote_state" "core-ca-local" {

  backend = "local"

  config = {

    path = "../core-ca/.terraform/terraform.tfstate"

  }

}

When I do this with the following;

destination_cidr_block         = data.terraform_remote_state.core-ca-local.outputs.cidr_block

I get the same error;

  90:   destination_cidr_block         = data.terraform_remote_state.core-ca-local.outputs.cidr_block
    |----------------
    | data.terraform_remote_state.core-ca-local.outputs is object with no attributes

This object does not have an attribute named "cidr_block".

From the terraform-core-cs-state.json file I see the following

  "version": 4,
  "terraform_version": "0.14.7",
  "serial": 1,
  "lineage": "de121872-2302-c648-6ca2-3909ae82c39c",
  "outputs": {},

It appears that there is no attributes in the outputs field.

I feel like I’m missing something basic. I had been using version 0.11 but I am starting fresh with this new version. Any help would be appreciated.

Also, be aware that I am deploying this into Canada if that makes a difference.

If you want to access a variable from a remote state, the root module of that other stack must output the value. It looks like your have not added an output block for cidr_block.

Canada should not matter here, keyboard might be colder up north and your keys might be a little harder to press :wink:

1 Like

Thanks for the response ohmer! I was thinking along the same line but I am using common modules to build this environment and in that module for the cidr_block, there is an output statement. Do I still call that with a data call or do I use a module call? and if it is a module call, how do I access another stack’s modules?

The output blocks need to be in the root module

2 Likes

As @stuart-c said, you can’t access other stack submodule outputs. Only the root module outputs. That’s why you need the root module to output the output of a submodule.

Something like:

1/ Stack A root module (required provider block omitted)

terraform {
  backend {
    // reference to state file A in shared backend
  }
}

module "m" {
  source = "..."
}

output "m_cidr_block" {
  value = module.m.cidr_block
}

2/ The source for module m must output the value you output in the root module.

output "cidr_block" {
  value = aws_vpc.this.cidr_block
}

Note that the root module and submodule output names do not need to be the same. I usually have the module name prefix the root module output like above.

I have not checked the syntax snippets above. A verified syntax and more complete example is here: Build a Module | Terraform - HashiCorp Learn

1 Like