Skip to content

Commit a3c866a

Browse files
authored
fix(pklGeneration): Handle resolvables correctly for AWS::IAM:RolePolicy RoleName and improve unmanaged stack rendering (#97)
* Fix resolvable generation for rolepolicy rolename * Extend pkl to generate real value for unmanaged res
1 parent c74dfc6 commit a3c866a

File tree

3 files changed

+77
-7
lines changed

3 files changed

+77
-7
lines changed

plugins/aws/schema/pkl/iam/rolepolicy.pkl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ open class RolePolicy extends formae.Resource {
3030
policyName: String
3131

3232
@aws.FieldHint{createOnly = true}
33-
roleName: String
33+
roleName: String|formae.Resolvable
3434

3535
}

plugins/pkl/generator/examples/json/types/iam_rolepolicy.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,70 @@
27982798
},
27992799
"NativeId": "TestInlinePolicy-9|pkl-evaluator-execution-role",
28002800
"Ksuid": "33jy2eVgVFkvWj46Q7hCruatDwf"
2801+
},
2802+
{
2803+
"Label": "SysOpsAdmin|developer",
2804+
"Type": "AWS::IAM::RolePolicy",
2805+
"Stack": "$unmanaged",
2806+
"Target": "us-west-2",
2807+
"Schema": {
2808+
"Identifier": "PolicyName",
2809+
"Tags": "",
2810+
"Fields": [
2811+
"PolicyDocument",
2812+
"PolicyName",
2813+
"RoleName"
2814+
],
2815+
"Nonprovisionable": false,
2816+
"Hints": {
2817+
"PolicyDocument": {
2818+
"CreateOnly": false,
2819+
"Persist": false,
2820+
"WriteOnly": false,
2821+
"Required": false,
2822+
"RequiredOnCreate": false
2823+
},
2824+
"PolicyName": {
2825+
"CreateOnly": true,
2826+
"Persist": false,
2827+
"WriteOnly": false,
2828+
"Required": true,
2829+
"RequiredOnCreate": false
2830+
},
2831+
"RoleName": {
2832+
"CreateOnly": true,
2833+
"Persist": false,
2834+
"WriteOnly": false,
2835+
"Required": true,
2836+
"RequiredOnCreate": false
2837+
}
2838+
},
2839+
"Discoverable": false,
2840+
"Extractable": false
2841+
},
2842+
"Properties": {
2843+
"PolicyDocument": {
2844+
"Statement": [
2845+
{
2846+
"Action": "*",
2847+
"Effect": "Allow",
2848+
"Resource": "*"
2849+
}
2850+
],
2851+
"Version": "2012-10-17"
2852+
},
2853+
"PolicyName": "SysOpsAdmin",
2854+
"RoleName": {
2855+
"$label": "developer",
2856+
"$property": "RoleName",
2857+
"$res": true,
2858+
"$stack": "$unmanaged",
2859+
"$type": "AWS::IAM::Role",
2860+
"$value": "developer"
2861+
}
2862+
},
2863+
"NativeID": "SysOpsAdmin|developer",
2864+
"Ksuid": "363KCYk8M5JahXzZPibwPxwA4Vh"
28012865
}
28022866
]
28032867
}

plugins/pkl/generator/gen.pkl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,18 @@ local function formatValueWithTypes(value: Any, indent: String): String =
538538
let (label = value.getOrNull("FakeLabel"))
539539
let (property = value.getOrNull("FakeProperty"))
540540
let (realValue = if (value.getOrNull("$visibility") == "Clear") value.getOrNull("RealValue") else "Secret")
541-
let (comment = if (realValue != null) "\n" + indent + " // RealValue: \(realValue)" else "")
542-
typeDeclaration + " {" +
543-
comment + "\n" +
544-
(if (stack != null) indent + " stack = \"\(stack)\".label\n" else "") +
545-
(if (label != null) indent + " label = \"\(label)\"\n" else "") +
546-
indent + "}.\(property)"
541+
542+
// Check if stack is unmanaged
543+
if (stack == "$unmanaged")
544+
let (comment = "// The target resource with the label = \"\(label)\" of type = \"\(value["FakeType"])\" is not managed yet. Bring it under management first to convert this into a Resolvable.")
545+
"\"\(realValue)\" \(comment)"
546+
else
547+
let (comment = if (realValue != null) "\n" + indent + " // RealValue: \(realValue)" else "")
548+
typeDeclaration + " {" +
549+
comment + "\n" +
550+
(if (stack != null) indent + " stack = \"\(stack)\".label\n" else "") +
551+
(if (label != null) indent + " label = \"\(label)\"\n" else "") +
552+
indent + "}.\(property)"
547553
else if (typeName == "FakeValue")
548554
// Special handling for FakeValue
549555
let (fakeValue = value.getOrNull("FakeValue"))

0 commit comments

Comments
 (0)