Added terraform cloud-init example

This commit is contained in:
Michele Cereda
2023-01-18 01:02:04 +01:00
parent 063f76a435
commit 2a1ff4c556
5 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# https://registry.terraform.io/providers/hashicorp/cloudinit/latest/docs
# https://github.com/chrusty/terraform-multipart-userdata/blob/master/example/cloudinit.tf
data "cloudinit_config" "azurerm_linux_virtual_machine" {
# Disabled only to make the rendered config readable in the outputs.
gzip = false
base64_encode = false
part {
content = file("${path.module}/files/base.yaml")
content_type = "text/cloud-config"
filename = "base"
}
# part {
# content = file("${path.module}/templates/n-th.yaml")
# content_type = "text/cloud-config"
# merge_type = "dict(recurse_array,no_replace)+list(append)"
# filename = "n-th.yaml"
# }
}
data "cloudinit_config" "oci_core_instance" {
# Disabled only to make the rendered config readable in the outputs.
gzip = false
base64_encode = false
part {
content = file("${path.module}/files/base.yaml")
content_type = "text/cloud-config"
filename = "base"
}
part {
content = templatefile(
"${path.module}/templates/boinc-client.oci-core-instance.yaml.tftpl",
{
user = "opc"
}
)
content_type = "text/cloud-config"
merge_type = "dict(recurse_array,no_replace)+list(append)"
filename = "n-th.yaml"
}
}

View File

@@ -0,0 +1,4 @@
#cloud-config
package_reboot_if_required: false
package_upgrade: false

View File

@@ -0,0 +1,12 @@
# resource "azurerm_linux_virtual_machine" "vm" {
# user_data = data.cloudinit_config.azurerm_linux_virtual_machine.rendered
# …
# }
# resource "oci_core_instance" "instance" {
# …
# metadata = {
# …
# user_data = data.cloudinit_config.oci_core_instance.rendered
# }
# }

View File

@@ -0,0 +1,7 @@
output "cloudinit_config_azurerm_linux_virtual_machine" {
value = data.cloudinit_config.azurerm_linux_virtual_machine.rendered
}
output "cloudinit_config_oci_core_instance" {
value = data.cloudinit_config.oci_core_instance.rendered
}

View File

@@ -0,0 +1,6 @@
#cloud-config
packages:
- boinc-client
# Something about user ${user}