Reputation: 425
I need to create a aws_s3_bucket_notification that uses existing bucket (not defined in the terraform script)
I'm trying this configuration :
data "aws_s3_bucket" "terraform-bucket-name" {
bucket = "account-bucket-name"
}
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = "${data.aws_s3_bucket.terraform-bucket-name.id}"
lambda_function {
lambda_function_arn = "${aws_lambda_function.something.arn}"
events = ["s3:ObjectCreated:*"]
}
depends_on = ["aws_lambda_function.something", "data.aws_s3_bucket.terraform-bucket-name"]
}
But I have this error:
Error putting S3 notification configuration: InvalidArgument: Unable to validate the following destination configurations
Maybe "data" isn't the proper way of defining an existing bucket... Any help? Thanks!
Upvotes: 1
Views: 3203
Reputation: 37580
You have to define it as a regular resource:
resource "aws_s3_bucket" "my_bucket" {
bucket = "terraform-bucket-name"
Then you have to import it into Terraform's state:
terraform import aws_s3_bucket.my_bucket terraform-bucket-name
Afterwards, terraform plan
will show you the differences between the real world and your code, which you should resolve. If terraform plan
lists no changes, your code matches reality.
See the very end of the documentation..
Upvotes: 2