-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
import of aws_key_pair fails because it ignores assumed role of provider #5347
Comments
Hi @maxdreamland 👋 Does importing work if you add the
|
Hi, and thanks for your advice! yes that actually worked. I was able to import both key pairs with that method. and "terraform plan" looks plausible too now. that seems to confirm that the provider attribute specified in the aws_key_pair resource is ignored, right? so maybe there's still a todo? I noticed one more thing in the "terraform plan", it shows the public_key attribute of the imported key to be empty (which it is not in reality), but i assume thats because you probably can't query the public key via the aws cli for security reasons, right? If that's the case, should i use lifecycle/ignore_changes on the public_key field to avoid terraform reapplying the key pair over and over again? |
@maxdreamland hope these answer your questions:
If you remove the provider argument on your resources (e.g.
Correct! In this case, we can only retrieve the key name and fingerprint from the EC2 API: https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#KeyPairInfo |
alright then. Thank you for your help with this. I think this can be closed now. best regards |
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! |
Hi,
i'm trying to import two ssh key pairs that already exist in AWS, to link them to the resource entries in my .tf file (see below for the .tf file)
when i execute this:
terraform import aws_key_pair.prod_ssh_key aws_cccs_prod
then terraform is complaining that the key i'm trying to import does not exist:
Terraform detected a resource with this ID doesn't exist. Please verify the ID is correct. You cannot import non-existent resources using Terraform import.
I'm pretty sure the reason is either that the import ignores the provider attribute in the aws_key_pair resource (and therefore looks for the key in the wrong account), or it may have something to do with the fact that i don't have defined a default provider (provider without an alias) and therefore the import may be looking in the account my credentials are associated with?
My credentials (AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY) are set to an AWS account that holds only user accounts and no resources of it's own. From this account we use assume role to switch to our development and production accounts that hold the actual resources, in this case the key pairs.
I assume that the import is ignoring the assume role that is defined in the two providers and therefore looks for the keys in the account that holds only our user accounts.
I can kinda get this to work if i provide a default provider (one without alias) that assumes the development role for example, then i can import the dev-keypair (and only that one). then i switch the default provider to the production role and can import the prod key. but later on, during plan and apply terraform tries to do non-plausible changes that imply it does not associate the imported keys with the right account. so it's not really a viable workaround.
I would consider this a bug.
best regards
Mario
Community Note
Terraform Version
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
i would have expected that both key pairs can be imported, since they exist and the providers are configured correctly to point to the two different accounts where the keys are located.
Actual Behavior
see above (beginning of post)
The text was updated successfully, but these errors were encountered: