refined-terabyte-65361
08/16/2021, 4:41 PMCalling [toString] on an [Output<T>] is not supported.
o get the value of an Output<T> as an Output<string> consider
code :
const accessLogsBucket = new aws.s3.Bucket(dev-access-logs,{bucket:dev-access-logs});
const accessbucketPolicy = new aws.s3.BucketPolicy(`${accessLogsBucket.id}`, {
bucket: accessLogsBucket.bucket,
policy: accessLogsBucket.bucket.apply(accessLogsBucketPolicy)
})
green-stone-37839
08/16/2021, 5:12 PMaccessLogsBucket.toString()
?
If so, you'll need to use the apply()
function. This behaves like a promise<T>
and will allow you to access the underlying types of an Output<T>
.
As an example:
accessLogsBucket.id.apply(id => {
console.log(id);
};
refined-terabyte-65361
08/16/2021, 5:15 PMgreen-stone-37839
08/16/2021, 5:29 PMinterpolate
function to shorten usage. If you havent already I recommend reading this documentation.steep-toddler-94095
08/16/2021, 6:38 PMinterpolate
can't be used in the first parameter of a Pulumi resource, just fyi. If you want to create a resource with the name of an Output<string>
you'll have to create the resource within an apply
refined-terabyte-65361
08/16/2021, 7:52 PMconst accessLogsBucket = new aws.s3.Bucket(dev-access-logs,{bucket:dev-access-logs});
const bucketName = accessLogsBucket.id.apply(
(id) => id
);
when i tried to pass the bucketName to alb
"<http://alb.ingress.kubernetes.io/load-balancer-attributes|alb.ingress.kubernetes.io/load-balancer-attributes>": `access_logs.s3.enabled=true,access_logs.s3.bucket=${bucketName},access_logs.s3.prefix=dev-Access-Logs`
it still fails with below error
access_logs.s3.enabled=true,access_logs.s3.bucket=Calling [toString] on an [Output<T>] is not supported.
when i tried to print accessLogsBucket
i get below output
Bucket {
__pulumiResource: true,
__transformations: [],
__name: 'dev-access-logs',
__providers: {},
__protect: false,
__aliases: [],
id: OutputImpl {
__pulumiOutput: true,
resources: [Function (anonymous)],
allResources: [Function (anonymous)],
isKnown: Promise { <pending> },
isSecret: Promise { <pending> },
promise: [Function (anonymous)],
toString: [Function (anonymous)],
toJSON: [Function (anonymous)]
},
how to access __name: 'dev-access-logs',
?steep-toddler-94095
08/16/2021, 8:21 PMconst accessLogsBucket = new aws.s3.Bucket(dev-access-logs,{bucket:dev-access-logs});
const accessbucketPolicy = accessLogsBucket.id.apply(id =>
new aws.s3.BucketPolicy(id, {
bucket: accessLogsBucket.bucket,
...
}))
it needs to be done within the apply
so you can access the value as a string
instead of an Output<string>
little-cartoon-10569
08/16/2021, 9:16 PMapply
. It's an antipattern and will cause issues down the line.
Pulumi names are like pointers in your stack. They're not intended to be dynamic. Think of a Pulumi name as an LHS (name of a variable) rather than an RHS (value). You don't want the name of a variable to be unknown at compile time.const accessLogsBucket = new aws.s3.Bucket(dev-access-logs,{bucket:dev-access-logs});
const accessbucketPolicy = new aws.s3.BucketPolicy(dev-access-logs, {
bucket: accessLogsBucket.bucket,
policy: {
// Put your policy document here.
}
})
-
in variable names. That won't work either...steep-toddler-94095
08/16/2021, 11:32 PM