1. 地形图
• 每一行的SSM自动化需求
{
"description": "Invoke Lambda Function ${key}",
"name": "InvokeLambdaFunction${key}",
"action": "aws:invokeLambdaFunction",
"inputs": {
"FunctionName": "arn:aws:lambda:us-east-1:${account_number}:function:hello",
"InvocationType": "RequestResponse",
"Payload": "{"key1": "${account_number}", "key2": "<first value from arg_map>", "key3": "<second value from arg_map>"}"
}
}
主 席
provider "aws" {
region = "us-east-1" # Set your desired region here
}
variable "account_number" {
default = "123456789"
}
variable "arg_map" {
type = map(list(string))
default = {
"key" = ["a", "b"]
"key" = ["d", "e"]
"key" = ["g", "h"]
"key" = ["j", "k"]
}
}
resource "aws_ssm_document" "sync_epv2asm" {
name = "sync_epv2asm"
document_type = "Automation"
content = templatefile("${path.module}/ssm_document_template.tftpl", {
account_number = var.account_number
arg_map = var.arg_map
})
}
ssm_document_template.tftpl
{
"schemaVersion": "0.3",
"description": "My description.",
"mainSteps": [
% for key, values in arg_map:
{
"description": "Invoke Lambda Function ${key}",
"name": "InvokeLambdaFunction${key}",
"action": "aws:invokeLambdaFunction",
"inputs": {
"FunctionName": "arn:aws:lambda:us-east-1:${account_number}:function:hello",
"InvocationType": "RequestResponse",
"Payload": "{"key1": "${account_number}", "key2": "${values[0]}", "key3": "${values[1]}"}"
}
}% if not loop.last %,
% endif
% endfor
]
}
运行地貌应用
│ Error: Invalid function argument │ │ on 主 席 line 23, in resource "aws_ssm_document" "sync_epv2asm": │ 23: content = templatefile("${path.module}/ssm_document_template.tftpl", { │ 24: account_number = var.account_number │ 25: arg_map = var.arg_map │ 26: }) │ ├──────────────── │ │ while calling templatefile(path, vars) │ │ var.arg_map is a map of list of string │ │ Invalid value for "vars" parameter: vars map does not contain key "key", referenced at ./ssm_document_template.tftpl:7,44-47.
around不见。 我甚至试图让一些大赦国际看看看他们是否并查明我的问题。
互联网上的一些东西显示“{}”围绕“%”的模板。 这并没有改变我的错误。
对我为什么不能把模板投入工作有什么想法?