From 42e689376a63cb3da86b9f94462eaca31cb0b22a Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Wed, 12 Oct 2022 13:35:58 +0300 Subject: [PATCH] Add example for using cloud-config in place of file provisioners --- .../resources/provisioners/syntax.mdx | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/website/docs/language/resources/provisioners/syntax.mdx b/website/docs/language/resources/provisioners/syntax.mdx index df421527a5..7b8bcbb4b1 100644 --- a/website/docs/language/resources/provisioners/syntax.mdx +++ b/website/docs/language/resources/provisioners/syntax.mdx @@ -95,6 +95,44 @@ data this way will allow faster boot times and simplify deployment by avoiding the need for direct network access from Terraform to the new server and for remote access credentials to be provided. +### Provisioning files using cloud-config + +Under some circumstances it may be feasible to +[yamlencode](https://www.terraform.io/language/functions/yamlencode) your entire +[cloud-config](https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs) +file. In that case you could use the `write_files` section in place of file +provisioners. For example: + +```hcl +data "cloudinit_config" "my_cloud_config" { + gzip = false + base64_encode = false + + part { + content_type = "text/cloud-config" + filename = "cloud.conf" + content = yamlencode( + { + "write_files" : [ + { + "path" : "/etc/foo.conf", + "content" : "foo contents", + }, + { + "path" : "/etc/bar.conf", + "content" : file("bar.conf"), + }, + { + "path" : "/etc/baz.conf", + "content" : templatefile("baz.tpl.conf", { SOME_VAR = "qux" }), + }, + ], + } + ) + } +} +``` + ### Running configuration management software As a convenience to users who are forced to use generic operating system