我想在現有的 s3_bucket 上創建一個事件通知(我在當前的 terraform 代碼中沒有設定它)。
我遇到了這個答案:
terraform aws_s3_bucket_notification 現有存盤桶
所以我嘗試了這個。這里,local.bucket_name 是現有存盤桶的名稱。
通知.tf
resource "aws_s3_bucket" "trigger_pipeline" {
bucket = local.bucket_name
}
terraform import aws_s3_bucket.trigger_pipeline local.bucket_name
但是,我不確定如何使用此匯入陳述句。我在資源塊之后使用它嗎?我是否在同一個檔案的開頭使用它?
如果我按原樣使用它,在資源塊下,我會收到以下錯誤:
Invalid block definition: Either a quoted string block label or an opening brace ("{") is expected here.HCL
點這里:aws_s3_bucket.trigger_pipeline
編輯:
所以首先我定義了 s3 資源,如上面的問題所示。然后我跑terraform init。接下來,我terraform import aws_s3_bucket.trigger_pipeline "myoriginalbucketname"在 CLI 上運行。但是,我仍然收到以下錯誤:
Before importing this resource, please create its configuration in the root module. For example:
resource "aws_s3_bucket" "trigger_pipeline" {
# (resource arguments)
}
我想我弄錯了事件的順序
uj5u.com熱心網友回復:
我建議你在這里使用資料塊。Data Block 允許使用在 Terraform 之外定義的資訊,這有助于在現有基礎設施資源上執行 Terraform 代碼(在此處閱讀更多內容),在本例中為 S3 Bucket。與資源塊一樣,資料塊支持引數來指定它們的行為方式;對于 aws_s3_bucket,它是“bucket”(在此處閱讀更多內容)。
data "aws_s3_bucket" "trigger_pipeline" {
bucket = "local.bucket_name"
}
// use data.aws_s3_bucket.trigger_pipeline.<attribute_reference> in script
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = data.aws_s3_bucket.trigger_pipeline.id
// your code block for Notification configuration
}
uj5u.com熱心網友回復:
local.bucket_name在你的 bash 中執行,而不是在 TF 中。您必須實際提供全名:
terraform import aws_s3_bucket.trigger_pipeline "my-bucket-name"
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/481019.html
標籤:亚马逊网络服务 亚马逊-s3 地形 terraform-provider-aws terraform0.12
上一篇:新發布AWS站點后資料未重繪
