Hi, i want to create a new s3 bucket every time i run terraform apply with a bucket name. i tried with the following terraform configuration. It’s creating s3 bucket for the first time. Any subsequent terraform apply with a new bucket name changing the previous one. Can anyone help?
main.tf
`provider “aws” {
region = var.aws_region
}
resource “aws_s3_bucket” “aqua-robotics-bucket” {
bucket = “${var.env}-${var.company_name}-${var.bucket_name}”
}
resource “aws_s3_bucket_acl” “aqua-robotics-bucket-acl” {
bucket = aws_s3_bucket.aqua-robotics-bucket.id
acl = var.acl
}
resource “aws_s3_bucket_versioning” “aqua-robotics-bucket-versioning” {
bucket = aws_s3_bucket.aqua-robotics-bucket.id
versioning_configuration {
status = var.versioning
}
}`
variables.tf
`variable “aws_region” {
description = “The AWS region to use to create resources.”
default = “eu-north-1”
}
variable “env” {
description = “Deployment Environment”
type = string
default = “dev”
}
variable “company_name” {
description = “Company Name”
type = string
default = “aquarobotics”
}
variable “bucket_name” {
description = “The name of the bucket”
type = string
}
variable “acl” {
type = string
description = " Defaults to private"
default = “private”
}
variable “tags” {
type = map(string)
description = “(Optional) A mapping of tags to assign to the bucket.”
default = {
environment = “DEV”
}
}
variable “versioning” {
type = string
description = “(Optional) A state of versioning.”
default = “Disabled”
}`