Back to Packer

Local Dependency Limitation

website/content/partials/datasources/local-dependency-limitation.mdx

1.15.31.0 KB
Original Source

At this present time the use of locals within data sources such as the example below is not supported.

hcl
locals {
  cloud_owners           = ["happycloud"]
  cloud_base_filter_name = "cloud-hvm-2.0.*-x86_64-gp2"
}

data "happycloud" "happycloud-linux2-east" {
  filters = {
    name = local.cloud_base_filter_name
  }
  most_recent = true
  owners = local.cloud_owners
}

Locals can reference data sources but data sources can not reference locals to avoid cyclic dependencies, where a local may reference a data source that references the same local or some other locals variable. The preferred method, at this time, for referencing user input data within a data source is to use the variable block.

hcl
variable "cloud_base_filter_name" {
  type     = string
  default  = "cloud-hvm-2.0.*-x86_64-gp2"
}

variable "cloud_owners" {
  type     = string
  default  = "happycloud"
}

data "happycloud" "happycloud-linux2-east" {
  filters = {
    name =  var.cloud_base_filter_name
  }
  most_recent = true
  owners = var.cloud_owners
}