据我所知,我们可以使用资源 here.
通过 terraform 创建 Lex 机器人 (V1)我无法在任何地方找到使用 terraform 在 Lex V2 平台上创建机器人的任何资源。 那么 Terraform 现在是否支持 Lex v2?如果没有,是否有任何解决方法?
根据官方文档,
aws
提供者仍然不直接支持它,但是按照 GitHub 问题中的建议,您可以使用支持 V2 的awscc
。检查问题here
这里是一个如何使用
awscc
provider 来制作它的例子
resource "aws_iam_role" "lex_bot_role" {
name = "lex_bot_role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Service = "lex.amazonaws.com"
}
Action = "sts:AssumeRole"
}
]
})
}
resource "aws_iam_policy" "lex_bot_policy" {
name = "lex_bot_policy"
path = "/"
description = "Policy that allows a Lex bot to access AWS resources."
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
]
Resource = "*"
},
{
Effect = "Allow"
Action = [
"lex:CreateBotVersion",
"lex:CreateIntentVersion",
"lex:DeleteBot",
"lex:DeleteBotAlias",
"lex:DeleteBotChannelAssociation",
"lex:DeleteBotVersion",
"lex:DeleteIntent",
"lex:DeleteIntentVersion",
"lex:DeleteSlotType",
"lex:DeleteSlotTypeVersion",
"lex:PutBot",
"lex:PutBotAlias",
"lex:PutBotChannelAssociation",
"lex:PutIntent",
"lex:PutSlotType"
]
Resource = "*"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lex_bot_policy_attachment" {
policy_arn = aws_iam_policy.lex_bot_policy.arn
role = aws_iam_role.lex_bot_role.name
}
resource "awscc_lex_bot" "pizza_order_bot" {
name = var.bot_name
description = "A bot for ordering pizza"
role_arn = aws_iam_role.lex_bot_role.arn
idle_session_ttl_in_seconds = 300
data_privacy = {
child_directed = false
}
bot_tags = [
{
key = "Environment"
value = "Development"
},
]
depends_on = [
#TODO: Fix this and try to make it use the variables
# aws_lex_intent.order_pizza # The bot depends on the intent
aws_iam_role.lex_bot_role
]
}