-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Optional/Computed Sets with Terraform Plugin Framework #28638
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
This functionality has been released in v4.49.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
This issue documents research of optional/computed set attribute configurations with
terraform-plugin-framework
and protocol version 5 (Terraform AWS Provider). This includes various schema designs and alternatives for storing partial results to state.Background
The AWS AuditManager Assessment resource includes a “Roles” attribute that is a set of objects containing AWS IAM role information. At least one element is required on Create and Update. The resulting response may contain additional elements, as an IAM role may have access to all assessments by default. This effectively makes the attribute both required and computed, but since this combination is not permitted an optional/computed set attribute was attempted.
Recommendation
Based on the research below, I’d propose moving forward with Multiple Set Attributes. This pattern still has the caveat of the Other Alternatives (no drift detection for roles not tracked in configuration), but with the benefit of those roles being visible in state via the
roles_all
attribute.See this issue comment recommending a similar approach for a computed/optional map attribute.
Attempted Schema Designs
Because the AWS provider is limited to protocol version 5, nested attributes are not yet an option. Schema designs with Blocks and Set attributes are documented in detail below. Account numbers and role names have been redacted from error messages, but “redacted-admin” represents an IAM role that by default has permissions to all assessments, but isn’t included in the terraform configuration.
Block with Nested Optional/Computed Attributes
Schema:
Result on Apply:
Set Attribute with Optional and Computed
Schema:
Result on Apply:
Set Attribute with Optional and Computed, Plus Plan Modifiers
Schema:
Plan Modifier:
Result on Apply:
Multiple SetNestedBlocks
With this approach, separate nested blocks were used to distinguish between user provided values (roles), and the complete list of roles with access to the assessment (roles_all).
Result on Apply:
Multiple Set Attributes
With this approach, separate attributes were used to distinguish between user provided values (roles), and the complete list of roles with access to the assessment (roles_all).
Schema:
Result on Apply: Success
Other Alternatives
Filter API Results on Create/Update
This would involve parsing the returned Roles object and only writing values that also exist in the configuration to state. This provides no drift detection for roles not tracked in the configuration. See this related issue comment.
Set Configuration only on Create/Update
This would involve ignoring the returned Roles object and writing the roles configuration directly to state. This provides no drift detection for roles not tracked in the configuration. See this related issue comment.
Reference
Related Issues
Tested Terraform Configuration
While testing a development configuration was used as the AuditManager assessment resource is not yet published.
main.tf
:dev.tfrc
:Workflow to reproduce:
Existing Resource Examples (SDKv2)
Kendra Index
terraform-provider-aws/internal/service/kendra/index.go
Lines 87 to 92 in b848146
References
Relates #17981
Relates #28356
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: