Use pulumi.jsonStringify
MODIFY
aws-native-ts-s3-folder/index.ts
aws-native-ts-s3-folder/index.ts
@@ -28,7 +28,7 @@ for (const item of fs.readdirSync(siteDir)) {
// Set the access policy for the bucket so all objects are readable
const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
bucket: siteBucket.id, // refer to the bucket created earlier
- policy: siteBucket.arn.apply(bucketArn => JSON.stringify({
+ policy: pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
@@ -37,10 +37,10 @@ const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
"s3:GetObject",
],
Resource: [
- `${bucketArn}/*`, //
+ pulumi.interpolate `${siteBucket.arn}/*`,
],
}],
- })),
+ }),
});
// Stack exports

MODIFY
aws-native-ts-stepfunctions/index.ts
aws-native-ts-stepfunctions/index.ts
@@ -75,25 +75,22 @@ const sfnRolePolicy = new aws.iam.RolePolicy("sfnRolePolicy", {
const stateMachine = new awsnative.stepfunctions.StateMachine("stateMachine", {
roleArn: sfnRole.arn,
stateMachineType: "EXPRESS",
- definitionString: pulumi.all([helloFunction.arn, worldFunction.arn])
- .apply(([helloArn, worldArn]) => {
- return JSON.stringify({
+ definitionString: pulumi.jsonStringify({
"Comment": "A Hello World example of the Amazon States Language using two AWS Lambda Functions",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Task",
- "Resource": helloArn,
+ "Resource": helloFunction.arn,
"Next": "World",
},
"World": {
"Type": "Task",
- "Resource": worldArn,
+ "Resource": worldFunction.arn,
"End": true,
},
},
- });
- }),
+ })
}, {dependsOn: sfnRolePolicy});
export const stateMachineArn = stateMachine.id;

MODIFY
aws-ts-apigateway-eventbridge/index.ts
aws-ts-apigateway-eventbridge/index.ts
@@ -112,18 +112,16 @@ const integration = new aws.apigateway.Integration("integration", {
"integration.request.header.Content-Type": "'application/x-amz-json-1.1'",
},
requestTemplates: {
- "application/json": bus.name.apply((busName) =>
- JSON.stringify({
+ "application/json": pulumi.jsonStringify({
Entries: [
{
Source: "my-event-source",
- EventBusName: busName,
+ EventBusName: bus.name,
DetailType: "my-detail-type",
Detail: "$util.escapeJavaScript($input.body)",
},
],
- }),
- ),
+ })
},
});
@@ -172,32 +170,16 @@ const deployment = new aws.apigateway.Deployment(
// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment#triggers
triggers: {
// The property name ("deployment") isn't relevant here; it can actually be anything you like.
- deployment: pulumi
- .all([
+ deployment:
+ // Stringify the array of properties to create a diff (triggering
+ // a redeployment) if/when one of the properties listed changes.
+ pulumi.jsonStringify([
resource.id,
method.id,
integration.requestTemplates,
integrationResponse.responseTemplates,
method.requestValidatorId,
- ])
- .apply(
- ([
- resourceID,
- methodID,
- methodRequestValidatorID,
- integrationRequestTemplates,
- integrationResponseTemplates,
- ]) =>
- // Stringify the array of properties to create a diff (triggering
- // a redeployment) if/when one of the properties listed changes.
- JSON.stringify([
- resourceID,
- methodID,
- methodRequestValidatorID,
- integrationRequestTemplates,
- integrationResponseTemplates,
]),
- ),
},
},
);

MODIFY
aws-ts-ecs-anywhere/index.ts
aws-ts-ecs-anywhere/index.ts
@@ -150,19 +150,15 @@ const repo = new awsx.ecr.Repository("app");
const image = repo.buildAndPushImage("./app");
// Set up task definition
-const taskDefinition = pulumi
- .all([image, logGroup.name, logGroup.namePrefix])
- .apply(
- ([img, logGroupName, nameprefix]) =>
- new aws.ecs.TaskDefinition("taskdefinition", {
+const taskDefinition = new aws.ecs.TaskDefinition("taskdefinition", {
family: "ecs-anywhere",
requiresCompatibilities: ["EXTERNAL"],
taskRoleArn: taskRole.arn,
executionRoleArn: executionRole.arn,
- containerDefinitions: JSON.stringify([
+ containerDefinitions: pulumi.jsonStringify([
{
name: "app",
- image: img,
+ image: image,
cpu: 256,
memory: 256,
essential: true,
@@ -175,15 +171,14 @@ const taskDefinition = pulumi
logConfiguration: {
logDriver: "awslogs",
options: {
- "awslogs-group": logGroupName,
+ "awslogs-group": logGroup.name,
"awslogs-region": awsRegion,
- "awslogs-stream-prefixs": nameprefix,
+ "awslogs-stream-prefixs": logGroup.namePrefix,
},
},
},
]),
- }),
- );
+});
// Deploy containers to droplets
const service = new aws.ecs.Service("service", {

MODIFY
aws-ts-s3-folder/index.ts
aws-ts-s3-folder/index.ts
@@ -27,7 +27,7 @@ for (const item of fs.readdirSync(siteDir)) {
// Set the access policy for the bucket so all objects are readable
const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
bucket: siteBucket.id, // refer to the bucket created earlier
- policy: siteBucket.arn.apply(bucketArn => JSON.stringify({
+ policy: pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
@@ -36,10 +36,10 @@ const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
"s3:GetObject",
],
Resource: [
- `${bucketArn}/*`, //
+ pulumi.interpolate `${siteBucket.arn}/*`,
],
}],
- })),
+ }),
});
// Stack exports

MODIFY
aws-ts-static-website/index.ts
aws-ts-static-website/index.ts
@@ -297,19 +297,19 @@ function createWWWAliasRecord(targetDomain: string, distribution: aws.cloudfront
const bucketPolicy = new aws.s3.BucketPolicy("bucketPolicy", {
bucket: contentBucket.id, // refer to the bucket created earlier
- policy: pulumi.all([originAccessIdentity.iamArn, contentBucket.arn]).apply(([oaiArn, bucketArn]) =>JSON.stringify({
+ policy: pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Principal: {
- AWS: oaiArn,
+ AWS: originAccessIdentity.iamArn,
}, // Only allow Cloudfront read access.
Action: ["s3:GetObject"],
- Resource: [`${bucketArn}/*`], // Give Cloudfront access to the entire bucket.
+ Resource: [pulumi.interpolate `${contentBucket.arn}/*`], // Give Cloudfront access to the entire bucket.
},
],
- })),
+ })
});
const aRecord = createAliasRecord(config.targetDomain, cdn);

MODIFY
aws-ts-stepfunctions/index.ts
aws-ts-stepfunctions/index.ts
@@ -62,25 +62,22 @@ const worldFunction = new aws.lambda.CallbackFunction(
const stateMachine = new aws.sfn.StateMachine("stateMachine", {
roleArn: sfnRole.arn,
- definition: pulumi.all([helloFunction.arn, worldFunction.arn])
- .apply(([helloArn, worldArn]) => {
- return JSON.stringify({
+ definition: pulumi.jsonStringify({
"Comment": "A Hello World example of the Amazon States Language using two AWS Lambda Functions",
"StartAt": "Hello",
"States": {
"Hello": {
"Type": "Task",
- "Resource": helloArn,
+ "Resource": helloFunction.arn,
"Next": "World",
},
"World": {
"Type": "Task",
- "Resource": worldArn,
+ "Resource": worldFunction.arn,
"End": true,
},
},
- });
- }),
+ })
});
export const stateMachineArn = stateMachine.id;

MODIFY
aws-ts-wordpress-fargate-rds/frontend.ts
aws-ts-wordpress-fargate-rds/frontend.ts
@@ -82,16 +82,14 @@ export class WebService extends pulumi.ComponentResource {
// Spin up a load balanced service running our container image.
const taskName = `${name}-app-task`;
const containerName = `${name}-app-container`;
- const taskDefinition = pulumi.all([args.dbHost, args.dbPort, args.dbName, args.dbUser, args.dbPassword]).
- apply(([dbHost, dbPort, dbName, dbUser, dbPassword]) =>
- new aws.ecs.TaskDefinition(taskName, {
+ const taskDefinition = new aws.ecs.TaskDefinition(taskName, {
family: "fargate-task-definition",
cpu: "256",
memory: "512",
networkMode: "awsvpc",
requiresCompatibilities: ["FARGATE"],
executionRoleArn: role.arn,
- containerDefinitions: JSON.stringify([{
+ containerDefinitions: pulumi.jsonStringify([{
"name": containerName,
"image": "wordpress",
"portMappings": [{
@@ -102,24 +100,23 @@ export class WebService extends pulumi.ComponentResource {
"environment": [
{
"name": "WORDPRESS_DB_HOST",
- "value": `${dbHost}:${dbPort}`,
+ "value": pulumi.interpolate `${args.dbHost}:${args.dbPort}`,
},
{
"name": "WORDPRESS_DB_NAME",
- "value": `${dbName}`,
+ "value": args.dbName,
},
{
"name": "WORDPRESS_DB_USER",
- "value": `${dbUser}`,
+ "value": args.dbUser,
},
{
"name": "WORDPRESS_DB_PASSWORD",
- "value": `${dbPassword}`,
+ "value": args.dbPassword,
},
],
}]),
- }, { parent: this }),
- );
+ }, { parent: this });
const service = new aws.ecs.Service(`${name}-app-svc`, {
cluster: cluster.arn,

MODIFY
kubernetes-ts-s3-rollout/s3Helpers.ts
kubernetes-ts-s3-rollout/s3Helpers.ts
@@ -64,8 +64,7 @@ export class FileBucket {
// Create an S3 Bucket Policy to allow public read of all objects in bucket
export function publicReadPolicy(bucket: aws.s3.Bucket): pulumi.Output<string> {
- return bucket.bucket.apply(bucketName =>
- JSON.stringify({
+ return pulumi.jsonStringify({
Version: "2012-10-17",
Statement: [
{
@@ -73,10 +72,9 @@ export function publicReadPolicy(bucket: aws.s3.Bucket): pulumi.Output<string> {
Principal: "*",
Action: ["s3:GetObject"],
Resource: [
- `arn:aws:s3:::${bucketName}/*`, // policy refers to bucket name explicitly
+ pulumi.interpolate `arn:aws:s3:::${bucket.bucket}/*`, // policy refers to bucket name explicitly
],
},
],
- }),
- );
+ });
}

Use pulumi.jsonStringify (#1332)