Skip to content

Conversation

@naxty
Copy link
Contributor

@naxty naxty commented Nov 27, 2025

Problem

When extracting resources with resolvable references, the PKL generator encountered two issues:

  1. Type mismatch error: Resources with resolvable properties (e.g., AWS::IAM::RolePolicy with RoleName) failed during extraction with error:

    Expected "String" but got "Dynamic"
    

    This occurred because resolvable values were being passed as Dynamic but in rolepolicy.pkl it was implemented as roleName: String which doesn't allow Resovable.

  2. Unmanaged stack rendering: Resolvables referencing unmanaged resources were rendered as full resolvable objects, which would fail during PKL evaluation since the referenced stack doesn't exist yet and it wouldn't change the stack of the Resolvable.

Solution

1. Add formae.Resolvable to RoleName of rolepolicy: This allows the generation of a Resolvable for this property.

2. Improved unmanaged stack rendering

  • Added conditional rendering for resolvables based on stack value:
    • Unmanaged stacks ($unmanaged): Renders as a string value with an inline comment
          roleName = "developer" // The target resource with the label = "developer" of type = "AWS::IAM::Role" is not managed yet. Bring it under management first to convert this into a Resolvable.
    • Managed stacks: Renders as a proper resolvable object
      roleName = new role.RoleResolvable {
        // RealValue: developer
        stack = someStack.res.label
        label = "developer"
      }.roleName

Testing

Before:

formae extract --query="type:AWS::IAM::RolePolicy" ./iam_rolepolicy.pkl
# Error: Expected "String" but got "Dynamic"

After:

formae extract --query="type:AWS::IAM::RolePolicy" ./iam_rolepolicy.pkl
# Successfully generates PKL with proper resolvable handling

@naxty naxty added the bug Something isn't working label Nov 27, 2025
@naxty naxty enabled auto-merge (squash) November 27, 2025 12:10
@naxty naxty requested a review from JeroenSoeters November 28, 2025 08:54
@naxty naxty merged commit a3c866a into main Nov 29, 2025
5 checks passed
@naxty naxty deleted the fix/pkl-gen-unmanaged-resolvable branch November 29, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants