amazon-web-services - 将元数据添加到 terraform 中的 S3 对象
问题描述
我正在尝试根据 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}
推荐阅读
- notepad++ - 如何在notepad++中同时搜索两个项目
- c++ - 如何指示 CMAKE 在 Visual Studio 中使用英特尔 MKL
- node.js - 连接猫鼬的语法
- nosql - MarkLogic:MarkLogic 错误日志文件中的日志类型异常?
- java - 模拟可选参数时出现空指针异常
- javascript - Firestore 错误“更新不存在的查询”
- selenium - 如何自动单击并从下拉菜单中选择并保存?
- ruby-on-rails - 生产 Sidekiq
- apache-camel - 骆驼路线不为文件延迟连续轮询文件
- android - 在放大和缩小时移动图像视图上的对象