我有 Terraform 模块来预置 AWS 资源。之后terraform plan
,我看到以下错误:
错误:main.tf 第 113 行缺少必需的参数,在模块“ecs-task-execution-role”中:113:模块“ecs-task-execution-role”{ 需要参数“iam_role_name”,但未找到定义.
这是我在中定义的资源../terraform/modules/iam/ecs_iam.tf
:
resource "aws_iam_role" "iam--task-execution-role" {
name = var.iam_role_name
assume_role_policy = data.aws_iam_policy_document.ecs-task-assume-role.json
}
data "aws_iam_policy_document" "ecs-task-assume-role" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
}
}
}
data "aws_iam_policy" "ecs-task-execution-role" {
arn = "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
}
# Attach the above policy to the execution role.
resource "aws_iam_role_policy_attachment" "ecs-task-execution-role" {
role = aws_iam_role.iam-task-execution-role.name
policy_arn = data.aws_iam_policy.ecs-task-execution-role.arn
}
变量定义在../terraform/modules/iam/variables.tf
:
variable "iam_role_name" {
type = string
}
该模块位于../terraform/production/main.tf
:
module "iam-jo-task-execution-role" {
source = "../modules/iam"
iam_role_name = "iam-jo-task-execution-role"
}
# Attach the above policy to the execution role.
module "ecs-task-execution-role" {
source = "../modules/iam"
}
任何帮助表示赞赏。