mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #31995 from sed-i/yamlencode-cloudconfig
This commit is contained in:
commit
8b210951d9
@ -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
|
the need for direct network access from Terraform to the new server and for
|
||||||
remote access credentials to be provided.
|
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
|
### Running configuration management software
|
||||||
|
|
||||||
As a convenience to users who are forced to use generic operating system
|
As a convenience to users who are forced to use generic operating system
|
||||||
|
Loading…
Reference in New Issue
Block a user