Add resource_name variable to template context#9
Merged
jeffreyaven merged 1 commit intomainfrom Feb 23, 2026
Merged
Conversation
Introduces {{ resource_name }} as a JIT-evaluated template variable
(alongside stack_name and stack_env) that resolves to the current
resource's name during processing. This enables tagging resources
with their own name in both resource-level props and globals like
global_tags.
Global values containing {{ resource_name }} are preserved as literal
template expressions during initial rendering (since no resource is
known yet), then re-rendered per-resource in get_full_context() when
the resource name becomes available.
https://claude.ai/code/session_01JVr4F97rZNWMEsADMpAotd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change enables templates to reference the current resource's name via a
resource_namevariable, similar to existingstack_nameandstack_envvariables. This allows global context values (like tags) to be customized per-resource using template expressions.Key Changes
resource_nameinjection: Theget_full_context()function now injectsresource_nameinto the context before rendering resource propertiesre_render_context_with_deferred_vars()function re-renders global context values that contain template expressions (e.g.,{{ resource_name }}), allowing globals defined at startup to reference resource-specific variablesresource_nameavailability in full contextresource_nameusage in resource properties{{ resource_name }}resource_nameImplementation Details
resource_namevariable is injected into a cloned copy of the global context before property rendering{{in values and are re-rendered using the template engineTrue/False→ JSON'strue/false) during re-renderinghttps://claude.ai/code/session_01JVr4F97rZNWMEsADMpAotd