-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
user-data sometimes corrupted #754
Comments
Unfortunately it seems that this issue is caused by the fact that Terraform is not designed to preserve raw binary data stored in variables. The reason it seems to work intermittently is that if the rendering of the cloudinit config and its use in the This difference can be seen in the plan output if I first allow it to deal with both resources at the same time:
...and then use
Notice that in the second example there are lots of Unicode Replacement Character (�) which results when attempting to interpret non-UTF8 data as UTF8. Eventually we will hopefully have a way to use raw binary data in Terraform, but in the short term I'm planning to deal with this in the following way:
The example in the original comment would then become: data "template_cloudinit_config" "config" {
gzip = true
base64_encode = true
...
}
resource "aws_instance" "my_instance" {
user_data_base64 = "${data.template_cloudinit_config.config.rendered}"
...
} Since the EC2 resource implementations will decode the base64 encoding client-side, this will achieve an equivalent result but will avoid the risk of data corruption caused by trying to pass the binary data between resources directly. This is consistent with (and complementary to) where we landed on hashicorp/terraform#3858, which would've suffered the same problem. |
@apparentlymart thanks for your comprehensive explanation (as usual). |
I think this bug should be almost fixed and can be closed upon the next release of the AWS provider?
|
Closing as per #497 (comment) |
Thanks for pointing this out @tamsky ! |
I am getting exact same issue if I use data "template_cloudinit_config" "config" {
gzip = true
base64_encode = true
part {
filename = "test"
content_type = "text/cloud-config"
content = "${file("${path.module}/../../resources/test")}"
}
}
resource "aws_launch_template" "template" {
...
user_data = "${data.template_cloudinit_config.config.rendered}"
...
} Worth mentioning my cloud-init file has Unfortunately, |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
This issue was originally opened by @mcanevet as hashicorp/terraform#14314. It was migrated here as part of the provider split. The original body of the issue is below.
Terraform Version
v0.9.4
Affected Resource(s)
Terraform Configuration Files
Expected Behavior
Cloud-init should always get the correct user_data
Actual Behavior
Somehow, sometimes cloud-init does not apply the configuration. When I log into an instance that failed and try to get the user_data, it looks like the metadata does not serves un gzipped content...
If I taint the
aws_instance
resource and apply it again (without changing thetemplate_cloudinit_config
datasource it works...I'm not sure if it's a bug in aws metadata or in terraform as I don't understand in details how user_data works.
Unfortunately I can't always reproduce the issue...
The text was updated successfully, but these errors were encountered: