I already have a bucket in the AWS account, I just want to upload the code so that the terraform does not create additional resources and deletes the existing ones. Things like lifecycle don't help, terraform gives an error.
resource "aws_s3_bucket" "static_website" {
for_each = var.env == "ololo" ? { "bucket" = var.bucket_name } : {}
bucket = each.value["bucket"]
website {
index_document = "index.html"
error_document = "index.html"
}
lifecycle {
ignore_changes = all
}
}
resource "aws_s3_bucket_public_access_block" "static_website" {
for_each = aws_s3_bucket.static_website
bucket = each.value.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
variable "bucket_name" {
type = string
description = "Name of the bucket."
default = ""
}
variable "env" {
type = string
description = "Environment variable."
default = "dev"
}