Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[provider.aws v2.24.0] No valid credential sources found for AWS Provider. #9962

Closed
trentmillar opened this issue Sep 2, 2019 · 11 comments · Fixed by #14077
Closed

[provider.aws v2.24.0] No valid credential sources found for AWS Provider. #9962

trentmillar opened this issue Sep 2, 2019 · 11 comments · Fixed by #14077
Assignees
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.
Milestone

Comments

@trentmillar
Copy link

trentmillar commented Sep 2, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.12.7
+ provider.aws v2.24.0

Affected Resource(s)

  • provider.aws v2.24.0

Terraform Configuration Files

provider "aws" {
  region = "us-west-2"
  profile = "btg"
}

Debug Output

terraform init --reconfigure                  

Initializing the backend...
bucket
  The name of the S3 bucket

  Enter a value: xxxxxxx
key
  The path to the state file inside the bucket

  Enter a value: us-west-2/development/terraform-infr.tfstate

region
  The region of the S3 bucket.

  Enter a value: us-west-2


Error: No valid credential sources found for AWS Provider.
        Please see https://terraform.io/docs/providers/aws/index.html for more information on
        providing credentials for the AWS Provider

Expected Behavior

I should successfully reinit my terraform project.

Actual Behavior

Error: No valid credential sources found for AWS Provider.

Steps to Reproduce

Confirmed the following:

  • the credentials file is located in ~.aws\credentials with the contents,
    [btg]
    aws_access_key_id=...
    aws_secret_access_key=...
    
  • don't have the env var AWS_PROFILE set
  • do not pass the access or secret key directly into terraform, just the profile
  • confirm the credential file works with the AWS CLI using the option --profile btg while executing any command
  1. terraform apply

Important Factoids

I can init, apply, destroy,... without any changes if I simply rename the named profile in the the credentials file to [default] instead of [btg].

Another side affect to consider is after renaming the profile to default there is no warning or error even when the provide "aws" { ...'s profile is set to "btg"?

References

#6320 except I confirmed there is nothing funky (tabs, extra spaces) within the credentials file

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 2, 2019
@trentmillar
Copy link
Author

trentmillar commented Sep 3, 2019

I also ran this command with TF_LOG=debug,

TF_LOG=debug terraform init --reconfigure             
2019/09/02 18:03:31 [INFO] Terraform version: 0.12.7  
2019/09/02 18:03:31 [INFO] Go runtime version: go1.12.9
2019/09/02 18:03:31 [INFO] CLI args: []string{"/usr/local/bin/terraform", "init", "--reconfigure"}
2019/09/02 18:03:31 [DEBUG] Attempting to open CLI config file: /Users/trentm/.terraformrc
2019/09/02 18:03:31 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/09/02 18:03:31 [INFO] CLI command args: []string{"init", "--reconfigure"}

Initializing the backend...
2019/09/02 18:03:31 [DEBUG] command: asking for input: "bucket"
bucket
  The name of the S3 bucket

  Enter a value: a_bucket

2019/09/02 18:03:39 [DEBUG] command: asking for input: "key"
key
  The path to the state file inside the bucket

  Enter a value: a_key

2019/09/02 18:03:41 [DEBUG] command: asking for input: "region"
region
  The region of the S3 bucket.

  Enter a value: us-west-2

2019/09/02 18:03:44 [INFO] Setting AWS metadata API timeout to 100ms
2019/09/02 18:03:45 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id

Error: No valid credential sources found for AWS Provider.
        Please see https://terraform.io/docs/providers/aws/index.html for more information on
        providing credentials for the AWS Provider

@trentmillar
Copy link
Author

I just inited a new project and the aws.provider is newer, * provider.aws: version = "~> 2.26"

It is still failing to resolve any !default profile's

TF_LOG=debug terraform apply -var-file="dev.tfvars"
2019/09/03 12:10:29 [INFO] Terraform version: 0.12.7  
2019/09/03 12:10:29 [INFO] Go runtime version: go1.12.9
2019/09/03 12:10:29 [INFO] CLI args: []string{"/usr/local/bin/terraform", "apply", "-var-file=dev.tfvars"}
2019/09/03 12:10:29 [DEBUG] Attempting to open CLI config file: /Users/trentm/.terraformrc
2019/09/03 12:10:29 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/09/03 12:10:29 [INFO] CLI command args: []string{"apply", "-var-file=dev.tfvars"}
2019/09/03 12:10:29 [INFO] Setting AWS metadata API timeout to 100ms
2019/09/03 12:10:29 [INFO] Ignoring AWS metadata API endpoint at default location as it doesn't return any instance-id

Error: No valid credential sources found for AWS Provider.
        Please see https://terraform.io/docs/providers/aws/index.html for more information on
        providing credentials for the AWS Provider

@redjab
Copy link

redjab commented Sep 6, 2019

@trentmillar Have you found any solution to this? I'm running into the same issue where any non-default profile is simply ignored

@trentmillar
Copy link
Author

@redjab No, I'm currently opening ~/.aws/credentials and manually changing the profiles to [default].

@bsakweson
Copy link

I just ran into this same problem today. When I changed the profile name to default, I am able to connect but not with the actual profile name.

@redjab
Copy link

redjab commented Sep 9, 2019

I found it a bit easier to set AWS_PROFILE in the command line then run terraform apply rather than changing the creds file every time -- but it's still just a workaround. Would be great if this can be expressed in code instead.

@timrourke
Copy link

I'm still seeing the same behavior, running Terraform with the following versions:

Terraform v0.12.15
+ provider.aws v2.36.0

Changing my desired AWS profile name to [default] from its proper name definitely worked, but this is highly undesirable as a workaround; raises a fear that someone might use this workaround and then target the wrong AWS environment.

@woz5999
Copy link
Contributor

woz5999 commented Mar 16, 2020

I was just hit by this issue. In my case, the projects were already initialized and in use for some time utilizing the default profile but broke when I added the "provider" parameter to the backend configuration. Removing the .terraform folder from the local project and re-initializing solved the issue for me.

@bflad bflad added bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 7, 2020
@bflad bflad added this to the v3.0.0 milestone Jul 7, 2020
bflad added a commit that referenced this issue Jul 7, 2020
Reference: #5018
Reference: #6913
Reference: #7333
Reference: #9236
Reference: #9869
Reference: #9898
Reference: #9962
Reference: #9986
Reference: #10507
Reference: #11429
Reference: #12236
Reference: #12727
Reference: #12815
Reference: #13057

Changes:

```
NOTES

* provider: Credential ordering has changed from static, environment, shared credentials, EC2 metadata, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata) to static, environment, shared credentials, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata)
* provider: The `AWS_METADATA_TIMEOUT` environment variable no longer has any effect as we now depend on the default AWS Go SDK EC2 Metadata client timeout of one second with two retries

ENHANCEMENTS

* provider: Always enable shared configuration file support (no longer require `AWS_SDK_LOAD_CONFIG` environment variable)
* provider: Add `assume_role` configuration block `duration_seconds`, `policy_arns`, `tags`, and `transitive_tag_keys` arguments

BUG FIXES

* provider: Ensure configured STS endpoint is used during `AssumeRole` API calls
* provider: Prefer AWS shared configuration over EC2 metadata credentials by default
* provider: Prefer CodeBuild, ECS, EKS credentials over EC2 metadata credentials by default
```

Output from acceptance testing:

```
--- PASS: TestAccAWSProvider_Region_AwsCommercial (3.89s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (3.90s)
--- PASS: TestAccAWSProvider_Region_AwsChina (3.99s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (4.22s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (4.29s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (4.37s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (4.38s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (4.39s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (4.40s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (4.40s)
--- PASS: TestAccAWSProvider_Endpoints_Deprecated (4.42s)
--- PASS: TestAccAWSProvider_Endpoints (4.53s)
--- PASS: TestAccAWSProvider_AssumeRole_Empty (8.32s)
```
@bflad bflad self-assigned this Jul 7, 2020
bflad added a commit that referenced this issue Jul 13, 2020
…14077)

* Update module hashicorp/aws-sdk-go-base to v0.5.0

* provider: Authentication updates for Terraform AWS Provider v3.0.0

Reference: #5018
Reference: #6913
Reference: #7333
Reference: #9236
Reference: #9869
Reference: #9898
Reference: #9962
Reference: #9986
Reference: #10507
Reference: #11429
Reference: #12236
Reference: #12727
Reference: #12815
Reference: #13057

Changes:

```
NOTES

* provider: Credential ordering has changed from static, environment, shared credentials, EC2 metadata, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata) to static, environment, shared credentials, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata)
* provider: The `AWS_METADATA_TIMEOUT` environment variable no longer has any effect as we now depend on the default AWS Go SDK EC2 Metadata client timeout of one second with two retries

ENHANCEMENTS

* provider: Always enable shared configuration file support (no longer require `AWS_SDK_LOAD_CONFIG` environment variable)
* provider: Add `assume_role` configuration block `duration_seconds`, `policy_arns`, `tags`, and `transitive_tag_keys` arguments

BUG FIXES

* provider: Ensure configured STS endpoint is used during `AssumeRole` API calls
* provider: Prefer AWS shared configuration over EC2 metadata credentials by default
* provider: Prefer CodeBuild, ECS, EKS credentials over EC2 metadata credentials by default
```

Output from acceptance testing:

```
--- PASS: TestAccAWSProvider_Region_AwsCommercial (3.89s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (3.90s)
--- PASS: TestAccAWSProvider_Region_AwsChina (3.99s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (4.22s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (4.29s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (4.37s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (4.38s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (4.39s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (4.40s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (4.40s)
--- PASS: TestAccAWSProvider_Endpoints_Deprecated (4.42s)
--- PASS: TestAccAWSProvider_Endpoints (4.53s)
--- PASS: TestAccAWSProvider_AssumeRole_Empty (8.32s)
```

* docs/provider: Add authentication changes section to version 3 upgrade guide and remove pre-3.0 notes

Co-authored-by: Renovate Bot <[email protected]>
@bflad
Copy link
Contributor

bflad commented Jul 13, 2020

Hi folks 👋 Version 3.0 of the Terraform AWS Provider will include a few authentication changes that should help in this case. Similar enhancements and fixes were applied to the Terraform S3 Backend (part of Terraform CLI) in version 0.13.0-beta2.

The Terraform AWS Provider major version update will release in the next two weeks or so. Please follow the v3.0.0 milestone for tracking the progress of that release. If you are still having trouble after updating when its released, please file a new issue. Thanks!

@ghost
Copy link

ghost commented Jul 31, 2020

This has been released in version 3.0.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Aug 12, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. provider Pertains to the provider itself, rather than any interaction with AWS.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants