github.com/opentofu/opentofu@v1.7.1/internal/command/jsonplan/resource.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package jsonplan
     7  
     8  import (
     9  	"encoding/json"
    10  
    11  	"github.com/opentofu/opentofu/internal/addrs"
    12  )
    13  
    14  // Resource is the representation of a resource in the json plan
    15  type Resource struct {
    16  	// Address is the absolute resource address
    17  	Address string `json:"address,omitempty"`
    18  
    19  	// Mode can be "managed" or "data"
    20  	Mode string `json:"mode,omitempty"`
    21  
    22  	Type string `json:"type,omitempty"`
    23  	Name string `json:"name,omitempty"`
    24  
    25  	// Index is omitted for a resource not using `count` or `for_each`
    26  	Index addrs.InstanceKey `json:"index,omitempty"`
    27  
    28  	// ProviderName allows the property "type" to be interpreted unambiguously
    29  	// in the unusual situation where a provider offers a resource type whose
    30  	// name does not start with its own name, such as the "googlebeta" provider
    31  	// offering "google_compute_instance".
    32  	ProviderName string `json:"provider_name,omitempty"`
    33  
    34  	// SchemaVersion indicates which version of the resource type schema the
    35  	// "values" property conforms to.
    36  	SchemaVersion uint64 `json:"schema_version"`
    37  
    38  	// AttributeValues is the JSON representation of the attribute values of the
    39  	// resource, whose structure depends on the resource type schema. Any
    40  	// unknown values are omitted or set to null, making them indistinguishable
    41  	// from absent values.
    42  	AttributeValues AttributeValues `json:"values,omitempty"`
    43  
    44  	// SensitiveValues is similar to AttributeValues, but with all sensitive
    45  	// values replaced with true, and all non-sensitive leaf values omitted.
    46  	SensitiveValues json.RawMessage `json:"sensitive_values,omitempty"`
    47  }
    48  
    49  // ResourceChange is a description of an individual change action that OpenTofu
    50  // plans to use to move from the prior state to a new state matching the
    51  // configuration.
    52  type ResourceChange struct {
    53  	// Address is the absolute resource address
    54  	Address string `json:"address,omitempty"`
    55  
    56  	// PreviousAddress is the absolute address that this resource instance had
    57  	// at the conclusion of a previous run.
    58  	//
    59  	// This will typically be omitted, but will be present if the previous
    60  	// resource instance was subject to a "moved" block that we handled in the
    61  	// process of creating this plan.
    62  	//
    63  	// Note that this behavior diverges from the internal plan data structure,
    64  	// where the previous address is set equal to the current address in the
    65  	// common case, rather than being omitted.
    66  	PreviousAddress string `json:"previous_address,omitempty"`
    67  
    68  	// ModuleAddress is the module portion of the above address. Omitted if the
    69  	// instance is in the root module.
    70  	ModuleAddress string `json:"module_address,omitempty"`
    71  
    72  	// "managed" or "data"
    73  	Mode string `json:"mode,omitempty"`
    74  
    75  	Type         string          `json:"type,omitempty"`
    76  	Name         string          `json:"name,omitempty"`
    77  	Index        json.RawMessage `json:"index,omitempty"`
    78  	ProviderName string          `json:"provider_name,omitempty"`
    79  
    80  	// "deposed", if set, indicates that this action applies to a "deposed"
    81  	// object of the given instance rather than to its "current" object. Omitted
    82  	// for changes to the current object.
    83  	Deposed string `json:"deposed,omitempty"`
    84  
    85  	// Change describes the change that will be made to this object
    86  	Change Change `json:"change,omitempty"`
    87  
    88  	// ActionReason is a keyword representing some optional extra context
    89  	// for why the actions in Change.Actions were chosen.
    90  	//
    91  	// This extra detail is only for display purposes, to help a UI layer
    92  	// present some additional explanation to a human user. The possible
    93  	// values here might grow and change over time, so any consumer of this
    94  	// information should be resilient to encountering unrecognized values
    95  	// and treat them as an unspecified reason.
    96  	ActionReason string `json:"action_reason,omitempty"`
    97  }