2021-02-12 02:52:10 +01:00
|
|
|
package views
|
2014-06-27 02:05:21 +02:00
|
|
|
|
|
|
|
import (
|
2014-10-06 08:29:13 +02:00
|
|
|
"bufio"
|
2014-07-13 02:03:55 +02:00
|
|
|
"bytes"
|
2014-06-27 02:05:21 +02:00
|
|
|
"fmt"
|
2014-07-13 02:03:55 +02:00
|
|
|
"strings"
|
2014-06-27 07:01:05 +02:00
|
|
|
"sync"
|
2016-04-13 19:54:11 +02:00
|
|
|
"time"
|
2014-10-12 18:59:08 +02:00
|
|
|
"unicode"
|
2014-06-27 02:05:21 +02:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2018-10-13 19:47:46 +02:00
|
|
|
"github.com/hashicorp/terraform/command/format"
|
2021-05-17 19:40:40 +02:00
|
|
|
"github.com/hashicorp/terraform/internal/providers"
|
2018-08-25 01:13:50 +02:00
|
|
|
"github.com/hashicorp/terraform/plans"
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-06-27 02:05:21 +02:00
|
|
|
)
|
|
|
|
|
2017-03-13 21:09:25 +01:00
|
|
|
const defaultPeriodicUiTimer = 10 * time.Second
|
2017-04-04 16:41:54 +02:00
|
|
|
const maxIdLen = 80
|
2016-04-13 19:54:11 +02:00
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
func NewUiHook(view *View) *UiHook {
|
|
|
|
return &UiHook{
|
|
|
|
view: view,
|
|
|
|
periodicUiTimer: defaultPeriodicUiTimer,
|
|
|
|
resources: make(map[string]uiResourceState),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-27 02:05:21 +02:00
|
|
|
type UiHook struct {
|
|
|
|
terraform.NilHook
|
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
view *View
|
|
|
|
viewLock sync.Mutex
|
|
|
|
|
|
|
|
periodicUiTimer time.Duration
|
2014-06-27 07:01:05 +02:00
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
resources map[string]uiResourceState
|
|
|
|
resourcesLock sync.Mutex
|
2014-06-27 02:05:21 +02:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
var _ terraform.Hook = (*UiHook)(nil)
|
|
|
|
|
2016-04-13 19:54:11 +02:00
|
|
|
// uiResourceState tracks the state of a single resource
|
|
|
|
type uiResourceState struct {
|
2018-10-13 19:47:46 +02:00
|
|
|
DispAddr string
|
|
|
|
IDKey, IDValue string
|
|
|
|
Op uiResourceOp
|
|
|
|
Start time.Time
|
2017-03-02 20:15:02 +01:00
|
|
|
|
|
|
|
DoneCh chan struct{} // To be used for cancellation
|
2017-03-17 16:04:27 +01:00
|
|
|
|
|
|
|
done chan struct{} // used to coordinate tests
|
2016-04-13 19:54:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// uiResourceOp is an enum for operations on a resource
|
2014-07-27 06:20:31 +02:00
|
|
|
type uiResourceOp byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
uiResourceUnknown uiResourceOp = iota
|
|
|
|
uiResourceCreate
|
|
|
|
uiResourceModify
|
|
|
|
uiResourceDestroy
|
2020-05-21 22:02:18 +02:00
|
|
|
uiResourceRead
|
2014-07-27 06:20:31 +02:00
|
|
|
)
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) PreApply(addr addrs.AbsResourceInstance, gen states.Generation, action plans.Action, priorState, plannedNewState cty.Value) (terraform.HookAction, error) {
|
2018-09-05 01:51:22 +02:00
|
|
|
dispAddr := addr.String()
|
|
|
|
if gen != states.CurrentGen {
|
2021-05-13 00:18:25 +02:00
|
|
|
dispAddr = fmt.Sprintf("%s (deposed object %s)", dispAddr, gen)
|
2018-09-05 01:51:22 +02:00
|
|
|
}
|
|
|
|
|
2014-07-27 06:20:31 +02:00
|
|
|
var operation string
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
var op uiResourceOp
|
2018-10-13 19:47:46 +02:00
|
|
|
idKey, idValue := format.ObjectValueIDOrName(priorState)
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
switch action {
|
|
|
|
case plans.Delete:
|
2014-07-27 06:20:31 +02:00
|
|
|
operation = "Destroying..."
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
op = uiResourceDestroy
|
|
|
|
case plans.Create:
|
2014-07-13 02:03:55 +02:00
|
|
|
operation = "Creating..."
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
op = uiResourceCreate
|
2018-09-05 01:51:22 +02:00
|
|
|
case plans.Update:
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
operation = "Modifying..."
|
|
|
|
op = uiResourceModify
|
2020-05-21 22:02:18 +02:00
|
|
|
case plans.Read:
|
|
|
|
operation = "Reading..."
|
|
|
|
op = uiResourceRead
|
2018-09-05 01:51:22 +02:00
|
|
|
default:
|
|
|
|
// We don't expect any other actions in here, so anything else is a
|
|
|
|
// bug in the caller but we'll ignore it in order to be robust.
|
2021-02-12 02:52:10 +01:00
|
|
|
h.println(fmt.Sprintf("(Unknown action %s for %s)", action, dispAddr))
|
2018-09-05 01:51:22 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
2014-07-13 02:03:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-13 19:47:46 +02:00
|
|
|
var stateIdSuffix string
|
|
|
|
if idKey != "" && idValue != "" {
|
|
|
|
stateIdSuffix = fmt.Sprintf(" [%s=%s]", idKey, idValue)
|
|
|
|
} else {
|
|
|
|
// Make sure they are both empty so we can deal with this more
|
|
|
|
// easily in the other hook methods.
|
|
|
|
idKey = ""
|
|
|
|
idValue = ""
|
|
|
|
}
|
2017-03-01 23:16:22 +01:00
|
|
|
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: %s%s[reset]"),
|
2018-09-05 01:51:22 +02:00
|
|
|
dispAddr,
|
2014-07-13 02:03:55 +02:00
|
|
|
operation,
|
2017-03-01 23:16:22 +01:00
|
|
|
stateIdSuffix,
|
2021-02-16 17:33:03 +01:00
|
|
|
))
|
2014-07-13 02:03:55 +02:00
|
|
|
|
2018-10-13 19:47:46 +02:00
|
|
|
key := addr.String()
|
2017-03-02 20:15:02 +01:00
|
|
|
uiState := uiResourceState{
|
2018-10-14 16:59:15 +02:00
|
|
|
DispAddr: key,
|
|
|
|
IDKey: idKey,
|
|
|
|
IDValue: idValue,
|
|
|
|
Op: op,
|
|
|
|
Start: time.Now().Round(time.Second),
|
|
|
|
DoneCh: make(chan struct{}),
|
|
|
|
done: make(chan struct{}),
|
2017-03-02 20:15:02 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
h.resourcesLock.Lock()
|
2018-10-13 19:47:46 +02:00
|
|
|
h.resources[key] = uiState
|
2021-02-12 02:52:10 +01:00
|
|
|
h.resourcesLock.Unlock()
|
2017-03-02 20:15:02 +01:00
|
|
|
|
|
|
|
// Start goroutine that shows progress
|
|
|
|
go h.stillApplying(uiState)
|
2016-04-13 19:54:11 +02:00
|
|
|
|
2014-06-27 07:11:04 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2017-03-02 20:15:02 +01:00
|
|
|
func (h *UiHook) stillApplying(state uiResourceState) {
|
2017-03-17 16:04:27 +01:00
|
|
|
defer close(state.done)
|
2017-03-02 20:15:02 +01:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-state.DoneCh:
|
|
|
|
return
|
2016-04-13 19:54:11 +02:00
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
case <-time.After(h.periodicUiTimer):
|
2017-03-02 20:15:02 +01:00
|
|
|
// Timer up, show status
|
|
|
|
}
|
2016-04-13 19:54:11 +02:00
|
|
|
|
2017-03-02 20:15:02 +01:00
|
|
|
var msg string
|
|
|
|
switch state.Op {
|
|
|
|
case uiResourceModify:
|
|
|
|
msg = "Still modifying..."
|
|
|
|
case uiResourceDestroy:
|
|
|
|
msg = "Still destroying..."
|
|
|
|
case uiResourceCreate:
|
|
|
|
msg = "Still creating..."
|
2020-05-21 22:02:18 +02:00
|
|
|
case uiResourceRead:
|
|
|
|
msg = "Still reading..."
|
2017-03-02 20:15:02 +01:00
|
|
|
case uiResourceUnknown:
|
|
|
|
return
|
|
|
|
}
|
2017-03-01 23:16:22 +01:00
|
|
|
|
2017-03-02 20:15:02 +01:00
|
|
|
idSuffix := ""
|
2018-10-13 19:47:46 +02:00
|
|
|
if state.IDKey != "" {
|
|
|
|
idSuffix = fmt.Sprintf("%s=%s, ", state.IDKey, truncateId(state.IDValue, maxIdLen))
|
2017-03-02 20:15:02 +01:00
|
|
|
}
|
2016-04-13 19:54:11 +02:00
|
|
|
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: %s [%s%s elapsed][reset]"),
|
2018-10-13 19:47:46 +02:00
|
|
|
state.DispAddr,
|
2017-03-02 20:15:02 +01:00
|
|
|
msg,
|
|
|
|
idSuffix,
|
|
|
|
time.Now().Round(time.Second).Sub(state.Start),
|
2021-02-16 17:33:03 +01:00
|
|
|
))
|
2017-03-02 20:15:02 +01:00
|
|
|
}
|
2016-04-13 19:54:11 +02:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) PostApply(addr addrs.AbsResourceInstance, gen states.Generation, newState cty.Value, applyerr error) (terraform.HookAction, error) {
|
|
|
|
id := addr.String()
|
2014-09-25 23:52:06 +02:00
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
h.resourcesLock.Lock()
|
2016-04-13 19:54:11 +02:00
|
|
|
state := h.resources[id]
|
2017-03-02 20:15:02 +01:00
|
|
|
if state.DoneCh != nil {
|
|
|
|
close(state.DoneCh)
|
|
|
|
}
|
|
|
|
|
2014-07-27 06:20:31 +02:00
|
|
|
delete(h.resources, id)
|
2021-02-12 02:52:10 +01:00
|
|
|
h.resourcesLock.Unlock()
|
2014-07-27 06:20:31 +02:00
|
|
|
|
2017-03-01 23:16:22 +01:00
|
|
|
var stateIdSuffix string
|
2018-10-13 19:47:46 +02:00
|
|
|
if k, v := format.ObjectValueID(newState); k != "" && v != "" {
|
|
|
|
stateIdSuffix = fmt.Sprintf(" [%s=%s]", k, v)
|
|
|
|
}
|
2017-03-01 23:16:22 +01:00
|
|
|
|
2014-07-27 06:20:31 +02:00
|
|
|
var msg string
|
2016-04-13 19:54:11 +02:00
|
|
|
switch state.Op {
|
2014-07-27 06:20:31 +02:00
|
|
|
case uiResourceModify:
|
|
|
|
msg = "Modifications complete"
|
|
|
|
case uiResourceDestroy:
|
|
|
|
msg = "Destruction complete"
|
|
|
|
case uiResourceCreate:
|
|
|
|
msg = "Creation complete"
|
2020-05-21 22:02:18 +02:00
|
|
|
case uiResourceRead:
|
|
|
|
msg = "Read complete"
|
2014-07-27 06:20:31 +02:00
|
|
|
case uiResourceUnknown:
|
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if applyerr != nil {
|
2015-07-22 12:49:05 +02:00
|
|
|
// Errors are collected and printed in ApplyCommand, no need to duplicate
|
|
|
|
return terraform.HookActionContinue, nil
|
2014-07-27 06:20:31 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 00:18:25 +02:00
|
|
|
addrStr := addr.String()
|
|
|
|
if depKey, ok := gen.(states.DeposedKey); ok {
|
|
|
|
addrStr = fmt.Sprintf("%s (deposed object %s)", addrStr, depKey)
|
|
|
|
}
|
|
|
|
|
2021-02-16 17:33:03 +01:00
|
|
|
colorized := fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: %s after %s%s"),
|
2021-05-13 00:18:25 +02:00
|
|
|
addrStr, msg, time.Now().Round(time.Second).Sub(state.Start), stateIdSuffix)
|
2017-03-02 19:41:18 +01:00
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
h.println(colorized)
|
2014-07-27 06:20:31 +02:00
|
|
|
|
2014-06-27 02:18:46 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) PreProvisionInstanceStep(addr addrs.AbsResourceInstance, typeName string) (terraform.HookAction, error) {
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: Provisioning with '%s'...[reset]"),
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
addr, typeName,
|
2021-02-16 17:33:03 +01:00
|
|
|
))
|
2014-07-27 18:11:53 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) ProvisionOutput(addr addrs.AbsResourceInstance, typeName string, msg string) {
|
2014-10-05 01:33:47 +02:00
|
|
|
var buf bytes.Buffer
|
2014-10-06 08:29:13 +02:00
|
|
|
|
2021-02-16 17:33:03 +01:00
|
|
|
prefix := fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s (%s):[reset] "),
|
|
|
|
addr, typeName,
|
|
|
|
)
|
2014-10-06 08:29:13 +02:00
|
|
|
s := bufio.NewScanner(strings.NewReader(msg))
|
2014-10-12 02:35:32 +02:00
|
|
|
s.Split(scanLines)
|
2014-10-06 08:29:13 +02:00
|
|
|
for s.Scan() {
|
2014-10-12 18:59:08 +02:00
|
|
|
line := strings.TrimRightFunc(s.Text(), unicode.IsSpace)
|
|
|
|
if line != "" {
|
2014-10-12 02:40:28 +02:00
|
|
|
buf.WriteString(fmt.Sprintf("%s%s\n", prefix, line))
|
|
|
|
}
|
2014-10-06 08:29:13 +02:00
|
|
|
}
|
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
h.println(strings.TrimSpace(buf.String()))
|
2014-10-05 01:33:47 +02:00
|
|
|
}
|
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) PreRefresh(addr addrs.AbsResourceInstance, gen states.Generation, priorState cty.Value) (terraform.HookAction, error) {
|
2016-05-08 08:51:55 +02:00
|
|
|
var stateIdSuffix string
|
2018-10-13 19:47:46 +02:00
|
|
|
if k, v := format.ObjectValueID(priorState); k != "" && v != "" {
|
|
|
|
stateIdSuffix = fmt.Sprintf(" [%s=%s]", k, v)
|
|
|
|
}
|
2016-05-08 08:51:55 +02:00
|
|
|
|
2021-05-13 00:18:25 +02:00
|
|
|
addrStr := addr.String()
|
|
|
|
if depKey, ok := gen.(states.DeposedKey); ok {
|
|
|
|
addrStr = fmt.Sprintf("%s (deposed object %s)", addrStr, depKey)
|
|
|
|
}
|
|
|
|
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: Refreshing state...%s"),
|
2021-05-13 00:18:25 +02:00
|
|
|
addrStr, stateIdSuffix))
|
2014-06-27 02:05:21 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
2014-06-27 07:01:05 +02:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
func (h *UiHook) PreImportState(addr addrs.AbsResourceInstance, importID string) (terraform.HookAction, error) {
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold]%s: Importing from ID %q..."),
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
addr, importID,
|
2021-02-16 17:33:03 +01:00
|
|
|
))
|
2016-05-04 21:05:42 +02:00
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2018-08-25 01:13:50 +02:00
|
|
|
func (h *UiHook) PostImportState(addr addrs.AbsResourceInstance, imported []providers.ImportedResource) (terraform.HookAction, error) {
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][bold][green]%s: Import prepared!"),
|
|
|
|
addr,
|
|
|
|
))
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 23:24:45 +02:00
|
|
|
for _, s := range imported {
|
2021-02-16 17:33:03 +01:00
|
|
|
h.println(fmt.Sprintf(
|
|
|
|
h.view.colorize.Color("[reset][green] Prepared %s for import"),
|
2018-08-25 01:13:50 +02:00
|
|
|
s.TypeName,
|
2021-02-16 17:33:03 +01:00
|
|
|
))
|
2016-05-04 21:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return terraform.HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2021-02-12 02:52:10 +01:00
|
|
|
// Wrap calls to the view so that concurrent calls do not interleave println.
|
|
|
|
func (h *UiHook) println(s string) {
|
|
|
|
h.viewLock.Lock()
|
|
|
|
defer h.viewLock.Unlock()
|
|
|
|
h.view.streams.Println(s)
|
2014-06-27 07:01:05 +02:00
|
|
|
}
|
2014-10-12 02:35:32 +02:00
|
|
|
|
|
|
|
// scanLines is basically copied from the Go standard library except
|
|
|
|
// we've modified it to also fine `\r`.
|
|
|
|
func scanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
|
|
|
if atEOF && len(data) == 0 {
|
|
|
|
return 0, nil, nil
|
|
|
|
}
|
|
|
|
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
|
|
|
// We have a full newline-terminated line.
|
|
|
|
return i + 1, dropCR(data[0:i]), nil
|
|
|
|
}
|
|
|
|
if i := bytes.IndexByte(data, '\r'); i >= 0 {
|
2021-02-16 17:33:03 +01:00
|
|
|
// We have a full carriage-return-terminated line.
|
2014-10-12 02:35:32 +02:00
|
|
|
return i + 1, dropCR(data[0:i]), nil
|
|
|
|
}
|
|
|
|
// If we're at EOF, we have a final, non-terminated line. Return it.
|
|
|
|
if atEOF {
|
|
|
|
return len(data), dropCR(data), nil
|
|
|
|
}
|
|
|
|
// Request more data.
|
|
|
|
return 0, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// dropCR drops a terminal \r from the data.
|
|
|
|
func dropCR(data []byte) []byte {
|
|
|
|
if len(data) > 0 && data[len(data)-1] == '\r' {
|
|
|
|
return data[0 : len(data)-1]
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
}
|
2017-03-01 23:16:22 +01:00
|
|
|
|
|
|
|
func truncateId(id string, maxLen int) string {
|
2018-09-09 17:21:24 +02:00
|
|
|
// Note that the id may contain multibyte characters.
|
|
|
|
// We need to truncate it to maxLen characters, not maxLen bytes.
|
|
|
|
rid := []rune(id)
|
|
|
|
totalLength := len(rid)
|
2017-03-01 23:16:22 +01:00
|
|
|
if totalLength <= maxLen {
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
if maxLen < 5 {
|
|
|
|
// We don't shorten to less than 5 chars
|
|
|
|
// as that would be pointless with ... (3 chars)
|
|
|
|
maxLen = 5
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:21:24 +02:00
|
|
|
dots := []rune("...")
|
2017-03-01 23:16:22 +01:00
|
|
|
partLen := maxLen / 2
|
|
|
|
|
|
|
|
leftIdx := partLen - 1
|
2018-09-09 17:21:24 +02:00
|
|
|
leftPart := rid[0:leftIdx]
|
2017-03-01 23:16:22 +01:00
|
|
|
|
|
|
|
rightIdx := totalLength - partLen - 1
|
|
|
|
|
|
|
|
overlap := maxLen - (partLen*2 + len(dots))
|
|
|
|
if overlap < 0 {
|
|
|
|
rightIdx -= overlap
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:21:24 +02:00
|
|
|
rightPart := rid[rightIdx:]
|
2017-03-01 23:16:22 +01:00
|
|
|
|
2018-09-09 17:21:24 +02:00
|
|
|
return string(leftPart) + string(dots) + string(rightPart)
|
2017-03-01 23:16:22 +01:00
|
|
|
}
|