I am writing a gitlab-ci stage to run terratest tests for my terraform and I get and error when is authenticating to AWS.
I have correctly set as env variables for the pipeline AWS credentials and the tests are successfully running locally.
my stage is:
terratest:
stage: Test and Lint
image:
name: "hashicorp/terraform:1.0.5"
entrypoint:
- "/usr/bin/env"
- "PATH=/go/bin:/usr/local/go/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
needs:
- Package-lambda
script:
- go mod init $(basename $PWD)
- go mod tidy
- go test ./test/ -v -timeout 30m
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|production)$/ || $CI_COMMIT_BRANCH =~ /^(master|production)$/'
and the error message is:
with module.image-lambda-s3-trg.provider["registry.terraform.io/hashicorp/aws"],
TestTerraformFirst 2022-08-10T14:17:13Z logger.go:66: │ on .terraform/modules/image-lambda-s3-trg/image-lambda-s3-trg/main.tf line 2, in provider "aws":
TestTerraformFirst 2022-08-10T14:17:13Z logger.go:66: │ 2: provider "aws" {
TestTerraformFirst 2022-08-10T14:17:13Z logger.go:66: │
TestTerraformFirst 2022-08-10T14:17:13Z logger.go:66: ╵
TestTerraformFirst 2022-08-10T14:17:13Z retry.go:99: Returning due to fatal error: FatalError{Underlying: error while running command: exit status 1; ╷
│ Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
I wonder if the problem can be causes by the fact that I am using a module in my terraform and I just wrote a simple tests to check if the outputs a correct.
any clue on how to debug/solve this?