Chef Solo provisioner in HCL

How do I get this provisioner to work in HCL?

{
  "type": "chef-solo",
  "cookbook_paths": [
    "cookbooks"
  ],
  "json": {
    "ssh-hardening":{
      "ssh":{
        "server":{
          "allow_tcp_forwarding": true
        }
      }
    }
  },
  "run_list": [
    "os-hardening",
    "ssh-hardening"
  ]
}

I thought that it should be this:

provisioner "chef-solo" {
  cookbook_paths = [
    "cookbooks"
  ]

  run_list = [
    "os-hardening",
    "ssh-hardening"
  ]

  json = {
    ssh-hardening = {
      ssh = {
        server = {
          allow_tcp_forwarding = true
        }
      }
    }
  }
}

but when I run packer validate I get an error:

Inappropriate value for attribute "json": element "ssh-hardening": string
required.
1 Like

Hey @b-dean, did you figure it out?

Use json_string with jsonencode instead of json. For example:

json_string = jsonencode(
  {
    "ssh-hardening" = {
      "ssh" = {
        "server" = {
          "allow_tcp_forwarding" = true
        },
      },
    },
  }
)
1 Like