Can we modify the existing s3 bucket not managed by terraform?
Use case- I need to attach replication rule to an existing s3 bucket and enable the versioning on it .
You can import a resource to be managed by Terraform. A resource is either fully managed by Terraform or not managed at all. The provider decides exactly which resources exist and what they do. For example a route table and a route within it are two separate resources, so in that case you could have one managed by Terraform and the other not - notwithstanding their possible interactions (for example removing the table would remove the route)
Thanks for your prompt response, I found out that we can’t attach replication rule to existing s3 bucket or I’m wrong?
Seems like we need to attach replication rule at the time of s3 bucket creation via terraform. Though it is supported via console and cloudformation.
If the S3 bucket is managed by Terraform you can adjust various settings (some things would require a destroy and recreate such as changing the bucket name).
So you need to import the S3 bucket to be managed by Terraform
I’m running into a similar issue where I’m importing an existing S3 bucket just to add replication but terraform is trying to destroy the existing bucket and spin up a fresh new instance.
terraform import module.replication-configuration.aws_s3_bucket.example example_bucket
resource "aws_s3_bucket" "example" {
bucket = "example_bucket"
versioning {
enabled = true
}
replication_configuration {
role = var.example_role
rules {
id = "test"
status = "Enabled"
destination {
bucket = var.destination_bucket_arn
replica_kms_key_id = var.destination_kms_key_arn
account_id = var.destination_account_number
access_control_translation {
owner = "Destination"
}
}
}
}
}
When running, I get the following:
Error: error deleting S3 Bucket (example): BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.