My terraform setup was running fine with Jenkins but then suddenly I am seeing this error when running the Jenkinsfile (see below). But the problem is not with the Jenkinsfile because even when I run this without Jenkins now, I see the same error.
The only modifications I was making was to the Jenkinsfile at the time where the config file and the credentials file were removed.
I went to the /home/ubuntu/.aws/credentials and the file is completely missing (config file is also missing). How could the file suddenly be removed?
Here is the error in the Jenkins script and below that without Jenkins running terraform from the terminal:(so it is not Jenkins it is a local issue of the credentials not being re-generated).
I was making no changes to providers.tf file when this happened just the Jenkinsfile and the jenkinsfile is using AWS_SHARED_CREDENTIALS_FILE=‘/home/ubuntu/.aws/credentials’
as ENV variable.
Plan: 2 to add, 0 to change, 0 to destroy.
Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
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, http response error StatusCode: 404, request to EC2 IMDS failed
with provider[“Terraform Registry”],
on providers.tf line 13, in provider “aws”:
13: provider “aws” {
==========
this is without Jenkins
dave:~/environment/mtc-terraform-ansible-jenkins (dev_terraform_FULL_ansible) $ terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
- create
Terraform planned the following actions, but then encountered a problem:
random_id.mtc_compute_node_id[0] will be created
- resource “random_id” “mtc_compute_node_id” {
- b64_std = (known after apply)
- b64_url = (known after apply)
- byte_length = 2
- dec = (known after apply)
- hex = (known after apply)
- id = (known after apply)
}
random_id.random will be created
- resource “random_id” “random” {
- b64_std = (known after apply)
- b64_url = (known after apply)
- byte_length = 2
- dec = (known after apply)
- hex = (known after apply)
- id = (known after apply)
}
Plan: 2 to add, 0 to change, 0 to destroy.
╷
│ Error: configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│
│ 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, http response error StatusCode: 404, request to EC2 IMDS failed
│
│
│ with provider[“Terraform Registry”],
│ on providers.tf line 13, in provider “aws”:
│ 13: provider “aws” {
==========
My providers.tf does use the shared_credentials_files
provider “aws” {
region = “us-west-1”
shared_credentials_files=[“/home/ubuntu/.aws/credentials”]
}
======
dave:~/environment $ aws configure list
Name Value Type Location
---- ----- ---- --------
profile None None
access_key None None
secret_key None None
region None None
=====
I am on AWS Cloud9. The AWS CLI is installed automatically on this Cloud9 with my login credentials. I know I can re-create the files manually but can someone help me out so that I do it correctly. I also see there is an aws configure command that can do this for me but there is also a aws configure set aws_session_token but where do I get the token (ephemeral).
What could have happened here?
warmest regards
Dave