Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: "You're using escape sequences (${...}) with CDKTF Built-in functions" - false positive? #3562

Open
1 task
elruwen opened this issue Mar 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@elruwen
Copy link

elruwen commented Mar 22, 2024

Expected Behavior

No error message. I am not using escape sequences anywhere explicitly. I believe this is a false positive.

Actual Behavior

Given the following example application:

import {Construct} from "constructs";
import {App, Fn, TerraformStack, TerraformVariable} from "cdktf";
import {File} from "@cdktf/provider-local/lib/file";
import {LocalProvider} from "@cdktf/provider-local/lib/provider";

class MyStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new LocalProvider(this, "p")

        const myvar = new TerraformVariable(this, "prefix", {
            type: "string",
            default: "rwn-",
            description: "prefix",
        })

        const resources = [
            {
                foo: myvar.stringValue + "bar",
            },
            {
                bar: myvar.stringValue + "foo"
            }
        ]

        new File(this, "ruwen", {
            filename: `ruwen.yaml`,
            content: Fn.yamlencode(resources)
        })
    }
}

const app = new App();
new MyStack(app, "cdktf-playground");
app.synth();

This generates successfully the following yaml file without warnings:

- "foo": "rwn-bar"
- "bar": "rwn-foo"

But if I use the result from the Fn.yamlencode in another function, I am getting an error.

import {Construct} from "constructs";
import {App, Fn, TerraformStack, TerraformVariable} from "cdktf";
import {File} from "@cdktf/provider-local/lib/file";
import {LocalProvider} from "@cdktf/provider-local/lib/provider";

class MyStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new LocalProvider(this, "p")

        const myvar = new TerraformVariable(this, "prefix", {
            type: "string",
            default: "rwn-",
            description: "prefix",
        })

        const resources = [
            {
                foo: myvar.stringValue + "bar",
            },
            {
                bar: myvar.stringValue + "foo"
            }
        ]

        new File(this, "ruwen", {
            filename: `ruwen.yaml`,
            content: Fn.join("", [Fn.yamlencode(resources)])
        })
    }
}

const app = new App();
new MyStack(app, "cdktf-playground");
app.synth();
[2024-03-22T11:35:57.800] [ERROR] default - You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.

[2024-03-22T11:35:57.800] [ERROR] default - yamlencode([{"foo" = "${${TfToken[TOKEN.0]}}bar"}, {"bar" = "${${TfToken[TOKEN.1]}}foo"}])
You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.
yamlencode([{"foo" = "${${TfToken[TOKEN.0]}}bar"}, {"bar" = "${${TfToken[TOKEN.1]}}foo"}])

[2024-03-22T11:35:57.801] [ERROR] default - You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.
yamlencode([{"foo" = "${${TfToken[TOKEN.0]}}bar"}, {"bar" = "${${TfToken[TOKEN.1]}}foo"}])

[2024-03-22T11:35:57.803] [ERROR] default - You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.
yamlencode([{"foo" = "${${TfToken[TOKEN.0]}}bar"}, {"bar" = "${${TfToken[TOKEN.1]}}foo"}])

[2024-03-22T11:35:57.803] [ERROR] default - You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.
yamlencode([{"foo" = "${${TfToken[TOKEN.0]}}bar"}, {"bar" = "${${TfToken[TOKEN.1]}}foo"}])

[2024-03-22T11:35:57.803] [ERROR] default - You're using escape sequences (${...}) with CDKTF Built-in functions. This is not supported yet, and the output may be incorrect.

The file still gets generated correctly.

If I do something wrong, then the error message should point to the spot where I use Fn.join. Because the yamlencode without the join works.
If it is a false positive, then the warning shouldn't be there.

Steps to Reproduce

See above

Versions

cdktf debug
language: typescript
cdktf-cli: 0.20.4
node: v18.15.0
cdktf: 0.20.5
constructs: 10.3.0
jsii: null
terraform: 1.7.5
arch: x64
os: linux 6.1.0-17-amd64
providers
@cdktf/provider-local (PREBUILT)
terraform provider version: 2.5.1
prebuilt provider version: 10.1.0
cdktf version: ^0.20.0

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬───────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼───────────────────────┼─────────────────┤
│ local │ 2.5.1 │ ^0.20.0 │ │ @cdktf/provider-local │ 10.1.0 │
└───────────────┴──────────────────┴─────────┴────────────┴───────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

No response

Workarounds

No response

Anything Else?

No response

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@elruwen elruwen added bug Something isn't working new Un-triaged issue labels Mar 22, 2024
@mutahhir
Copy link
Contributor

I think the root of the problem might lie in this code:

                foo: myvar.stringValue + "bar",

If you were to replace this with Fn.join("", [myvar.stringValue, "bar"]), and try again, does the error go away?

@mutahhir mutahhir added waiting-on-answer and removed new Un-triaged issue labels Mar 25, 2024
@elruwen
Copy link
Author

elruwen commented Mar 26, 2024

That works. But I think it is a bit tedious to use. Especially when it comes to format strings. And the generated code looks good. Do you have currently cases where it doesn't work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants