diff --git a/website/docs/language/resources/provisioners/syntax.mdx b/website/docs/language/resources/provisioners/syntax.mdx index eb1378b953..bdf9e82e64 100644 --- a/website/docs/language/resources/provisioners/syntax.mdx +++ b/website/docs/language/resources/provisioners/syntax.mdx @@ -95,6 +95,42 @@ 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 + +You can add the [`cloudinit_config`](https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs) data source to your Terraform configuration and specify the files you want to provision as `text/cloud-config` content. The `cloudinit_config` data source renders multi-part MIME configurations for use with [cloud-init](https://cloudinit.readthedocs.io/en/latest/). Pass the files in the `content` field as YAML-encoded configurations using the `write_files` block. + +In the following example, the `my_cloud_config` data source specifies a `text/cloud-config` MIME part named `cloud.conf`. The `part.content` field is set to [`yamlencode`](/terraform/language/functions/yamlencode), which encodes the `write_files` JSON object as YAML so that the system can provision the referenced files. + +```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