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:
enabled (bool) - Controls whether the ephemeral resource will be used by
OpenTofu. When set to false, the resource is excluded from the configuration
as if it didn't exist. When set to true (the default), the resource operates
normally.
For ephemeral resources in particular, you can use the boolean
terraform.applying value with enabled to specify that a particular
ephemeral resource should be active only during the apply phase, which can
be useful for values used only by managed resource provisioners because
provisioners are active only during the apply phase.
For more information, refer to the enabled meta-argument.
precondition and postcondition blocks, as described in
Custom Conditions.
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.