Open shoekstra opened 5 years ago
Hi @shoekstra!
The behavior you've described is, unfortunately, as intended by the current design. Environment variables configured for a Terraform Cloud workspace are there to configure how Terraform runs in the remote execution environment, which is separate from when you run Terraform locally.
It's unlikely that this will change as you describe because that would involve the CLI being able to access the values of sensitive environment variables in the remote workspace like AWS_SECRET_ACCESS_KEY
, which is not allowed by the API -- sensitive environment variables are write-only.
For the moment we're going to use this issue to represent the more general idea that ideally the remote backend should be able to run other operations like importing or state rm
remotely too, because that's likely the only way we could make what you requested work without violating the write-only rule for sensitive variables. There is no short-term plan to do that, but it is a limitation we're aware of and would like to address eventually.
In the meantime, the intended usage pattern is indeed that for local operations you will need to obtain suitable values for the environment variables out of band and configure them on your local system. In many environments, the credentials that an individual would use to run a local operation are different than the ones that have been configured for Terraform Cloud itself to use. For example, they might be configured to have only read access to the target account and specifically-controlled access to update the workspace state snapshots in S3, thus ensuring that only Terraform Cloud remote runs can be used for to make changes to infrastructure, and thus any real infrastructure changes are captured as runs in the Terraform Cloud UI.
Thanks for the prompt reply!
Being new to using the remote backend I made the assumption the state subcommands were also being run remotely but, as they're not, what you've said makes sense and I agree with the rationale behind current implementation.
Started bumping into this issue today too, being able to use the remote backend to import resources would be helpful. I'd assumed the import would take place entirely remotely, just as a terraform plan
does (which avoids exposing the sensitive environment variables) when using the remote backend. I was quite surprised when it didn't already work this way.
It's not a huge issue, but it does make things slightly more complicated than they need to be when importing resources.
We have just run into this as well. To say that this is a disappointment is an understatement. A big reason we purchased Terraform Enterprise was so that we could allow more of our staff to make changes through an approval process without them having access to credentials. With all the various compliance we follow this is a necessity.
There are a lot of resources that we managed in Ansible or not at all which we want to manage with Terraform. The inability to run terraform import
without credentials is a real problem for us.
I'm having a bit of trouble using your workaround, which is an issue since there's no other way to import into the remote
backend that I know of.
Terraform ignores my local environment variable credentials, and using -var-file
or -var
doesn't work either, which is an even bigger issue in my opinion than this feature not being implemented.
However I do fully agree this is an essential feature for Terraform Cloud to be viable for many users. The documentation on this is misleading since it claims that the remote backend supports the import command yet the variable docs say best practice is to set the 'sensitive' flag for provider credentials, making the import
command unusable in workspaces which use provider credentials (every workspace surely on Terraform Cloud surely).
bumping this issue for attention. We don't want to distribute and have engineers maintain credentials locally.
IMO import should run on the cloud remote runners as well
Bumping this as well.
bumping
Thanks for your interest in this issue! This is just a reminder to please avoid "+1" comments, and to use the upvote mechanism (click or add the 👍 emoji to the original post) to indicate your support for this issue. This is how we prioritize issues for roadmap planning. Thanks again for the feedback!
Terraform Version
Terraform Configuration Files
Expected Behavior
As I've stored
AWS_DEFAULT_REGION
,AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
as environment variables in my workspace, I should be able to use them whilst doingterraform import
like I can forterraform plan
.Actual Behavior
I receive an error that the provider is not configured correctly (as the environment variables configured in my workspace are not available):
I can successfully import a resource if I prepend the command with the variables, e.g.
Steps to Reproduce
terraform state rm <name of resource>