hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.

Home Page:http://www.packer.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

For_each on data source like http

mahsoud opened this issue · comments

Description

for_each attribute support on configuration resource

Use Case(s)

At times we may iterate on multiple data sources.

Potential configuration

data "http" "this" {
  for_each = local.fileset
  URL         = "https://git.myserver/api/v4/projects/1000/repository/files/${replace(each.value, "/", "%2F")}?ref=master"
  request_headers = {
    PRIVATE-TOKEN = var.TOKEN
  }
}

Potential References

Hi @mahsoud,

Regarding this feature, this would imply we support dynamic on top-level blocks, which is something that is unsupported for everything.
Dynamic blocks are not even supported for data sources for now (though this may be supported someday).

It looks to me that what you're looking for is a list of URIs to fetch, which is something that may be implemented separately from this language change, as part of a data source specialised to do this.
The http data-source is only meant to get one resource through HTTP, maybe a new datasource that accepts a list of URIs and returns them as a list or a map would be appropriate for your use-case. That being said, there's the problem of how to handle errors in this case, I'm not sure what would be expected if one or multiple URIs fail to be fetched, at which point is this considered an error?

Out of curiosity, do you have a practical example of the problem you're trying to solve? Maybe there's something we can help to express with the current capabilities of HCL in Packer.

I'll keep this open for discussion purposes, but I'll mark this as a wontfix for now, since it's likely not something we'll take-on soon (and possibly long-term even).

Thanks!