|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package tfprotov5 |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "time" |
| 9 | +) |
| 10 | + |
| 11 | +// EphemeralResourceMetadata describes metadata for an ephemeral resource in the GetMetadata |
| 12 | +// RPC. |
| 13 | +type EphemeralResourceMetadata struct { |
| 14 | + // TypeName is the name of the ephemeral resource. |
| 15 | + TypeName string |
| 16 | +} |
| 17 | + |
| 18 | +// EphemeralResourceServer is an interface containing the methods an ephemeral resource |
| 19 | +// implementation needs to fill. |
| 20 | +type EphemeralResourceServer interface { |
| 21 | + // ValidateEphemeralResourceConfig is called when Terraform is checking that an |
| 22 | + // ephemeral resource configuration is valid. It is guaranteed to have types |
| 23 | + // conforming to your schema, but it is not guaranteed that all values |
| 24 | + // will be known. This is your opportunity to do custom or advanced |
| 25 | + // validation prior to an ephemeral resource being opened. |
| 26 | + ValidateEphemeralResourceConfig(context.Context, *ValidateEphemeralResourceConfigRequest) (*ValidateEphemeralResourceConfigResponse, error) |
| 27 | + |
| 28 | + // OpenEphemeralResource is called when Terraform wants to open the ephemeral resource, |
| 29 | + // usually during planning. If the config for the ephemeral resource contains unknown |
| 30 | + // values, Terraform will defer the OpenEphemeralResource call until apply. |
| 31 | + OpenEphemeralResource(context.Context, *OpenEphemeralResourceRequest) (*OpenEphemeralResourceResponse, error) |
| 32 | + |
| 33 | + // RenewEphemeralResource is called when Terraform detects that the previously specified |
| 34 | + // RenewAt timestamp has passed. The RenewAt timestamp is supplied either from the |
| 35 | + // OpenEphemeralResource call or a previous RenewEphemeralResource call. |
| 36 | + RenewEphemeralResource(context.Context, *RenewEphemeralResourceRequest) (*RenewEphemeralResourceResponse, error) |
| 37 | + |
| 38 | + // CloseEphemeralResource is called when Terraform is closing the ephemeral resource. |
| 39 | + CloseEphemeralResource(context.Context, *CloseEphemeralResourceRequest) (*CloseEphemeralResourceResponse, error) |
| 40 | +} |
| 41 | + |
| 42 | +// ValidateEphemeralResourceConfigRequest is the request Terraform sends when it |
| 43 | +// wants to validate an ephemeral resource's configuration. |
| 44 | +type ValidateEphemeralResourceConfigRequest struct { |
| 45 | + // TypeName is the type of resource Terraform is validating. |
| 46 | + TypeName string |
| 47 | + |
| 48 | + // Config is the configuration the user supplied for that ephemeral resource. See |
| 49 | + // the documentation on `DynamicValue` for more information about |
| 50 | + // safely accessing the configuration. |
| 51 | + // |
| 52 | + // The configuration is represented as a tftypes.Object, with each |
| 53 | + // attribute and nested block getting its own key and value. |
| 54 | + // |
| 55 | + // This configuration may contain unknown values if a user uses |
| 56 | + // interpolation or other functionality that would prevent Terraform |
| 57 | + // from knowing the value at request time. Any attributes not directly |
| 58 | + // set in the configuration will be null. |
| 59 | + Config *DynamicValue |
| 60 | +} |
| 61 | + |
| 62 | +// ValidateEphemeralResourceConfigResponse is the response from the provider about |
| 63 | +// the validity of an ephemeral resource's configuration. |
| 64 | +type ValidateEphemeralResourceConfigResponse struct { |
| 65 | + // Diagnostics report errors or warnings related to the given |
| 66 | + // configuration. Returning an empty slice indicates a successful |
| 67 | + // validation with no warnings or errors generated. |
| 68 | + Diagnostics []*Diagnostic |
| 69 | +} |
| 70 | + |
| 71 | +// OpenEphemeralResourceRequest is the request Terraform sends when it |
| 72 | +// wants to open an ephemeral resource. |
| 73 | +type OpenEphemeralResourceRequest struct { |
| 74 | + // TypeName is the type of resource Terraform is opening. |
| 75 | + TypeName string |
| 76 | + |
| 77 | + // Config is the configuration the user supplied for that ephemeral resource. See |
| 78 | + // the documentation on `DynamicValue` for more information about |
| 79 | + // safely accessing the configuration. |
| 80 | + // |
| 81 | + // The configuration is represented as a tftypes.Object, with each |
| 82 | + // attribute and nested block getting its own key and value. |
| 83 | + // |
| 84 | + // This configuration will always be fully known. If Config contains unknown values, |
| 85 | + // Terraform will defer the OpenEphemeralResource RPC until apply. |
| 86 | + Config *DynamicValue |
| 87 | + |
| 88 | + // ClientCapabilities defines optionally supported protocol features for the |
| 89 | + // OpenEphemeralResource RPC, such as forward-compatible Terraform behavior changes. |
| 90 | + ClientCapabilities *OpenEphemeralResourceClientCapabilities |
| 91 | +} |
| 92 | + |
| 93 | +// OpenEphemeralResourceResponse is the response from the provider about the current |
| 94 | +// state of the opened ephemeral resource. |
| 95 | +type OpenEphemeralResourceResponse struct { |
| 96 | + // Result is the provider's understanding of what the ephemeral resource's |
| 97 | + // data is after it has been opened, represented as a `DynamicValue`. |
| 98 | + // See the documentation for `DynamicValue` for information about |
| 99 | + // safely creating the `DynamicValue`. |
| 100 | + // |
| 101 | + // Any attribute, whether computed or not, that has a known value in |
| 102 | + // the Config in the OpenEphemeralResourceRequest must be preserved |
| 103 | + // exactly as it was in Result. |
| 104 | + // |
| 105 | + // Any attribute in the Config in the OpenEphemeralResourceRequest |
| 106 | + // that is unknown must take on a known value at this time. No unknown |
| 107 | + // values are allowed in the Result. |
| 108 | + // |
| 109 | + // The result should be represented as a tftypes.Object, with each |
| 110 | + // attribute and nested block getting its own key and value. |
| 111 | + Result *DynamicValue |
| 112 | + |
| 113 | + // Diagnostics report errors or warnings related to opening the |
| 114 | + // requested ephemeral resource. Returning an empty slice |
| 115 | + // indicates a successful creation with no warnings or errors |
| 116 | + // generated. |
| 117 | + Diagnostics []*Diagnostic |
| 118 | + |
| 119 | + // Private should be set to any private data that the provider would like to be |
| 120 | + // sent to the next Renew or Close call. |
| 121 | + Private []byte |
| 122 | + |
| 123 | + // RenewAt indicates to Terraform that the ephemeral resource |
| 124 | + // needs to be renewed at the specified time. Terraform will |
| 125 | + // call the RenewEphemeralResource RPC when the specified time has passed. |
| 126 | + RenewAt time.Time |
| 127 | + |
| 128 | + // Deferred is used to indicate to Terraform that the OpenEphemeralResource operation |
| 129 | + // needs to be deferred for a reason. |
| 130 | + Deferred *Deferred |
| 131 | +} |
| 132 | + |
| 133 | +// RenewEphemeralResourceRequest is the request Terraform sends when it |
| 134 | +// wants to renew an ephemeral resource. |
| 135 | +type RenewEphemeralResourceRequest struct { |
| 136 | + // TypeName is the type of resource Terraform is renewing. |
| 137 | + TypeName string |
| 138 | + |
| 139 | + // Private is any provider-defined private data stored with the |
| 140 | + // ephemeral resource from the most recent Open or Renew call. |
| 141 | + // |
| 142 | + // To ensure private data is preserved, copy any necessary data to |
| 143 | + // the RenewEphemeralResourceResponse type Private field. |
| 144 | + Private []byte |
| 145 | +} |
| 146 | + |
| 147 | +// RenewEphemeralResourceResponse is the response from the provider after an ephemeral resource |
| 148 | +// has been renewed. |
| 149 | +type RenewEphemeralResourceResponse struct { |
| 150 | + // Diagnostics report errors or warnings related to renewing the |
| 151 | + // requested ephemeral resource. Returning an empty slice |
| 152 | + // indicates a successful creation with no warnings or errors |
| 153 | + // generated. |
| 154 | + Diagnostics []*Diagnostic |
| 155 | + |
| 156 | + // Private should be set to any private data that the provider would like to be |
| 157 | + // sent to the next Renew or Close call. |
| 158 | + Private []byte |
| 159 | + |
| 160 | + // RenewAt indicates to Terraform that the ephemeral resource |
| 161 | + // needs to be renewed at the specified time. Terraform will |
| 162 | + // call the RenewEphemeralResource RPC when the specified time has passed. |
| 163 | + RenewAt time.Time |
| 164 | +} |
| 165 | + |
| 166 | +// CloseEphemeralResourceRequest is the request Terraform sends when it |
| 167 | +// wants to close an ephemeral resource. |
| 168 | +type CloseEphemeralResourceRequest struct { |
| 169 | + // TypeName is the type of resource Terraform is closing. |
| 170 | + TypeName string |
| 171 | + |
| 172 | + // Private is any provider-defined private data stored with the |
| 173 | + // ephemeral resource from the most recent Open or Renew call. |
| 174 | + Private []byte |
| 175 | +} |
| 176 | + |
| 177 | +// CloseEphemeralResourceResponse is the response from the provider about |
| 178 | +// the closed ephemeral resource. |
| 179 | +type CloseEphemeralResourceResponse struct { |
| 180 | + // Diagnostics report errors or warnings related to closing the |
| 181 | + // requested ephemeral resource. Returning an empty slice |
| 182 | + // indicates a successful creation with no warnings or errors |
| 183 | + // generated. |
| 184 | + Diagnostics []*Diagnostic |
| 185 | +} |
0 commit comments