Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11357

Merging remote state file objects in Terraform 0.12.x

$
0
0

@moorichardmoo wrote:

Using Terraform v0.12.9

I’m working on upgrading a project from version 0.11.x to 0.12.9. In this project, each terraform stack references a large number of remote state files.

Rather than defining the remote state files by hand, I kept the code neat and short by defining the remote states using a list, like this:

variable "remote_states" {
  default = ["network", "remote_component1","remote_component2","etc"]
}

data "terraform_remote_state" "remote_states" {
  count   = "${length(var.remote_states)}"
  backend = "s3"

  config {
    bucket = "${var.project}-${var.account_id}-${var.region}"
    key    = "/${var.environment}/${element(var.remote_states,count.index)}.tfstate"
    region = "${var.region}"
  }
}

and then I referred to the outputs like this:
= "${data.terraform_remote_state.remote_states.*.output_name[0]}"

and that always worked, so long as there were never any outputs with the same name as others.

However, I can’t get it working in version 0.12.9. When running the same code I get This object does not have an attribute named “output_name”

I figured I could use a local to amalgamate the remote states, but have tried to use toset() or concat() etc, but I get errors like: “Invalid value for “v” parameter: cannot convert tuple to set of any single type”

Essentially, I want to convert this:

 {
    "output_1" = "foo"
  },
  {
    "output_2" = "bar"
  }

into:

 {
    "output_1" = "foo"
    "output_2" = "bar"
  }

Is there a way of doing this? If not, can we create a way?

Posts: 8

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 11357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>