Skip to content

Plan modification design doc#64

Merged
kmoe merged 10 commits intomainfrom
kmoe-plan-modification
Jul 16, 2021
Merged

Plan modification design doc#64
kmoe merged 10 commits intomainfrom
kmoe-plan-modification

Conversation

@kmoe
Copy link
Member

@kmoe kmoe commented Jul 7, 2021

The first step towards #34.

@kmoe kmoe requested a review from a team July 7, 2021 16:11

### `CustomizeDiff`

Rather than exposing Terraform plans to provider developers, `helper/schema` has as a first-class concept the _resource diff_. Providers can optionally define a `CustomizeDiff` method on the `Resource` struct, which resembles a CRUD method, except that instead of `ResourceData` the function is supplied a `*ResourceDiff`, and is called during several points in the resource lifecycle, and must therefore be "resilient to support all scenarios".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Rather than exposing Terraform plans to provider developers, `helper/schema` has as a first-class concept the _resource diff_. Providers can optionally define a `CustomizeDiff` method on the `Resource` struct, which resembles a CRUD method, except that instead of `ResourceData` the function is supplied a `*ResourceDiff`, and is called during several points in the resource lifecycle, and must therefore be "resilient to support all scenarios".
Rather than exposing Terraform plans to provider developers, `helper/schema` has as a first-class concept the _resource diff_. Providers can optionally define a `CustomizeDiff` method on the `Resource` struct, which resembles a CRUD method, except that instead of `ResourceData` the function is supplied a `ResourceDiff`, and is called during several points in the resource lifecycle, and must therefore be "resilient to support all scenarios".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature is type CustomizeDiffFunc func(context.Context, *ResourceDiff, interface{}) error - any particular reason to omit the pointer here?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking really good -- I'm curious about a few points here, which happy to discuss offline:

  • Are documentation hooks desired for this functionality now or in the future?
  • Are there concerns with proliferating fields on attributes?
  • Is it important to allow attribute-level plan modifications access to the provider?

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some thoughts inline. I didn't see a convenient place to put it in, but I'm also interested in how this may impact the docs generator / language server and how we may be able to surface these behaviors to those tools, and how these possible paths forward interact with our capabilities there.

@kmoe
Copy link
Member Author

kmoe commented Jul 12, 2021

Thanks, all. Yes, PlanModifier (whatever we call it) is the missing piece here! Revising and dealing with all comments.

@kmoe kmoe force-pushed the kmoe-plan-modification branch from eda2b7a to 2d10330 Compare July 14, 2021 16:00
@kmoe kmoe requested a review from a team July 14, 2021 17:48
@kmoe
Copy link
Member Author

kmoe commented Jul 14, 2021

Hmm, actually I really like the typed validators in #65 but I didn't dare propose a StringAttributePlanModifier. Since it looks like our proposed solutions for plan customisation and validation are converging, I think it's worth considering offering the same kind of strong typing for both eventually.

Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in agreement with your conclusions. I am still unhappy about the type assertions going on with attr.Values. I think it limits our composability of these blocks significantly.

What if we offer an attr.ValueAs helper that does the same reflection Get does (and maybe attr.ValueIsKnown / attr.ValueIsNull helpers that use the ToTerraformValue to compare to nil and tftypes.UnknownValue) that will allow us to use attr.Values without limiting the types of the values? Then we offer the same way to get as values that CRUD uses, for example.

@kmoe kmoe requested review from bflad and paddycarver July 15, 2021 12:16
Copy link
Contributor

@paddycarver paddycarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple minor comments, but it seems solid and reasonable to me, and the comments are things it's reasonable enough to change later, I think, so this has my 👍 🚀

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall very well done!

One thing I'm curious about is how the provider instance will be available to this functionality if necessary, but it is fine to leave that as an implementation detail if the design does not inhibit that possibility.

@kmoe kmoe added the design-doc Issues or pull requests about a design document, capturing design ideas and trade-offs. label Jul 15, 2021
@kmoe kmoe merged commit 1be8c67 into main Jul 16, 2021
@kmoe kmoe deleted the kmoe-plan-modification branch July 16, 2021 16:03
@kmoe kmoe mentioned this pull request Aug 16, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

design-doc Issues or pull requests about a design document, capturing design ideas and trade-offs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants