“为什么在使用packer的转换功能时会出现’缺少键/值分隔符’的错误消息”

huangapple go评论66阅读模式
英文:

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.

英文:

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

答案1

得分: 0

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.

英文:

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.

huangapple
  • 本文由 发表于 2023年4月7日 00:14:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定