terraform-contour-mirror/modules/yc-s3/main.tf
Work 99fcdf5717 fix(yc-s3): use iam_binding instead of bucket_policy
Replace yandex_storage_bucket_policy with yandex_storage_bucket_iam_binding
for proper Yandex Cloud access bindings on bucket level
2026-02-03 13:57:14 +03:00

57 lines
1.5 KiB
HCL

locals {
buckets_map = { for bucket in var.buckets : bucket.name => bucket }
}
resource "yandex_iam_service_account" "sa" {
for_each = local.buckets_map
name = "${each.key}-sa"
description = "Service account for ${each.key} bucket"
}
resource "yandex_iam_service_account_static_access_key" "sa_key" {
for_each = local.buckets_map
service_account_id = yandex_iam_service_account.sa[each.key].id
description = "Static access key for ${each.key} bucket"
}
resource "yandex_storage_bucket" "this" {
for_each = local.buckets_map
bucket = each.key
acl = each.value.acl
folder_id = var.folder_id
dynamic "versioning" {
for_each = try(each.value.versioning.enabled, false) ? [1] : []
content {
enabled = true
}
}
dynamic "cors_rule" {
for_each = try(each.value.cors.enabled, false) ? [1] : []
content {
allowed_headers = try(each.value.cors.allowed_headers, [])
allowed_methods = try(each.value.cors.allowed_methods, [])
allowed_origins = try(each.value.cors.allowed_origins, [])
expose_headers = try(each.value.cors.expose_headers, [])
max_age_seconds = try(each.value.cors.max_age_seconds, 3600)
}
}
}
resource "yandex_storage_bucket_iam_binding" "uploader" {
for_each = local.buckets_map
bucket = yandex_storage_bucket.this[each.key].bucket
role = coalesce(each.value.role, var.default_bucket_role)
members = [
"serviceAccount:${yandex_iam_service_account.sa[each.key].id}"
]
depends_on = [yandex_storage_bucket.this]
}