[Solved] error configuring S3 Backend: no valid credential sources for S3 Backend found


Ok I managed to fix this issue. You have to remove profile from provider and other .tf files files.
So my main.tf file is –

provider "aws" {
    region = "${var.region}"
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.30"
    }
  }
  backend "s3" {

  }
}

And backend.dev.conf is –

bucket = "bucket"
key    = "dev/xxx.tfstate"
region = "ap-south-1"

And most importantly, You have to put acccess key, access key id and region inside circleci-> your project -> environment variable,
And you have to setup AWS CLI on circleci, apparently inside a job config.yml

version: 2.1

orbs:
  python: circleci/[email protected]
  aws-cli: circleci/[email protected]

jobs:
  build: 
    #  will use a python 3.10.2 container
    docker:
      - image: cimg/python:3.10.2
    working_directory: ~/project

plan-apply:
    executor: aws-cli/default
    docker:
      - image: docker.mirror.hashicorp.services/hashicorp/terraform:light
    working_directory: ~/project
    steps:
      - checkout

      - aws-cli/setup:
          aws-access-key-id: aws_access_key_id
          aws-secret-access-key: aws_secret_access_key
          aws-region: region

      - run:
          name: get aws acc info
          command: aws sts get-caller-identity
      
      - run:
          name: Init infrastructure
          command: sh scripts/init.sh dev

      - run:
          name: Plan infrastructure
          command: sh scripts/plan.sh dev

      - run:
          name: Apply infrastructure
          command: sh scripts/apply.sh dev
.....
.....

This solved the issue. But you have to init, plan and apply inside the job where you set up aws cli. I might be wrong to do setup and plan inside same job, but I’m learning now and this did the job. API changed and old tutorials don’t work nowadays.
Comment me your suggestions if any.

2

solved error configuring S3 Backend: no valid credential sources for S3 Backend found