-
Notifications
You must be signed in to change notification settings - Fork 28
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
startup_script is 64encoded again if passed as base64 #168
Comments
See also #91? |
If #91 is not merge nor fixed... why is it happening 🤔 ? |
This should not happen, at least not for
Can you provide additional context and a minimal example? |
This issue still affects In the short term we can work around this on the DVC side by using HCL for now, but this will eventually be a blocker for us. |
given this {
"//": "This file auto-generated by dvc-tpi, do not edit manually.",
"terraform": {
"required_providers": {
"iterative": {
"source": "iterative/iterative"
}
}
},
"provider": {
"iterative": {}
},
"resource": {
"iterative_machine": {
"peter-test": {
"name": "peter-test",
"cloud": "aws",
"startup_script": "PDxFT0YKIyEvYmluL2Jhc2gKc3VkbyBhcHQtZ2V0IHVwZGF0ZQpzdWRvIGFwdC1nZXQgaW5zdGFsbCAtLXllcyBweXRob24zIHB5dGhvbjMtcGlwCnB5dGhvbjMgLW0gcGlwIGluc3RhbGwgLS11cGdyYWRlIHBpcAoKY2QgL2V0Yy9hcHQvc291cmNlcy5saXN0LmQKc3VkbyB3Z2V0IGh0dHBzOi8vZHZjLm9yZy9kZWIvZHZjLmxpc3QKc3VkbyBhcHQtZ2V0IHVwZGF0ZQpzdWRvIGFwdC1nZXQgaW5zdGFsbCAtLXllcyBkdmMKCkVPRg=="
}
}
}
} I would expect the machine to be created with this startup script:
I've tried using the b64 encoded version of the script both with and without the heredoc Using a |
Thanks for reproducing the issue! Then, it only "affects"
I don't think JSON Configuration Syntax supports heredoc strings at all. Ideally Most sane JSON serializers will automatically escape any valid UTF-8 string so you don't have to, but, if you still want to resort to Base64, it's as easy as using Terraform's inbuilt Valid JSON script {
"startup_script": "#!/bin/bash\nsudo apt-get update\nsudo apt-get install --yes python3 python3-pip\npython3 -m pip install --upgrade pip\n\ncd /etc/apt/sources.list.d\nsudo wget https://dvc.org/deb/dvc.list\nsudo apt-get update\nsudo apt-get install --yes dvc"
} Valid Base64 script {
"startup_script": "${base64decode(\"IyEvYmluL2Jhc2gKc3VkbyBhcHQtZ2V0IHVwZGF0ZQpzdWRvIGFwdC1nZXQgaW5zdGFsbCAtLXllcyBweXRob24zIHB5dGhvbjMtcGlwCnB5dGhvbjMgLW0gcGlwIGluc3RhbGwgLS11cGdyYWRlIHBpcAoKY2QgL2V0Yy9hcHQvc291cmNlcy5saXN0LmQKc3VkbyB3Z2V0IGh0dHBzOi8vZHZjLm9yZy9kZWIvZHZjLmxpc3QKc3VkbyBhcHQtZ2V0IHVwZGF0ZQpzdWRvIGFwdC1nZXQgaW5zdGFsbCAtLXllcyBkdmMK\")}"
} Sample JSON encoder import json
print(json.dumps({"startup_script": "#!/bin/bash ···"})) Sample Base64 encoder import json
import base64
def escape(string: str) -> str:
encoded: str = base64.b64encode(string.encode()).decode()
return f"""${{base64decode("{encoded}")}}"""
print(json.dumps({"startup_script": escape("#!/bin/bash ···")})) |
@casperdcl, how would this fit in iterative/tpi? I guess that you can get rid of HCL2 once and for all. |
Ok, that was my misunderstanding then. I was assuming that in JSON, the terraform provider needed
|
Touché! Sorry for the inconsistent API, #91's purpose is exactly modifying
Excellent! I overlooked |
Closing in favor of #91 |
If you pass a base64 startup script its encoded again
The text was updated successfully, but these errors were encountered: