opentofu/internal/command/arguments/backend.go
Andrei Ciobanu 5603b8a27c
Some checks are pending
build / Build for freebsd_386 (push) Waiting to run
build / Build for linux_386 (push) Waiting to run
build / Build for openbsd_386 (push) Waiting to run
build / Build for windows_386 (push) Waiting to run
build / Build for freebsd_amd64 (push) Waiting to run
build / Build for linux_amd64 (push) Waiting to run
build / Build for openbsd_amd64 (push) Waiting to run
build / Build for solaris_amd64 (push) Waiting to run
build / Build for windows_amd64 (push) Waiting to run
build / Build for freebsd_arm (push) Waiting to run
build / Build for linux_arm (push) Waiting to run
build / Build for linux_arm64 (push) Waiting to run
build / Build for darwin_amd64 (push) Waiting to run
build / Build for darwin_arm64 (push) Waiting to run
build / End-to-end Tests for linux_386 (push) Waiting to run
build / End-to-end Tests for windows_386 (push) Waiting to run
build / End-to-end Tests for darwin_amd64 (push) Waiting to run
build / End-to-end Tests for linux_amd64 (push) Waiting to run
build / End-to-end Tests for windows_amd64 (push) Waiting to run
Quick Checks / List files changed for pull request (push) Waiting to run
Quick Checks / Unit tests for linux_386 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for windows_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm (push) Blocked by required conditions
Quick Checks / Unit tests for darwin_arm64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm64 (push) Blocked by required conditions
Quick Checks / Race Tests (push) Blocked by required conditions
Quick Checks / End-to-end Tests (push) Blocked by required conditions
Quick Checks / Code Consistency Checks (push) Blocked by required conditions
Quick Checks / License Checks (push) Waiting to run
Website checks / List files changed for pull request (push) Waiting to run
Website checks / Build (push) Blocked by required conditions
Website checks / Test Installation Instructions (push) Blocked by required conditions
Refactor init command to use View instead of Ui (#3749)
Signed-off-by: Andrei Ciobanu <andrei.ciobanu@opentofu.org>
2026-02-11 16:29:31 +02:00

59 lines
2 KiB
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package arguments
import (
"flag"
"time"
"github.com/opentofu/opentofu/internal/tfdiags"
)
type Backend struct {
IgnoreRemoteVersion bool
// StateLock indicates if the state should be locked or not.
StateLock bool
// StateLockTimeout configures the duration that it waits for the state lock to be acquired.
StateLockTimeout time.Duration
// ForceInitCopy controls if the prompts for state migration should be skipped or not.
ForceInitCopy bool
// Reconfigure controls if the reconfiguration of the backend should happen with discarding the old configurations.
Reconfigure bool
// MigrateState controls if during the reconfiguration of the backend a migration should be attempted.
MigrateState bool
}
func (b *Backend) AddIgnoreRemoteVersionFlag(f *flag.FlagSet) {
f.BoolVar(&b.IgnoreRemoteVersion, "ignore-remote-version", false, "continue even if remote and local OpenTofu versions are incompatible")
}
func (b *Backend) AddStateFlags(f *flag.FlagSet) {
f.BoolVar(&b.StateLock, "lock", true, "lock state")
f.DurationVar(&b.StateLockTimeout, "lock-timeout", 0, "lock timeout")
}
func (b *Backend) AddMigrationFlags(f *flag.FlagSet) {
f.BoolVar(&b.ForceInitCopy, "force-copy", false, "suppress prompts about copying state data")
f.BoolVar(&b.Reconfigure, "reconfigure", false, "reconfigure")
f.BoolVar(&b.MigrateState, "migrate-state", false, "migrate state")
}
func (b *Backend) migrationFlagsCheck() (diags tfdiags.Diagnostics) {
if b.MigrateState && b.Reconfigure {
return diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Wrong combination of options",
"The -migrate-state and -reconfigure options are mutually-exclusive",
))
}
// Copying the state only happens during backend migration, so setting
// -force-copy implies -migrate-state
if b.ForceInitCopy {
b.MigrateState = true
}
return diags
}