Skip to content

Commit 1af8e99

Browse files
committed
fix: construct json better
1 parent 5d64033 commit 1af8e99

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

pkg/builder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
8080
component.IAMRole = role
8181

8282
// Create KMS policy
83-
policyJSON := createKMSPolicy(args.BuilderEnv.BuilderKey)
83+
policyJSON := CreateKMSPolicy(args.BuilderEnv.BuilderKey)
8484

8585
policy, err := iam.NewPolicy(ctx, fmt.Sprintf("%s-policy", args.Name), &iam.PolicyArgs{
8686
Policy: policyJSON,

pkg/builder/helpers.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package builder
22

33
import (
4+
"encoding/json"
45
"reflect"
56
"strings"
67
"unicode"
@@ -12,24 +13,28 @@ import (
1213
// CreateKMSPolicy creates a KMS policy for the builder service.
1314
// Exported for testing.
1415
func CreateKMSPolicy(key pulumi.StringInput) pulumi.StringOutput {
15-
return pulumi.Sprintf(`{
16-
"Version": "2012-10-17",
17-
"Statement": [
16+
policy := KMSPolicy{
17+
Version: "2012-10-17",
18+
Statement: []KMSStatement{
1819
{
19-
"Effect": "Allow",
20-
"Action": [
20+
Effect: "Allow",
21+
Action: []string{
2122
"kms:Sign",
22-
"kms:GetPublicKey"
23-
],
24-
"Resource": %s
25-
}
26-
]
27-
}`, key)
28-
}
23+
"kms:GetPublicKey",
24+
},
25+
Resource: key,
26+
},
27+
},
28+
}
2929

30-
// createKMSPolicy is the internal version kept for backward compatibility
31-
func createKMSPolicy(key pulumi.StringInput) pulumi.StringOutput {
32-
return CreateKMSPolicy(key)
30+
// Convert to JSON string output
31+
return pulumi.All(key).ApplyT(func(_ []interface{}) (string, error) {
32+
jsonBytes, err := json.Marshal(policy)
33+
if err != nil {
34+
return "", err
35+
}
36+
return string(jsonBytes), nil
37+
}).(pulumi.StringOutput)
3338
}
3439

3540
// CreateEnvVars creates environment variables by automatically mapping

0 commit comments

Comments
 (0)