'Terraform file for AWS S3 bucket keeps getting Error: Invalid provider configuration

Edit: I've modified the question to show the entire main.tf file, now.

I have a Terraform file that is supposed to create an AWS S3 bucket, but one of the errors I keep getting every time I run terraform plan is this:

│ Error: Invalid provider configuration
│ Provider "registry.terraform.io/hashicorp/aws" requires explicit configuration. Add a provider block to the root module and configure the provider's required arguments as described in the provider documentation.

The main.tf file:

terraform {
    backend  "s3" {
    region         = "us-east-1"
    bucket         = "bucketname"
    key            = "path/terraform.tfstate" 
    dynamodb_table = "tf-state-lock" 
    access_key = "<access_key>"
    secret_key = "<secret_key"
    }

    required_providers {
      aws = {
        version = " ~> 3.0"
        source = "registry.terraform.io/hashicorp/aws"
      }
    }

} 

provider "aws" {
  alias  = "east" 
  region = "us-east-1"
  access_key = "access_key"
  secret_key = "secret_key"
}

resource "aws_s3_bucket" "tf-remote-state" {
  bucket = "bucketname" 

  versioning {
    enabled = true
  }

  lifecycle {
    prevent_destroy = true
  }
}

resource "aws_dynamodb_table" "dynamodb-tf-state-lock" {
  name            = "tf-state-lock" 
  hash_key        = "LockID"
  read_capacity   = 20
  write_capacity = 20

  attribute {
    name = "LockID"
    type = "S"
  }

  tags = {
    name = "state lock"
  }
} 

What am I doing wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source