[英]add metadata to S3 object in terraform
我正在嘗試根據 S3 中的現有文件在上傳新文件期間添加元數據。 我使用的代碼如下:
provider "aws" {
region = "xxx"
profile = "xxx"
}
data "aws_s3_bucket_object" "index_cdn" {
bucket = "bucket name"
key = "index.html"
}
resource "aws_s3_bucket_object" "index" {
bucket = "bucket name"
key = "index_new.html"
source = "${path.module}/index.html"
content_type = "text/html"
metadata = lower(data.aws_s3_bucket_object.index_cdn.metadata)
}
output "metadata" {
value = data.aws_s3_bucket_object.index_cdn.metadata
}
它失敗並顯示以下錯誤消息。
Error: Incorrect attribute value type
on main.tf line xx, in resource "aws_s3_bucket_object" "index":
xx: metadata = lower(data.aws_s3_bucket_object.index_cdn.metadata)
Inappropriate value for attribute "metadata": map of string required.
當我在沒有代碼塊resource "aws_s3_bucket_object" "index"
情況下運行代碼時,輸出如下:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ metadata = {
+ "Codebuild-Buildarn" = "arn:aws:codebuild:xxxxx"
+ "Codebuild-Content-Md5" = "716d3e5bc7c972f89033aad7dd6c9a9f"
+ "Codebuild-Content-Sha256" = "d015e0a093938b21135c2ba5abc23278d4c5961d7e18aa8e3b9a748cc09e6bc7"
}
知道如何解決嗎? 謝謝您的幫助。
應該是, keys
應該是小寫的:
metadata = {for k, v in data.aws_s3_bucket_object.index_cdn.metadata: lower(k) => v}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.