https://pulumi.com logo
#aws
Title
# aws
p

polite-king-94596

05/18/2022, 5:55 PM
hey all, just learned about policy documents and how if we don't json.stringify the docs when inlining it in a RolePolicy args, pulumi will do this for you. This has an advantage of allowing you to use Pulumi Input/Output types in policy documents too. However, I don't see any documentation for this, and I was wondering if anyone had seen one or if it's something that was rolled out recently and is in some blog post?
v

victorious-church-57397

05/18/2022, 7:51 PM
if you’re using typescript (which im guessing you are due to json.stringify reference) you can create an object which is of type iam.PolicyDocument and looks much tidier and easier to work with than json stringify… see example :
Copy code
const examplePolicyDocument: iam.PolicyDocument = {
  Version: '2012-10-17',
  Statement: [
    {
      Effect: 'Allow',
      Action: ['s3:GetBucketAcl', 's3:ListBucket', 's3:PutObject'],
      Resource: [pulumi.interpolate`${bucket.arn}`, pulumi.interpolate`${bucket.arn}/*`],
    },
  ],
};
and you can use like this:
Copy code
new iam.RolePolicy(
  'exampleRolePolicy',
  {
    role: exampleRole.id,
    policy: examplePolicyDocument,
  },
);
p

polite-king-94596

05/18/2022, 8:18 PM
oh i see its defined as a type, and not a resource in the pulumi/aws lib
l

little-cartoon-10569

05/18/2022, 8:40 PM
FYI @victorious-church-57397: pulumi.interpolate`${bucket.arn}` can be rewritten as
bucket.arn
.
v

victorious-church-57397

05/18/2022, 8:41 PM
The bucket in question is imported from a different file so had to use interpolate
l

little-cartoon-10569

05/18/2022, 8:41 PM
If
bucket
is an object and
bucket.arn
is an ARN, then you don't need interpolate.
interpolate
is just a convenience function for
s.apply(s => s.toString())
With interpolation added, obviously 🙂
v

victorious-church-57397

05/18/2022, 8:43 PM
Yeah, aware of that cheers mate but was getting an error suggesting that we used interpolate so just followed the docs! Normally just use the object where I can
👍 1
34 Views