Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: Add support for write-only attributes #1375

Merged
merged 63 commits into from
Feb 3, 2025
Merged

Conversation

SBGoods
Copy link
Contributor

@SBGoods SBGoods commented Sep 10, 2024

Adds support for new write-only attribute feature in Terraform v1.11 or higher. Write-only attributes are managed resource attributes whose values are not saved to the Terraform plan or state artifacts and can accept ephemeral values.

A provider can declare an attribute as write-only in the schema using the WriteOnly field. Write-only attributes values are only available in the configuration, and the prior state, planned state, and final state values for write-only attributes should always be null.

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

All of this is looking awesome, great work! I left some initial comments, but in addition to that:

  • I'm wondering what will eventually show up in the plan renderer for Terraform... since we are planning non-null values that will eventually be set to null. Feels like it should either explicitly mention that the value is write-only, or we should be planning null for write-only attributes as well. We should make a note to come back to this once core gets further along.
  • It'd be cool to get some corner testing for SDKv2 to catch any regressions we might introduce in the future
  • I'd love to run this development branch against a major cloud TF provider (aws/gcp/azure) if we can get a hand from their teams finding the appropriate CI jobs to do so. They have so many SDKv2 schemas + tests that it would be a good smoke test.
    • We would need them to update their plugin-go/mux/etc, so you might need to adjust the plugin-go branch to make that all compile.

@SBGoods SBGoods requested review from a team as code owners January 22, 2025 17:40
@SBGoods SBGoods requested a review from pbortnick January 22, 2025 17:40
@SBGoods SBGoods changed the title [DRAFT] Add support for write only attributes all: Add support for write only attributes Jan 22, 2025
@SBGoods SBGoods changed the title all: Add support for write only attributes all: Add support for write-only attributes Jan 22, 2025
@SBGoods SBGoods requested a review from jbardin January 22, 2025 17:42
//
// GetRawConfigAt is considered advanced functionality, and
// familiarity with the Terraform protocol is suggested when using it.
func (d *ResourceData) GetRawConfigAt(valPath cty.Path) (cty.Value, diag.Diagnostics) {
Copy link
Member

Choose a reason for hiding this comment

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

I would check that this works for nested blocks; specifically traversing across cty.SetVal values is weird and I think cty.Walk is going to fail there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout! I've added more test cases in commit d1d4c14. The Set and Set nested block traversal test cases are passing 👍🏾

var oldAttrs []attribute

err := cty.Walk(req.RawConfig, func(path cty.Path, value cty.Value) (bool, error) {
if PathMatches(path, oldAttribute) {
Copy link
Member

Choose a reason for hiding this comment

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

should all cty.Walk' calls use PathMatches`? Or are they expected to only have paths from what should be matching objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm using PathMatches as a quick and dirty equivalent to the framework's path expressions to indicate locations in the schema (as opposed to schema-based data like config).

The cty.Walk in GetRawConfigAt() could also use PathMatches although it's not entirely clear what exactly the resulting cty.Value should be when specifying "any" nested block in the path, so I'm leaning on waiting for a feature request asking for such functionality. The only downside is that cty.Path now works differently in the SDKv2 depending on the function it's being used for which could be confusing.

austinvalle
austinvalle previously approved these changes Jan 22, 2025
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Looks good! I left some comments, mostly just considerations for documentation. (will re-approve if there are more changes pushed to the PR)

Copy link
Contributor

@rkoron007 rkoron007 left a comment

Choose a reason for hiding this comment

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

I see there are a bunch of suggestions here, so I kept my review light. Happy to go through this again after you get a chance to review Austin's comments! ✨

Copy link

@pbortnick pbortnick left a comment

Choose a reason for hiding this comment

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

All good from Web Presence POV

Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Great work! 🚀

@SBGoods SBGoods merged commit 19e5b30 into main Feb 3, 2025
8 checks passed
@SBGoods SBGoods deleted the SBGoods/write-only-attributes branch February 3, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants