Search code examples
datasourcepackeraws-ssmaws-parameter-store

Why am I getting "Missing key/value separator" when using packer convert function


I have the following stored in AWS Systems Manager Parameter Store:

"name_prefix"="base","os"="AmazonLinux2"

I have the following Packer code:

data "amazon-parameterstore" "base" {
  name = "/devops/ami/base"
}

locals {
  parameters = convert({data.amazon-parameterstore.base.value}, map(string))
}

I am receiving the following error:

Error: Missing key/value separator

on packer/aws-amzn2-base.pkr.hcl line 12, in locals: 12: parameters = convert({data.amazon-parameterstore.base.value}, map(string))

Expected an equals sign ("=") to mark the beginning of the attribute value.

Can anyone please help? I am trying to remove the need to have multiple parameters stored which would then require multiple data sources in packer


Solution

  • The usage is mostly correct, but you are attempting to convert a string to a map(string) without interpolating the original string first with the proper syntax:

    locals {
      parameters = convert("{${data.amazon-parameterstore.base.value}}", map(string))
    }
    

    Alternatively, AWS SSM also allows setting multiple parameters with JSON format strings:

    {"name_prefix": "base", "os": "AmazonLinux2"}
    

    and then this can easily be decoded from a JSON format string into a map:

    locals {
      parameters = jsondecode(data.amazon-parameterstore.base.value)
    }
    

    Thus, you have two quick paths forward here depending upon your preference.