Hi I am writing a terraform resource, which requires authentication. It goes by user specifying the username and password as input in the resource block and then we perform the authentication. Authentication is a one time process, the username and password is not retrieve-able by any means.
Now my problem is: when I write the test, I try to verify the import state, it says the attributes are not equivalent because the username and password is missing from the state, but there is no way to retrieve the username and password for me, since the resource is already authenticated when user want to import it and there is no way to retrieve the password, so may I know what is the best way to handle this situation?
Normally people would make username/password part of their provider configuration, not part of a resource.
Or, are you saying the username and password will be different for every instance of this resource type?
Hey @maxb , yes the username and password will be different for each instance of this resource type
Hi @weilueluo, you can use the ImportStateVerifyIgnore field to ignore the username and password attributes during import state testing
Hey @SBGoods thanks for the suggestion. I wonder will there be any bad side effect on the user if I just simply ignore it? I am new to terraform and not sure if this will open up possibility to leave terraform in an inconsistent state.
@weilueluo I’ve re-read your original question and I’m having difficulty understanding how authentication works with your provider. If the authentication credentials will be different for every instance of the resource, then when a user uses
terraform import to import a resource, they would have to provide the username and password as well. When you import a resource in Terraform, it’s a separate resource instance so it shouldn’t be authenticated with your backend API.
If you want authentication credentials to be shared between different resources then it should be done in the provider configuration like maxb suggested.
Hey @SBGoods Thanks for the information, it is very helpful. There is one last thing that I am not sure even after looking up the documentation: whats the difference between
terraform import in CLI and using import statement?
Hi @weilueluo, if you are referring to the
import state that’s referred to in the testing documentation such as
import state testing then that is just referring to the Terraform state after a
terraform import command is run.
I see, thank you so much!