hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.62k stars 9.01k forks source link

Version 3.0.0 provider giving INIParseError: invalid state with ASTKind #14439

Open Andrew13648 opened 3 years ago

Andrew13648 commented 3 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.29

Affected Resource(s)

Expected Behavior

Expecting terraform apply to work with the 3.0.0 provider.

Actual Behavior

When I do terraform apply with the 3.0.0 provider, I am getting this error:

Error: error configuring Terraform AWS Provider: Error creating AWS session: SharedConfigLoadError: failed to load config file, C:\Users\myusername\.aws\config
caused by: INIParseError: invalid state with ASTKind { {4 NONE 0 [61]} true [{expr {1 STRING 0 [97 122 117 114 101 95 115 101 115 115 105 111 110 95 100 117 114 97 116 105 111 110 95 109 105 110 117 116 101 115]}
true []}]} and TokenType none

I tried deleting my .terraform folder and rerunning terraform init to get around this, but no luck with that. However, I was able to get this to work successfully when I downgraded my provider back to 2.70.0, so it appears it is related to the 3.0.0 provider.

I did check the ASCII numbers from the error string and see that it is representing azure_session_duration_minutes. I do have this line in my config file:

azure_session_duration_minutes=

I found that if I deleted this line from my config, it does work as expected. However, it seems like this should not be required since this was present and working in the previous provider version.

Steps to Reproduce

  1. terraform apply

Important Factoids

N/A

References

bflad commented 3 years ago

Hi folks 👋 Any issues with parsing AWS configuration files, such as incorrect handling with certain options or hard to understand INIParseError errors, will need bug reports filed upstream in the AWS Go SDK. The Terraform AWS Provider is wholly dependent on the AWS Go SDK to properly work with INI files that are also supported by other AWS SDKs and the AWS CLI (boto/Python).

praveendandu02 commented 3 years ago

Change the Provider Version Configuration

For example, given this previous configuration: provider "aws" { version = "~> 2.70" }

it worked for me.

amoncusir commented 3 years ago

Hi! I have the same issue with AWS config file, but I found a solution (and I don't know if it applies with your casuistry).

In my case, the config file looks like this:

# Amazon Web Services Config File used by AWS CLI, SDKs, and tools
# More comments...

[default]
# The access key and secret key pair identify your account and grant access to AWS.

aws_access_key_id = [accessKey]
aws_secret_access_key = [secretKey]

# More config...

I think that the problem is the values [accessKey] and [secretKey]!

I cleaned the config file (removing all comments and these fields) and it works. Try it!

schwinbp commented 2 years ago

Ran into this issue using init with the 0.13.5 and 0.14.11 versions. Ran init again with 0.12.18 and no error.

Error: error configuring S3 Backend: Error creating AWS session: SharedConfigLoadError: failed to load config file, C:\Users\myuseraccounthere.aws\config caused by: INIParseError: invalid state with ASTKind {section_stmt {1 STRING 0 [112 114 111 102 105 108 101 32]} true []} and TokenType comment

However, I did hit issue again running the plan with 0.12.18...

sumanbk92 commented 1 year ago

Many Thanks @amoncusir The issue is with .credentials file. Removed rest all after [default] profile and it worked

github-actions[bot] commented 1 week ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!