Terraform plan : Failed to query available provider packages

I have successfully been able to execute “terraform init”. I see the packages in .terraform directory. But, when I run “terraform plan” I get an error message: Failed to query available provider packages. This is running on a windows system.

$  terraform init 

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 3.51.0"...
- Installing hashicorp/aws v3.51.0...
- Installed hashicorp/aws v3.51.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
$ terraform plan
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

To view this run in a browser, visit:
https://xxx.xxx.net/app/yyyyy/runs/run-kTWgUW6EGtWrZhpg

Waiting for the plan to start...

Terraform v0.14.11
Configuring remote state backend...
Initializing Terraform configuration...

Setup failed: Failed terraform init (exit 1): <nil>

Output:

Initializing the backend...

Successfully configured the backend "remote"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...

Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider hashicorp/aws:
the previously-selected version 3.51.0 is no longer available

- Reusing previous version of hashicorp/aws from the dependency lock file

Hi @snuttam,

Based on the messages you shared here it seems that for some reason the remote execution environment got a different result when it asked the registry for available versions of the provider hashicorp/aws, such that version 3.51.0 wasn’t included in the list.

That particular release of the AWS provider was published over a week before you created this forum topic, so I’m not sure what would cause this inconsistency. In order to investigate further, can you say whether you are using Terraform Cloud or Terraform Enterprise (self-hosted Terraform Cloud), and if you are using Terraform Cloud whether you are using the default execution environment provided by Terraform Cloud or if you are using a local agent?

@apparentlymart I am using Terraform Enterprise. After much digging around I figured out that an environment variable was not set. This was causing the the TFE not to be executed correctly causing the error message which had nothing to do with the fact that I was not able to reach TFE.
Thank you for your response! Much appreciate it.