Skip to content
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

Merged
merged 2 commits into from
Apr 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion vault/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,18 @@ func MountCreateContextWrapper(f schema.CreateContextFunc, minVersion *version.V
func importNamespace(d *schema.ResourceData) error {
if ns := os.Getenv(consts.EnvVarVaultNamespaceImport); ns != "" {
s := d.State()
if _, ok := s.Attributes[consts.FieldNamespace]; !ok {
var attemptNamespaceImport bool
if s == nil {
// state does not yet exist
// import is acceptable
attemptNamespaceImport = true
} else {
// only import if namespace
// is not already set in state
_, ok := s.Attributes[consts.FieldNamespace]
vinay-gopalan marked this conversation as resolved.
Show resolved Hide resolved
attemptNamespaceImport = !ok
}
if attemptNamespaceImport {
log.Printf(`[INFO] Environment variable %s set, `+
`attempting TF state import "%s=%s"`,
consts.EnvVarVaultNamespaceImport, consts.FieldNamespace, ns)
Expand Down