英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论