Я пытаюсь создать точки доступа AWS EFS динамически через terraform.
Во-первых, вот код, который я использую:
resource "aws_efs_access_point" "this" {
for_each = { for k, v in var.access_points : k => v if var.create }
file_system_id = var.aws_efs_file_system_id
dynamic "posix_user" {
for_each = try([each.value.posix_user], [])
content {
gid = posix_user.value.gid
uid = posix_user.value.uid
secondary_gids = try(posix_user.value.secondary_gids, null)
}
}
dynamic "root_directory" {
for_each = try([each.value.root_directory], [])
content {
path = try(root_directory.value.path, null)
dynamic "creation_info" {
for_each = try([root_directory.value.creation_info], [])
content {
owner_gid = creation_info.value.owner_gid
owner_uid = creation_info.value.owner_uid
permissions = creation_info.value.permissions
}
}
}
}
/*tags = merge(
var.tags,
try(each.value.tags, {}),
{ Name = try(each.value.name, each.key) },
)*/
}
variable "create" {
description = "Determines whether resources will be created (affects all resources)"
type = bool
default = true
}
variable "access_points" {
description = "A map of access point definitions to create"
type = any
}
variable "aws_efs_file_system_id" {
description = "ID of Elastic File system to which access points will be associated"
type = string
}
/*variable "tags" {
description = "Tags"
type = string
}*/
module "EFS-ap" {
source = "../modules/xxx/xxx/accessPoints"
aws_efs_file_system_id = "fs-0bcf0c0xxxx"
access_points = {
posix_user = {
gid = 1001,
uid = 1001
},
root_directory = {
creation_info = {
owner_gid = 1001,
owner_uid = 1001,
permissions = 0775
},
path : "/hengg/git",
}
}
}
В результате вышеизложенного я увидел, что создаются 3 точки доступа с косой чертой по умолчанию и без каких-либо других данных.
Я знаю, что неправильно передаю значения переменной access_points, что и вызывает эту проблему. Но не могу найти правильный путь.
По сути, мне нужно динамически создавать точки доступа для нескольких путей к корневому каталогу, но прямо сейчас я хочу, чтобы сначала это работало для одного пути к корневому каталогу.
Я пробовал несколько способов передать значения переменных access_points, но безуспешно.
Я ожидаю, что мой код будет динамически создавать точки доступа AWS EFS.





Ваш текущий код просто передает определение одной точки доступа непосредственно на вход access_points.
access_points = {
posix_user = {
gid = 1001,
uid = 1001
},
root_directory = {
creation_info = {
owner_gid = 1001,
owner_uid = 1001,
permissions = 0775
},
path : "/hengg/git",
}
}
Судя по вашим комментариям к коду и реальному коду в модуле, вы ожидаете, что это будет карта определений точек доступа. Карта определений точек доступа будет выглядеть следующим образом (необходимо указать ключ карты):
access_points = {
"my_access_point" = {
posix_user = {
gid = 1001,
uid = 1001
},
root_directory = {
creation_info = {
owner_gid = 1001,
owner_uid = 1001,
permissions = 0775
},
path : "/hengg/git",
}
}
}
Передача определений нескольких точек доступа будет выглядеть следующим образом:
access_points = {
"my_access_point" = {
posix_user = {
gid = 1001,
uid = 1001
},
root_directory = {
creation_info = {
owner_gid = 1001,
owner_uid = 1001,
permissions = 0775
},
path : "/hengg/git",
}
}
"another_access_point" = {
posix_user = {
gid = 1001,
uid = 1001
},
root_directory = {
creation_info = {
owner_gid = 1001,
owner_uid = 1001,
permissions = 0775
},
path : "/hengg/git",
}
}
}
Да, он ожидает карту, а не отдельный объект. По определению карта — это набор ключей и значений.
Спасибо, Марк. Это сработало! Таким образом, в основном в цикле for для переменной access_points он ищет как ключ, так и его значение/значения.