Closed crusstu closed 1 month ago
While investigating this further, the correct behaviour is achieved by the use of the TERRAFORM_VAULT_NAMESPACE_IMPORT
environment variable during import operations as documented in the provider: https://github.com/hashicorp/terraform-provider-vault/blob/0318b6b4523ef8a47a7b2ec8f120126166dad9ac/website/docs/index.html.markdown#namespace-support
I think I was expecting to use the VAULT_NAMESPACE
environment variable instead of an additional var to configure the namespace
property during import.
Important to note that the docs say
The import namespace will always be made relative to the
namespace
of theprovider{}
block.
but it's not just the provider block; if both VAULT_NAMESPACE
and TERRAFORM_VAULT_NAMESPACE_IMPORT
are set, TERRAFORM_VAULT_NAMESPACE_IMPORT
will be relative to VAULT_NAMESPACE
(which I think should be expected, but it's not specifically stipulated).
Terraform Core Version
1.9.5
Terraform Vault Provider Version
4.2.0
Vault Server Version
1.16.6+ent
Affected Resource(s)
Expected Behavior
Importing a namespaced LDAP auth method should set the
namespace
attribute for the resource.Provided a matching resource configuration, post-import
terraform apply
commands should indicate no changes are to be applied, and should definitely not force-recreate the LDAP auth method.Actual Behavior
Namespaced LDAP auth methods are imported without a
namespace
attribute, so subsequentterraform apply
commands force-recreate the LDAP auth method as changing thenamespace
attribute requires recreation of the resource.Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
Steps to Reproduce
terraform init
terraform apply
terraform state rm 'vault_ldap_auth_backend.ldap'
terraform import 'vault_ldap_auth_backend.ldap' 'ldap'
terraform plan
namespace
attribute has changed:Debug Output
No response
Panic Output
No response
Important Factoids
No response
References
When namespace support was introduced in #1479 it doesn't seem like any of the import machinery was re-evaluated. The implementation for
vault_ldap_auth_backend
relies onschema.ImportStatePassthroughContext
:https://github.com/hashicorp/terraform-provider-vault/blob/9af82cbd8aa395363f7cdf711c06f4d6f2818d7d/vault/resource_ldap_auth_backend.go#L214-L216
where the doc comment says
Since LDAP auth methods (actually, any auth method) is unaware of its containing namespace, I don't believe ID-only refreshes are possible for namespaced auth methods.
This is the same issue raised in #2030, so I believe all auth methods are likewise impacted.
Would you like to implement a fix?
None