-
Notifications
You must be signed in to change notification settings - Fork 553
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
Fix panic while importing namespaces in TFVP #1818
Conversation
Writing a dynamic test for this scenario is a bit difficult with the current TF SDK. A dynamic acceptance test would require the test code to set up a secret/auth engine mount within Vault without running a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just left a few thoughts on possible improvements
@vinay-gopalan RE: writing a test for this scenario I wonder if we could make use of the Vault API client (provider.GetClient) to set up a secret/auth engine mount within Vault? I think that should allow us to bypass the plan/apply in the SDK? |
@fairclothjm good question! I actually tried something very similar to what you were pointing at, and it doesn't look like the SDK allows an Import step to be the first step in a testcase 🤔
Error returned because no such resource exists in the state (state non-existent):
The test above also requires some prior set up to the Vault server (setting up the namespaces etc.) before it can be run, which might make it more of a local-only test. I'll dig into it a bit more to see if I can find a better solution, but for now we might have to resort to manual testing |
@vinay-gopalan I found ExternalProviders and it seems like that should allow us to do an import step as the first step. But I couldn't get it to work so maybe I am misunderstanding that field. I agree that manual tests should be ok for now since this will likely take a bit of work to figure out. (If it is even possible at all) |
This PR adds a nil check in the code that performs namespace imports. The code checks the TF state to ensure a namespace is not already set to state, however it does not account for the case where the state attributes are nil. This case occurs when a user would like to perform a
terraform import
command before anyplan
orapply
runs (terraform.tfstate
file does not necessarily exist)The panic was reproduced with the following steps:
vault_mount
resource that has the same path as your engine in the 2nd stepTERRAFORM_VAULT_NAMESPACE_IMPORT
env variable to the value of the created namespaceterraform import vault_mount.<your_mount> <your_path>
Without employing the fix, a panic is generated. With the fix, the import executes successfully.