UX for terraform init that copies state to TFC
This commit is contained in:
parent
d04c01573c
commit
261a2b49d3
|
@ -434,12 +434,21 @@ func (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Meta) backendMigrateEmptyConfirm(source, destination statemgr.Full, opts *backendMigrateOpts) (bool, error) {
|
func (m *Meta) backendMigrateEmptyConfirm(source, destination statemgr.Full, opts *backendMigrateOpts) (bool, error) {
|
||||||
inputOpts := &terraform.InputOpts{
|
var inputOpts *terraform.InputOpts
|
||||||
Id: "backend-migrate-copy-to-empty",
|
if opts.DestinationType == "cloud" {
|
||||||
Query: "Do you want to copy existing state to the new backend?",
|
inputOpts = &terraform.InputOpts{
|
||||||
Description: fmt.Sprintf(
|
Id: "backend-migrate-copy-to-empty-cloud",
|
||||||
strings.TrimSpace(inputBackendMigrateEmpty),
|
Query: "Do you want to copy existing state to Terraform Cloud?",
|
||||||
opts.SourceType, opts.DestinationType),
|
Description: fmt.Sprintf(strings.TrimSpace(inputBackendMigrateEmptyCloud), opts.SourceType),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputOpts = &terraform.InputOpts{
|
||||||
|
Id: "backend-migrate-copy-to-empty",
|
||||||
|
Query: "Do you want to copy existing state to the new backend?",
|
||||||
|
Description: fmt.Sprintf(
|
||||||
|
strings.TrimSpace(inputBackendMigrateEmpty),
|
||||||
|
opts.SourceType, opts.DestinationType),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.confirm(inputOpts)
|
return m.confirm(inputOpts)
|
||||||
|
@ -475,12 +484,23 @@ func (m *Meta) backendMigrateNonEmptyConfirm(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask for confirmation
|
// Ask for confirmation
|
||||||
inputOpts := &terraform.InputOpts{
|
var inputOpts *terraform.InputOpts
|
||||||
Id: "backend-migrate-to-backend",
|
if opts.DestinationType == "cloud" {
|
||||||
Query: "Do you want to copy existing state to the new backend?",
|
inputOpts = &terraform.InputOpts{
|
||||||
Description: fmt.Sprintf(
|
Id: "backend-migrate-to-tfc",
|
||||||
strings.TrimSpace(inputBackendMigrateNonEmpty),
|
Query: "Do you want to copy existing state to Terraform Cloud?",
|
||||||
opts.SourceType, opts.DestinationType, sourcePath, destinationPath),
|
Description: fmt.Sprintf(
|
||||||
|
strings.TrimSpace(inputBackendMigrateNonEmptyCloud),
|
||||||
|
opts.SourceType, sourcePath, destinationPath),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputOpts = &terraform.InputOpts{
|
||||||
|
Id: "backend-migrate-to-backend",
|
||||||
|
Query: "Do you want to copy existing state to the new backend?",
|
||||||
|
Description: fmt.Sprintf(
|
||||||
|
strings.TrimSpace(inputBackendMigrateNonEmpty),
|
||||||
|
opts.SourceType, opts.DestinationType, sourcePath, destinationPath),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Confirm with the user that the copy should occur
|
// Confirm with the user that the copy should occur
|
||||||
|
@ -807,6 +827,12 @@ configured %[2]q backend. Do you want to copy this state to the new %[2]q
|
||||||
backend? Enter "yes" to copy and "no" to start with an empty state.
|
backend? Enter "yes" to copy and "no" to start with an empty state.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const inputBackendMigrateEmptyCloud = `
|
||||||
|
Pre-existing state was found while migrating the previous %q backend to Terraform Cloud.
|
||||||
|
No existing state was found in Terraform Cloud. Do you want to copy this state to Terraform Cloud?
|
||||||
|
Enter "yes" to copy and "no" to start with an empty state.
|
||||||
|
`
|
||||||
|
|
||||||
const inputBackendMigrateNonEmpty = `
|
const inputBackendMigrateNonEmpty = `
|
||||||
Pre-existing state was found while migrating the previous %q backend to the
|
Pre-existing state was found while migrating the previous %q backend to the
|
||||||
newly configured %q backend. An existing non-empty state already exists in
|
newly configured %q backend. An existing non-empty state already exists in
|
||||||
|
@ -821,6 +847,19 @@ Enter "yes" to copy and "no" to start with the existing state in the newly
|
||||||
configured %[2]q backend.
|
configured %[2]q backend.
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const inputBackendMigrateNonEmptyCloud = `
|
||||||
|
Pre-existing state was found while migrating the previous %q backend to
|
||||||
|
Terraform Cloud. An existing non-empty state already exists in Terraform Cloud.
|
||||||
|
The two states have been saved to temporary files that will be removed after
|
||||||
|
responding to this query.
|
||||||
|
|
||||||
|
Previous (type %[1]q): %[2]s
|
||||||
|
New (Terraform Cloud): %[3]s
|
||||||
|
|
||||||
|
Do you want to overwrite the state in Terraform Cloud with the previous state?
|
||||||
|
Enter "yes" to copy and "no" to start with the existing state in Terraform Cloud.
|
||||||
|
`
|
||||||
|
|
||||||
const inputBackendMigrateMultiToSingle = `
|
const inputBackendMigrateMultiToSingle = `
|
||||||
The existing %[1]q backend supports workspaces and you currently are
|
The existing %[1]q backend supports workspaces and you currently are
|
||||||
using more than one. The newly configured %[2]q backend doesn't support
|
using more than one. The newly configured %[2]q backend doesn't support
|
||||||
|
|
Loading…
Reference in New Issue