Karthik K
Karthik K

Reputation: 243

Unable to create a s3 bucket with versioning using terraform

I am creating a S3 bucket using Terraform on AWS.

I am unable to create a s3 bucket with versioning using terraform. I am Getting "Error putting S3 versioning: AccessDenied" when I try terraform apply.

Terraform plan works with no issues.

provider "aws" {
  region = "us-east-1"
}

variable "instance_name" {}
variable "environment" {}


resource "aws_s3_bucket" "my_dr_bucket" {
  bucket = "${var.instance_name}-dr-us-west-2"
  region = "us-west-2"
  acl    = "private"
  versioning {
    enabled = "true"
  }
}

Gettin gthe below error: Error: Error putting S3 versioning: AccessDenied: Access Denied status code: 403, request id: 21EBBB358558C617

Upvotes: 0

Views: 4060

Answers (2)

Karthik K
Karthik K

Reputation: 243

Below code resolved the issue:

    provider "aws" {
  region = "us-east-1"
}

provider "aws" {
  alias  = "west"
  region = "us-west-2"
}

variable "instance_name" {}
variable "environment" {}

resource "aws_s3_bucket" "my_dr_bucket" {
  provider = "aws.west"
  bucket = "${var.instance_name}-dr-us-west-2"
  region = "us-west-2"
  acl    = "private"
  versioning {
          enabled = true
  }
}

Upvotes: 0

dmkvl
dmkvl

Reputation: 768

Make sure you are creating S3 bucket in the same region your provider is configured for.

Upvotes: 2

Related Questions