github.com/hashicorp/packer@v1.14.3/command/test-fixtures/hcl/dynamic/build.pkr.hcl (about)

     1  
     2  source "file" "base" {
     3  }
     4  
     5  variables {
     6    images = {
     7      dummy = {
     8        image      = "dummy"
     9        layers     = ["base/main"]
    10      }
    11      postgres = {
    12        image      = "postgres/13"
    13        layers     = ["base/main", "base/init", "postgres"]
    14      }
    15    }
    16  }
    17  
    18  locals {
    19    files = {
    20      foo = {
    21        destination = "fooo"
    22      }
    23      bar = {
    24        destination = "baar"
    25      }
    26    }
    27  }
    28  
    29  build {
    30    dynamic "source" {
    31      for_each = var.images
    32      labels   = ["file.base"]
    33      content {
    34        name         = source.key
    35        target       = "${source.value.image}.txt"
    36        content      = join("\n", formatlist("layers/%s/files", var.images[source.key].layers))
    37      }
    38    }
    39  
    40    dynamic "provisioner" {
    41      for_each = local.files
    42      labels   = ["shell-local"]
    43      content {
    44        inline = ["echo '' > ${var.images[source.name].image}-${provisioner.value.destination}.txt"]
    45      }
    46    }
    47  }