-
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
Tech debt: Reduce tags
boilerplate code - PoC
#29838
Conversation
…age name in Context.
Community NoteVoting for Prioritization
For Submitters
|
tags
boilerplate codetags
boilerplate code - PoC
This functionality has been released in v4.60.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 pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
Attempts to reduce the amount of boilerplate
tags
-related code in each resource by centralizing that code.This proof of concept implementation modifies a small number of resources implemented using Plugin SDK v2 or Plugin Framework:
aws_sns_topic
aws_vpc
aws_resourceexplorer2_index
Self-registration for all resources has opened up additional possibilities that allow common functionality to be injected transparently on initialization and run during resource CRUD operations.
Details
Function Annotations
Use an annotation on each resource’s (and data source’s) factory function to opt in to transparent tags handling. This annotation mechanism is similar to the one used for resource self-registration - A specially formatted comment is added to eligible functions and the code generation build step (
make gen
) generates a structure exported from each service package containing information processed during provider initialization.The proposed syntax for the annotation is
where identifierAttribute is the name of the attribute in the resource’s schema that is used in ListTags and UpdateTags calls.
Inject Interceptors
Interceptors are a mechanism to flexibly and extensibly change or augment a software system’s usual processing cycle. For the Terraform AWS Provider we will implement an interceptor capability to dynamically change resource CRUD handler processing.
Interceptors consist of a When and a Why:
and functionality that is run on match.
Interceptors register with a dispatcher and this dispatcher is invoked on each CRUD request.
There are interceptor variants for Plugin SDK v2 and Plugin Framework resources, as CRUD handler signatures differ.
Each interceptor has access to the current
Context
, handler request and response (viaschema.ResourceData
for Terraform Plugin SDK) and provider state (meta
for Terraform Plugin SDK).Interceptors return a
Context
(so as to be able to enrich the passed inContext
) andDiagnostics
(so as to accumulate and signal errors and warnings).Transparent Tagging Interceptor
During provider initialization, as the lists of supported resources and data sources are being built, inspect the information generated from the annotations and, if transparent tagging support is enabled, inject an interceptor around each of the resource’s CRUD handlers.
The transparent tagging interceptor will run Before and After resource Create, Read and Update and will
Context
, addingdefault_tags
andignore_tags
values from provider statewhere
identifier
is the value of theTags
annotation’sidentifierAttribute
fieldListTags
method, run standard tags read logic:Boilerplate tagging code can now be removed from the resource’s CRUD handler functions.
Relations
Relates #29747.
Output from Acceptance Testing
Failures are unrelated to this change.
Failures are unrelated to this change.