# Accessing Resource object from within an attribute plan modifier

**URL:** <https://discuss.hashicorp.com/t/accessing-resource-object-from-within-an-attribute-plan-modifier/75389>\
**Category:** Plugin Development\
**Created:** [June 11, 2025, 4:20am UTC](https://discuss.hashicorp.com/t/accessing-resource-object-from-within-an-attribute-plan-modifier/75389 "2025-06-11T04:20:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanecodes](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/zanecodes/32/44017_2.png) [@zanecodes](https://discuss.hashicorp.com/u/zanecodes)\
**Post date:** [June 11, 2025, 4:20am UTC](https://discuss.hashicorp.com/t/accessing-resource-object-from-within-an-attribute-plan-modifier/75389/1 "2025-06-11T04:20:38Z")

</div>

I’m writing a resource in a Terraform provider using the `terraform-plugin-framework` which has several attributes that interact in complex ways. One attribute is required, and if it’s known during planning it can be used to query the API to show the user the planned default value of another attribute that’s optional, as shown:

```hcl
resource "example" "example" {
  required_attribute = "known value"
}

# example.example will be created
+ resource "example" "example" {
    + required_attribute = "known value"
    + optional_attribute = "default"
  }

```

If `required_attribute` is unknown during planning, then `optional_attribute` will also be unknown.

Currently, I’m implementing this by writing a [resource plan modifier](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#resource-plan-modification), because in my real provider `optional_attribute` is a much more complex nested object type whose own attributes have plan modifiers of their own, and since [attribute plan modifiers run before resource plan modifiers](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#plan-modification-process), I end up having to write a lot of logic in the `ModifyPlan()` function to get the desired result.

I would strongly prefer to implement this using an [attribute plan modifier](https://developer.hashicorp.com/terraform/plugin/framework/resources/plan-modification#resource-plan-modification) that’s defined on `optional_attribute`, since it would completely save me from needing to convert/traverse/reconvert the entire data structure in `ModifyPlan()` and I could just use regular schema-defined attribute plan modifiers instead, since an attribute’s plan modifiers are run before any of its nested attributes’ plan modifiers. However, this would require access to the `resource.Resource` instance so that I can use its API client instance that was configured during `Resource.Configure()`, and the `planmodifier.*Request` types [don’t provide any way to access it](https://pkg.go.dev/github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier#ObjectRequest).

On the other hand, in my real provider, there are several other attributes whose planned values may also depend on `required_attribute`, and I would prefer to only make one API call to get all of their default values at once, as I’m currently doing with my resource plan modifier, rather than one API call per attribute, as would be necessary if I found a way to use an attribute plan modifier, unless I had some way to cache the API call result across attribute plan modifiers.

Is there some way to reference the Resource instance from an attribute plan modifier? I’ve tried implementing a plan modifier that takes a Resource instance as an argument (or takes a `func` that closes over it) and later uses it during `PlanModify()`, but the plan modifier is defined in the `Schema()` function, and the resource instance seems to be a nil pointer at that stage in the lifecycle.

Alternatively, if I could force my resource plan modifier to run _before_ all of the attribute plan modifiers (or, equivalently, force specific attribute plan modifiers to run _after_ the resource plan modifier), that would greatly simplify my implementation.

---

<div class="post-metadata">

**Author:** ![stephybun](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/stephybun/32/21281_2.png) [@stephybun](https://discuss.hashicorp.com/u/stephybun)\
**Post date:** [July 17, 2025, 11:55am UTC](https://discuss.hashicorp.com/t/accessing-resource-object-from-within-an-attribute-plan-modifier/75389/2 "2025-07-17T11:55:19Z")

</div>

Hey @zanecodes

Unfortunately there is no mechanism that allows provider developers to determine the order in which plan modifiers are run and it is not possible to reference the resource instance in the attribute plan modifier - the history and reasons for why it wasn’t made available in attribute plan modifiers is unclear, but if you’re willing to open a feature request for this on the [terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) repo this is something we could consider looking into to make this experience better!
