Usually, we don't require hard-code credentials for Terraform to work, instead, you can use the CodeBuild IAM role that would be enough for terraform.
The below CodeBuild role with S3 permission which allows creating a bucket, you can modify it accordingly:
version: 0.2
phases:
install:
commands:
- wget https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip -q
- unzip terraform_0.12.28_linux_amd64.zip && mv terraform /usr/local/bin/
- printf "resource \"aws_s3_bucket\" \"test\" {\n\tbucket = \"test-43242-efdfdfd-4444334\"\n\tacl = \"private\"\n}" >> s3.tf
- terraform init
- terraform plan
- terraform apply -auto-approve
Do checkout aws certification training to learn more about AWS.
You can check out the video tutorial on Terraform by Intellipaat!