I’m using a module which creates kubernetes and aws resources. There’s a flag skipping the aws resources creation which I’m using. All aws resources have count 0. Thus in a way I don’t need an aws provider. If I remove it terraform complains it’s required. But if I leave the provider then it complains:
│ Please see Terraform Registry
│ for more information about providing credentials.
│
│ Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, access disabled to EC2 IMDS via client option, or
│ “AWS_EC2_METADATA_DISABLED” environment variable
This is an example explaining the code I’m using:
provider "aws" {
skip_credentials_validation = true
skip_metadata_api_check = true
skip_region_validation = true
skip_requesting_account_id = true
}
resource "aws_s3_bucket" "disabled"{
count = 0
bucket = "hello-world"
}
You can reproduce the issue by calling:
docker run --rm -it -w $PWD -v $PWD:$PWD --platform=linux/amd64 hashicorp/terraform:1.9.8 init
docker run --rm -it -w $PWD -v $PWD:$PWD --platform=linux/amd64 hashicorp/terraform:1.9.8 plan
Is there something I could do to mock it? I found the mock providers but they can’t be used in this context right (Tests - Provider Mocking | Terraform | HashiCorp Developer) ?