mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
b802237e03
Previously we were repeating some logic in the UI layer in order to recover relevant additional context about a change to report to a user. In order to help keep things consistent, and to have a clearer path for adding more such things in the future, here we capture this user-facing idea of an "action reason" within the plan model, and then use that directly in order to decide how to describe the change to the user. For the moment the "tainted" situation is the only one that gets a special message, matching what we had before, but we can expand on this in future in order to give better feedback about the other replace situations too. This also preemptively includes the "replacing by request" reason, which is currently not reachable but will be used in the near future as part of implementing the -replace=... plan command line option to allow forcing a particular object to be replaced. So far we don't have any special reasons for anything other than replacing, which makes sense because replacing is the only one that is in a sense a special case of another action (Update), but this could expand to other kinds of reasons in the future, such as explaining which of the few different reasons a data source read might be deferred until the apply step.
75 lines
2.9 KiB
Go
75 lines
2.9 KiB
Go
package jsonplan
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
// Resource is the representation of a resource in the json plan
|
|
type resource struct {
|
|
// Address is the absolute resource address
|
|
Address string `json:"address,omitempty"`
|
|
|
|
// Mode can be "managed" or "data"
|
|
Mode string `json:"mode,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
|
|
// Index is omitted for a resource not using `count` or `for_each`
|
|
Index addrs.InstanceKey `json:"index,omitempty"`
|
|
|
|
// ProviderName allows the property "type" to be interpreted unambiguously
|
|
// in the unusual situation where a provider offers a resource type whose
|
|
// name does not start with its own name, such as the "googlebeta" provider
|
|
// offering "google_compute_instance".
|
|
ProviderName string `json:"provider_name,omitempty"`
|
|
|
|
// SchemaVersion indicates which version of the resource type schema the
|
|
// "values" property conforms to.
|
|
SchemaVersion uint64 `json:"schema_version"`
|
|
|
|
// AttributeValues is the JSON representation of the attribute values of the
|
|
// resource, whose structure depends on the resource type schema. Any
|
|
// unknown values are omitted or set to null, making them indistinguishable
|
|
// from absent values.
|
|
AttributeValues attributeValues `json:"values,omitempty"`
|
|
}
|
|
|
|
// resourceChange is a description of an individual change action that Terraform
|
|
// plans to use to move from the prior state to a new state matching the
|
|
// configuration.
|
|
type resourceChange struct {
|
|
// Address is the absolute resource address
|
|
Address string `json:"address,omitempty"`
|
|
|
|
// ModuleAddress is the module portion of the above address. Omitted if the
|
|
// instance is in the root module.
|
|
ModuleAddress string `json:"module_address,omitempty"`
|
|
|
|
// "managed" or "data"
|
|
Mode string `json:"mode,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
Index addrs.InstanceKey `json:"index,omitempty"`
|
|
ProviderName string `json:"provider_name,omitempty"`
|
|
|
|
// "deposed", if set, indicates that this action applies to a "deposed"
|
|
// object of the given instance rather than to its "current" object. Omitted
|
|
// for changes to the current object.
|
|
Deposed string `json:"deposed,omitempty"`
|
|
|
|
// Change describes the change that will be made to this object
|
|
Change change `json:"change,omitempty"`
|
|
|
|
// ActionReason is a keyword representing some optional extra context
|
|
// for why the actions in Change.Actions were chosen.
|
|
//
|
|
// This extra detail is only for display purposes, to help a UI layer
|
|
// present some additional explanation to a human user. The possible
|
|
// values here might grow and change over time, so any consumer of this
|
|
// information should be resilient to encountering unrecognized values
|
|
// and treat them as an unspecified reason.
|
|
ActionReason string `json:"action_reason,omitempty"`
|
|
}
|