VirtusLab / besom

Besom - a Pulumi SDK for Scala. Also, incidentally, a broom made of twigs tied round a stick. Brooms and besoms are used for protection, to ward off evil spirits, and cleansing of ritual spaces.
https://virtuslab.github.io/besom/
Apache License 2.0
114 stars 7 forks source link

Easy to accidentally use default `toString` with string interpolation #185

Open pawelprazak opened 9 months ago

pawelprazak commented 9 months ago

When referencing name in flatMap like this:

  val siteBucketPolicy = siteBucket.flatMap(name =>
    s3.BucketPolicy(
      s"${name}-access-policy",
  ...

this happens:

 +   ├─ aws:s3:Bucket                   s3-website-bucket                                                                         
 +   ├─ aws:s3:BucketPublicAccessBlock  Bucket(besom.internal.Output@2202995c,besom.internal.Output@36cb79e5,besom.internal.Output
 +   ├─ aws:s3:BucketPolicy             Bucket(besom.internal.Output@2202995c,besom.internal.Output@36cb79e5,besom.internal.Output
 +   ├─ aws:s3:BucketObject             favicon.ico                                                                               
 +   └─ aws:s3:BucketObject             index.html    

The full name of the policy:

aws:s3:BucketPolicy (Bucket(besom.internal.Output@1ed716ec,besom.internal.Output@3fc2b7c3,besom.internal.Output@2d9f7770,besom.internal.Output@44692a65,besom.internal.Output@622f3472,besom.internal.Output@4879eb5b,besom.internal.Output@1e8b31d3,besom.internal.Output@13bc1a65,besom.internal.Output@82b20c4,besom.internal.Output@f8f21a9,besom.internal.Output@484d8c22,besom.internal.Output@3b51c87c,besom.internal.Output@6aadf2d2,besom.internal.Output@1c591447,besom.internal.Output@38d1a772,besom.internal.Output@df68a3c,besom.internal.Output@8c8c232,besom.internal.Output@5ce70440,besom.internal.Output@6938d299,besom.internal.Output@50a612e8,besom.internal.Output@1eb1939c,besom.internal.Output@7a10410e,besom.internal.Output@5513e8cf,besom.internal.Output@354281d7,besom.internal.Output@277dd990,besom.internal.Output@5f1df440,besom.internal.Output@15823afc)-access-policy

Resource names should be shown instead. Not sure if this is a bug or user error (in this case it is an error prone construct and we might want to find a mitigation strategy for the user)

pawelprazak commented 9 months ago

OK, this was an embarrassing copy-paste kind of error ;)

Fix: siteBucket -> siteBucket.bucket

I keep wandering thou, if we could somehow detect and warn the user about this type of mistake.

lbialy commented 5 months ago

uh, our compiler plugin could, in theory, crash compilation if you try to interpolate anything that is <: Resource just like it crashes on interpolation of Output with f/raw/s interpolators.