full-king-49894
04/15/2022, 7:29 PMconst originAccessIdentity = new aws.cloudfront.OriginAccessIdentity("oai", {
comment: "Some comment",
});
But now I need to dereference the newly created ETag/Id to use in
...
origins: [
{
domainName: bucketV2.bucketRegionalDomainName,
originId: s3OriginId,
s3OriginConfig: {
originAccessIdentity: `origin-access-identity/cloudfront/${originAccessIdentity.id}` <=== Does not work
},
},
],
...
It does not seem possible to simply use originAccessIdentity.id
as the returned value is an object wrapped in pulumi sugar. I have tried all sorts of ways to try and get properties from the returned object including:
originAccessIdentity.id
originAccessIdentity.get()
originAccessIdentity.get("id")
originAccessIdentity.id.apply(id=>id)
I am following along on https://www.pulumi.com/docs/intro/concepts/inputs-outputs/ as well as using step-through debugging via VSCode to inspect the returned object.billowy-army-68599
full-king-49894
04/15/2022, 8:37 PM.apply()
assuming it was JavaScript apply when in actual fact it is a Pulumi SDK method of the same name?await
but to no avail. I found this about interpolation in the docs but it is in the context of converting inputs to outputs and my use case is very much about simply getting a property from an output object.const originAccessIdentity = new aws.cloudfront.OriginAccessIdentity("test");
const cmt = pulumi.interpolate(originAccessIdentity.Name);
console.log("Name", cmt);
Which still returns the same non-string result
Name Proxy {__pulumiOutput: true, resources: ƒ, allResources: ƒ, isKnown: Promise, isSecret: Promise, …}
arg1:Proxy {__pulumiOutput: true, resources: ƒ, allResources: ƒ, isKnown: Promise, isSecret: Promise, …}
[[Handler]]:Object
get:(obj, prop) => {…}
__proto__:Object
[[IsRevoked]]:false
[[Target]]:OutputImpl
__pulumiOutput:true
allResources:() => lifted.then(l => l.allResources)
isKnown:Promise {<pending>}
isSecret:Promise {<pending>}
promise:(withUnknowns) => OutputImpl.getPromisedValue(lifted.then(l => l.value), withUnknowns)
resources:() => resourcesCopy
toJSON:() => {\n const message = `Calling [toJSON] on an [Output<T>] is not supported.\n\nTo get the value of an Output as a JSON value or JSON string consider either:\n 1: o.apply(v => v.toJSON())\n 2: o.apply(v => JSON.stringify(v))\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi.`;\n return message;\n }
toString:() => {\n const message = `Calling [toString] on an [Output<T>] is not supported.\n\nTo get the value of an Output<T> as an Output<string> consider either:\n1: o.apply(v => \\`prefix\\${v}suffix\\`)\n2: pulumi.interpolate \\`prefix\\${v}suffix\\`\n\nSee <https://pulumi.io/help/outputs> for more details.\nThis function may throw in a future version of @pulumi/pulumi.`;\n return message;\n }
__proto__:Object
billowy-army-68599
full-king-49894
04/15/2022, 9:15 PMbillowy-army-68599
full-king-49894
04/15/2022, 9:20 PMoriginAccessIdentity
(about line 17). Rather than create one in the AWS console I thought I would dogfood it and use Pulumi. So, between the bucket ACL and creating the distribution I have something like
const originAccessIdentity = new aws.cloudfront.OriginAccessIdentity("test");
const cmt = pulumi.interpolate`${originAccessIdentity.id}`;
console.log("Name", cmt.toString());
//console.log(originAccessIdentity.apply(cloudfrontAccessIdentityPath));
I say "something like" because I have been editing those same four lines for a few hours now. Once I can understand how to reference the returned property I can clean it all upbillowy-army-68599
console.log
isn't working is because it's the wrong way round, it should be:
originAccessIdentity.cloudfrontAccessIdentityPath.apply(value => {
console.log(value)
})
full-king-49894
04/15/2022, 10:01 PMbillowy-army-68599
apply
is handling for youfull-king-49894
04/15/2022, 10:05 PMpulumi up
because I have deleted Origin access identities from the AWS console. Up is now failing with 404 errors saying it cannot access the identities I have deleted. I have tried pulumi destroy
but that does not seem to clear things up. Do I need to recreate all those test identities in the console THEN delete them via Pulumi?originAccessIdentity.cloudfrontAccessIdentityPath.apply(value => {
console.log(value)
})
as an example, and promisify the object that gets returned.billowy-army-68599
full-king-49894
04/15/2022, 10:15 PMoriginAccessIdentity.cloudfrontAccessIdentityPath.apply(value => {
console.log(value)
})
Is it possible to get the object? E.g. one level up? Let's say that in a different case the call results in half a dozen properties that are useful. Do I need to do something like
someMethod.property1.apply(value => {
console.log(value)
})
someMethod.property2.apply(value => {
console.log(value)
})
someMethod.property3.apply(value => {
console.log(value)
})
... etc
billowy-army-68599
full-king-49894
04/15/2022, 10:22 PMbillowy-army-68599
export const path = originAccessIdentity.cloudfrontAccessIdentityPath
an output value can be passed to another pulumi resource without the need to get its async valueyou almost never want to use the plain value because passing an output from one resource to another is how Pulumi builds its dependency graph
full-king-49894
04/15/2022, 10:24 PMbillowy-army-68599
full-king-49894
04/15/2022, 10:26 PMbillowy-army-68599
full-king-49894
04/15/2022, 10:27 PMbillowy-army-68599
# here we create an S3 bucket
const bucketV2 = new aws.s3.BucketV2("bucketV2", {tags: {
Name: "My bucket",
}});
then here, we create another resource, a bucket acl. you'll notice we pass the bucketV2.id
from the first resource into here. This is telling Pulumi that the bAcl depends on a value from bucketV2 and builds a dependency graph. This is going to be really hard to do in your imperative code, Pulumi handles it all for you
const bAcl = new aws.s3.BucketAclV2("bAcl", {
bucket: bucketV2.id,
acl: "private",
});
full-king-49894
04/15/2022, 10:34 PM