hashicorp / vscode-terraform

HashiCorp Terraform VSCode extension
https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform
Mozilla Public License 2.0
917 stars 179 forks source link

Pass AWS_PROFILE to extension #609

Closed PePoDev closed 2 years ago

PePoDev commented 3 years ago

I run Terraform: apply from vscode and got this error

Initialization failed: exit status 1 Error: error configuring S3 Backend: no valid credential sources for S3 Backend found. Please see https://www.terraform.io/docs/language/settings/backends/s3.html for more information about providing credentials. Error: NoCredentialProviders: no valid providers in chain. Deprecated. For verbose messaging see aws.Config.CredentialsChainVerboseErrors

How can I pass env AWS_PROFILE into Terraform extension?

gdlx commented 3 years ago

@PePoDev Did you find a workaround since then ?

PePoDev commented 3 years ago

@PePoDev Did you find a workaround since then ?

No 😢

glebsam commented 2 years ago

The question is, why should I pass the AWS_PROFILE? JetBrains IDE works without it. My case not about apply. I see these errors in the extension output. I think, VS Code extension should not require this env var. Maybe it tries to run init? In this case, it's already done from the terminal.

PePoDev commented 2 years ago

I want to run Terraform inside VSCode with another AWS account.

Maybe my question is "How can I specific AWS account to run Terraform with this extension?"

jpogran commented 2 years ago

Hello everyone,

The AWS Terraform provider has a section in the documentation on how to provide credentials and other sensitive information to Terraform when it runs. You'll have to check which method you're using in order to use it with VS Code.

For example, if you're using an Environment variable, you'll have to start VS Code from within a terminal that has that environment variable already populated. VS Code will then inherit all the environment variables of the parent process and any processes VS Code states (in this the case Terraform binary) will also have those environment variables. For example:

$ export AWS_ACCESS_KEY_ID="anaccesskey"
$ export AWS_SECRET_ACCESS_KEY="asecretkey"
$ export AWS_DEFAULT_REGION="us-west-2"
$ code . 

We see a common issue where people start VS Code from the dock in macOS or from the Start menu in Windows and it does not have the same set of environment variables as launching from the command line, so be sure that the place you're starting from has the data you need to execute Terraform.

If you have any further questions about usage, please reach out on our Discuss board and ask over there. I'm going to close this out for now, but please let us know if things do not work.

github-actions[bot] commented 2 years ago

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.