website/docs/language/ephemerality/ephemeral-resources.mdx
:::info Ephemeral resources can be used only with OpenTofu from v1.11 onwards. :::
The ephemeral block defines a temporary value that OpenTofu will not store in state or plan.
This block works only with providers that already offer such capability and is not meant to be used
as a drop-in replacement for other blocks (data or resource). To understand if providers offer
such capability, the provider documentation or schema should be consulted.
The lifecycle of an ephemeral resource is different than the lifecycle of other resource types. When OpenTofu encounters such a block, it will execute the following sequence:
Any attribute of the response returned by opening the ephemeral resource, is marked as ephemeral and can only be used in specific contexts:
connection blockswrite-only attributesAny usage of an ephemeral value in contexts where is not allowed will generate an error.
Besides the attributes in the schema of an ephemeral resource, the block supports also the following meta-arguments:
A lifecycle block inside an ephemeral block allows some customization of
OpenTofu's behavior relating to instances of a resource at different phases
of its lifecycle.
ephemeral "example" "example" {
# ...normal resource arguments...
lifecycle {
# ...lifecycle arguments...
}
}
The following arguments and nested block types are supported in the lifecycle
block for an ephemeral resource:
precondition and postcondition blocks, as described in
Custom Conditions.Following the same rule of not allowing ephemeral values in repetition meta arguments (count, for_each),
lifecycle.enabled disallows usage of such values too, including the usage of tofu.applying.
For more information, refer to the enabled meta-argument.
By design, the ephemeral resources cannot be opened if the configuration is not fully known. When that happens during planning, the ephemeral resource will be postponed (deferred) for the apply phase. On the apply phase, based on the dependency graph, the ephemeral resource will be opened only after all of its dependencies will be satisfied.
For an in-depth example on how to use ephemeral resources, please refer to this example.