Get terraform s3 state bucket name in code

Viewed 336

I have the following terraform backend:

terraform {
  backend "s3" {
    bucket = "zorbo-state-bucket"
    key    = "solutions/test"
    region = "eu-central-1"
  }
}

Is it possible to get the state bucket name somewhere else in my code? For example, instead of writing this:

data "terraform_remote_state" "organization" {
  backend = "s3"
  config = {
    bucket = "zorbo-state-bucket"
    key = "solutions/first"
    region = "eu-central-1"
  }
}

I can replace the bucket name with something like:

data "terraform_remote_state" "organization" {
  backend = "s3"
  config = {
    bucket = terraform.backend.s3.bucket
    key = "solutions/first"
    region = "eu-central-1"
  }
}
0 Answers
Related