This is not the first time, and if you are out there and seeing a similar error, this may be the soltuion you are looking for.

terraform plan

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: configuring Terraform AWS Provider: IAM Role (arn:aws:iam::111222333444:role/YourRole) cannot be assumed.
│
│ There are a number of possible causes of this - the most common are:
│   * The credentials used in order to assume the role are invalid
│   * The credentials do not have appropriate permission to assume the role
│   * The role ARN is not valid
│
│ AWS Error: operation error STS: AssumeRole, https response error StatusCode: 0, RequestID: , request send failed, Post "https://sts.eu-central-1.amazonaws.com/": dial tcp: lookup sts.eu-central-1.amazonaws.com on [2001:8a0:6727:d900::1]:53: no such host
│
│
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on _provider.tf line 1, in provider "aws":
│    1: provider "aws" {
│
╵
╷
│ Error: configuring Terraform AWS Provider: IAM Role (arn:aws:iam::111222333444:role/YourRole) cannot be assumed.
│
│ There are a number of possible causes of this - the most common are:
│   * The credentials used in order to assume the role are invalid
│   * The credentials do not have appropriate permission to assume the role
│   * The role ARN is not valid
│
│ AWS Error: operation error STS: AssumeRole, https response error StatusCode: 0, RequestID: , request send failed, Post "https://sts.eu-central-1.amazonaws.com/": dial tcp: lookup sts.eu-central-1.amazonaws.com on [2001:8a0:6727:d900::1]:53: no such host
│
│
│   with provider["registry.terraform.io/hashicorp/aws"].dev,
│   on _provider.tf line 18, in provider "aws":
│   18: provider "aws" {

All my logins where right, I was using them all along, even more, I have a differnt CLI window open on my computer with the same login working just fine.

Then my eyes glased at something:

dial tcp: lookup sts.eu-central-1.amazonaws.com on [2001:8a0:6727:d900::1]:53: no such host

Hum, no such host? port 53 ? is this a DNS error?

I quickly changed my DNS from the default ISP (shame on you Altice) to CloudFlare ones:

1.1.1.1
1.0.0.1
2606:4700:4700::1111
2606:4700:4700::1001

Guess what, problem solved, my Terraform is working again, it was not an IAM error at all, it was all about the DNS caches on my ISP.

Next time you see a STS error, consider changing your DNS to a different provider and may save you some unicorn hunt.x