Here is the full error:
Please see Terraform Registry
│ for more information about providing credentials.
│
│ AWS Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded
│
│
│ with provider[“registry.terraform.io/hashicorp/aws”],
│ on main.tf line 19, in provider “aws”:
│ 19: provider “aws” {
I simply followed the 8 video AWS tutorial on Terrafon at the Terraform site, and this failure occurred on the 8th video where we are shown how to migrate the local files to Terraform Cloud. The code I pasted here came directly from the instructions provided by Terraform. I hope this helps.
I had the same problem.
I created variable set for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
but it seems it is not enough. I was getting
Warning: Value for undeclared variable
The root module does not declare a variable named "AWS_ACCESS_KEY_ID" but a value was found in file "/home/tfc-agent/.tfc-agent/component/terraform/runs/run-mdoPMhwPa6ePGrGS/terraform.tfvars". If you meant to use this value, add a "variable" block to the configuration.
To silence these warnings, use TF_VAR_... environment variables to provide certain "global" settings to all configurations in your organization. To reduce the verbosity of these warnings, use the -compact-warnings option.
Warning: Value for undeclared variable
The root module does not declare a variable named "AWS_SECRET_ACCESS_KEY" but a value was found in file "/home/tfc-agent/.tfc-agent/component/terraform/runs/run-mdoPMhwPa6ePGrGS/terraform.tfvars". If you meant to use this value, add a "variable" block to the configuration.
To silence these warnings, use TF_VAR_... environment variables to provide certain "global" settings to all configurations in your organization. To reduce the verbosity of these warnings, use the -compact-warnings option.
Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found. Please see https://registry.terraform.io/providers/hashicorp/aws for more information about providing credentials. AWS Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request canceled, context deadline exceeded
with provider["registry.terraform.io/hashicorp/aws"]
on main.tf line 18, in provider "aws":
provider "aws" {
Do I really set access_key and secret_key in provider and variables to make it work Terraform cloud?
I read terraform official docs but none of them mention about defining key in terraform provider. and GitHub - hashicorp/learn-terraform-cloud does not have access_key and secret_key in provider
I found the problem myself.
There are two different types of variables on variable set.
Terraform variable and Environment variable. and it is Terraform variable by default.
Ensure that you choose environment variable for AWS keys