github.com/hashicorp/packer@v1.14.3/website/content/partials/datasources/local-dependency-limitation.mdx (about)

     1  
     2  At this present time the use of locals within data sources such as the example below is not supported. 
     3  
     4  ```hcl
     5  locals {
     6    cloud_owners           = ["happycloud"]
     7    cloud_base_filter_name = "cloud-hvm-2.0.*-x86_64-gp2"
     8  }
     9  
    10  data "happycloud" "happycloud-linux2-east" {
    11    filters = {
    12      name = local.cloud_base_filter_name
    13    }
    14    most_recent = true
    15    owners = local.cloud_owners
    16  }
    17  ```
    18  
    19  Locals can reference data sources but data sources can not reference locals to avoid cyclic dependencies, where a local
    20  may reference a data source that references the same local or some other locals variable. The preferred method, at this time,
    21  for referencing user input data within a data source is to use the `variable` block. 
    22  
    23  ```hcl
    24  variable "cloud_base_filter_name" {
    25    type     = string
    26    default  = "cloud-hvm-2.0.*-x86_64-gp2"
    27  }
    28  
    29  variable "cloud_owners" {
    30    type     = string
    31    default  = "happycloud"
    32  }
    33  
    34  data "happycloud" "happycloud-linux2-east" {
    35    filters = {
    36      name =  var.cloud_base_filter_name
    37    }
    38    most_recent = true
    39    owners = var.cloud_owners
    40  }
    41  ```
    42