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

HCL: HEREDOC invalid escaping #3716

Open
universam1 opened this issue Aug 26, 2024 · 3 comments
Open

HCL: HEREDOC invalid escaping #3716

universam1 opened this issue Aug 26, 2024 · 3 comments
Labels
bug Something isn't working new Un-triaged issue

Comments

@universam1
Copy link

universam1 commented Aug 26, 2024

Expected Behavior

For a multiline string, which is rendered into a HEREDOC for HCL output, the quotes should not be escaped.
Vault policy or AWS IAM policy render invalid.

Actual Behavior

Synth renders invalid strings, that are causing errors to apply at Vault or AWS.

Code: 400. Errors: * failed to parse policy: At 2:19: illegal char

Steps to Reproduce

y := `
path "secret/*" {
   capabilities = ["create", "read", "update", "delete", "list"]
}
`
policy.NewPolicy(stack, jsii.String("policy"), &policy.PolicyConfig{
	Name:   jsii.String("test),
	Policy: jsii.String(y),
})

Results into:
cdktf synth -hcl
Note the escaped quotes:

resource "vault_policy" "policy" {
  name   = "test"
  policy = <<EOF

        path \"secret/*\" {
          capabilities = [\"create\", \"read\", \"update\", \"delete\", \"list\"]
        }
        
EOF
}

Versions

language Golang
"version": "0.20.8"
same problem with 0.21.0-pre.123

Providers

  • aws
  • vault

Workarounds

try to use a single line statement, like a minified json.

Anything Else?

No response

References

try the example of https://github.com/ahmadalibagheri/cdktf-go-aws-iam

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
@universam1 universam1 added bug Something isn't working new Un-triaged issue labels Aug 26, 2024
@universam1
Copy link
Author

Another example issue for AWS IAM Policy:

	iampolicy.NewIamPolicy(stack, jsii.String("test"), &iampolicy.IamPolicyConfig{
		Name: jsii.String("CDKtf-Golang-policy-Demo"),
		Policy: jsii.String(`{
			"Version": "2012-10-17",
			"Statement": [{
				"Action": "*",
				"Resource": ["arn:aws:ec2:*:*:client-vpn-endpoint/*"],
				"Effect": "Allow"
			}]
		}`),
		Description: jsii.String("This policy is for Golang demo"),
	})

renders into escaped quotes in a heredoc which is invalid:

resource "aws_iam_policy" "test" {
  description = "This policy is for Golang demo"
  name        = "CDKtf-Golang-policy-Demo"
  policy      = <<EOF
{
			\"Version\": \"2012-10-17\",
			\"Statement\": [{
				\"Action\": \"*\",
				\"Resource\": [\"arn:aws:ec2:*:*:client-vpn-endpoint/*\"],
				\"Effect\": \"Allow\"
			}]
		}
EOF
}

@universam1 universam1 changed the title HEREDOC: invalid escaping HCL: HEREDOC invalid escaping Aug 27, 2024
@universam1
Copy link
Author

Note, even JSON synth is invalid! The references are escaped with double $ signs \"$$

    "vault_policy": {
      "test": {
        "//": {
          "metadata": {
            "path": "o11n:union/policyo11n.artifactory@p",
            "uniqueId": "policyo11nartifactoryp"
          }
        },
        "name": "o11n.artifactory@p",
        "policy": "path \"$${vault_aws_secret_backend_role.vroleo11nartifactorypjw-cd-cicd-01.backend}/+/$${vault_aws_secret_backend_role.vroleo11nartifactorypjw-cd-cicd-01.name}\" {\n  capabilities = [\"read\"]\n}\npath \"$${vault_aws_secret_backend_role.vroleo11nartifactorypjw-cd-lab-...."
      },

@ehvidal
Copy link

ehvidal commented Aug 27, 2024

Seeing the same problem. Looking forward for a solution. Thank you very much! 😃

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

No branches or pull requests

3 participants
@universam1 @ehvidal and others