https://pulumi.com logo
#typescript
Title
# typescript
f

freezing-twilight-25806

03/01/2023, 10:02 AM
Hi guys! I'm trying to manage some simple code and use output from resource1 (arn of aws sqs) as input for resource2 (iam policy), but with no luck... the error appears:
Copy code
Diagnostics:
  aws:iam:Policy (doc-mgmt-dev):
    error: 1 error occurred:
        * creating IAM Policy doc-mgmt-dev-ef9a0e5: MalformedPolicyDocument: Partition "
        1" is not valid for resource "arn:
        1: o.apply(v => v.toJSON())
        2: o.apply(v => JSON.stringify(v))

    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of @pulumi/pulumi.:*".
Here is the code I use:
Copy code
import * as pulumi from "@pulumi/pulumi";
import { Sqs } from './sqs';
import { IamPolicy } from './iamPolicy';

const stackName = pulumi.getStack();
const projectName = pulumi.getProject();

const tags = {
    project: projectName,
    environment: stackName,
}

const sqsQueue1 = new Sqs(`${projectName}-${stackName}`, {
    createDlq: true,
    tags: tags,
});

const iamLambdaPolicy = new IamPolicy(`${projectName}-${stackName}`, {
    path: "/",
    description: `${projectName}-${stackName}-Lambda-policies`,
    listOfStatements: JSON.stringify({
        Version: "2012-10-17",
        Statement: [
            {
                Action: [
                    "sqs:*"
                ],
                Effect: "Allow",
                Resource: [
                    sqsQueue1.sqs.arn.apply(v => JSON.stringify(v)),
                ],
            },
            {
                Action: [
                    "sqs:ReceiveMessage"
                ],
                Effect: "Allow",
                Resource: [
                    sqsQueue1.sqsDlq?.arn.apply(v => JSON.stringify(v)),
                ],
            },
        ]
    }),
    tags: tags,
});

export const iamLambdaPoliciyArn = iamLambdaPolicy.policy.arn;
I tried to use
pulumi.all([sqsQueue1.sqs.arn, sqsQueue1.sqsDlq?.arn]).apply(([sqs1Arn, sqs1DlqArn])...
it works, but with such approach I don't see the policy resource is going to be created during
pulumi preview
e

echoing-dinner-19531

03/01/2023, 10:28 AM
Don't use
JSON.stringify
, use
Output.jsonStringify
it will handle the nested output values for you.
f

freezing-twilight-25806

03/01/2023, 10:31 AM
Do you mean here?
Copy code
Resource: [
  sqsQueue1.sqs.arn.apply(v => JSON.stringify(v)),
],
image.png
e

echoing-dinner-19531

03/01/2023, 11:54 AM
No I mean:
Copy code
listOfStatements: JSON.stringify({
=>
Copy code
listOfStatements: pulumi.output.jsonStringify({
I always forget this is on the module not the type 🤦
f

freezing-twilight-25806

03/01/2023, 11:56 AM
After the change I got this:
e

echoing-dinner-19531

03/01/2023, 11:57 AM
If you get rid of
ouput
? Just
pulumi.jsonStringify
?
Sorry trying to keep all the language libraries in my head gets in a bit of a muddle about where things are defined sometimes 😆
f

freezing-twilight-25806

03/01/2023, 12:03 PM
That worked! Thank you! 🙂