Attribute RequiresReplace ... Maybe. Depending on API version

One of my resources has an attribute which can only be modified with some API versions: Early API releases treat it as immutable, but that constraint has been relaxed in later API releases.

The resource schema currently has this attribute marked with the RequiresReplace() attribute plan modifier, but I’d like to relax that constraint to match the API behavior.

I think I’d need to use a resource (rather than attribute) plan modifier because only the resource struct has access to the API version, but that’s only true after the provider’s Configure() has been invoked.

edit: I guess the important distinction in the paragraph above really comes down to specifying the plan modification behavior in ModifyPlan() rather than in Schema(). It’s not about the distinction between resource and attribute plan modification. Both functions (ModifyPlan() and Schema()) have the resource struct pointer as the function receiver but between the two, only ModifyPlan() is guaranteed to run after Configure() according @jbardin’s comment below.

Can I rely on the provider’s Configure() being called before the resource’s ModifyPlan()? This feels like it should be safe… After all, how can we have a plan if we’ve not checked in with the API?

Yes, a provider will always be configured before Terraform starts planning changes. It’s assumed that any planning process may require API access by the provider.

1 Like

Excellent.

Thank you @jbardin.