From f75f6576b747aee2064a5d5ec83d8b6db43bfdc0 Mon Sep 17 00:00:00 2001 From: Phorcys <57866459+phorcys420@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:11:41 +0000 Subject: [PATCH] chore: migrate to `hashicorp/cloud-init` provider --- .../{ => cloud-init}/cloud-config.yaml.tftpl | 0 examples/templates/azure-linux/main.tf | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) rename examples/templates/azure-linux/{ => cloud-init}/cloud-config.yaml.tftpl (100%) diff --git a/examples/templates/azure-linux/cloud-config.yaml.tftpl b/examples/templates/azure-linux/cloud-init/cloud-config.yaml.tftpl similarity index 100% rename from examples/templates/azure-linux/cloud-config.yaml.tftpl rename to examples/templates/azure-linux/cloud-init/cloud-config.yaml.tftpl diff --git a/examples/templates/azure-linux/main.tf b/examples/templates/azure-linux/main.tf index a7282bd76b31f..63f027687b433 100644 --- a/examples/templates/azure-linux/main.tf +++ b/examples/templates/azure-linux/main.tf @@ -6,6 +6,9 @@ terraform { azurerm = { source = "hashicorp/azurerm" } + cloudinit = { + source = "hashicorp/cloudinit" + } } } @@ -167,12 +170,24 @@ module "jetbrains_gateway" { locals { prefix = "coder-${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}" +} + +data "cloudinit_config" "user_data" { + gzip = false + base64_encode = true - userdata = templatefile("cloud-config.yaml.tftpl", { - username = "coder" # Ensure this user/group does not exist in your VM image - init_script = base64encode(coder_agent.main.init_script) - hostname = lower(data.coder_workspace.me.name) - }) + boundary = "//" + + part { + filename = "cloud-config.yaml" + content_type = "text/cloud-config" + + content = templatefile("${path.module}/cloud-init/cloud-config.yaml.tftpl", { + username = "coder" # Ensure this user/group does not exist in your VM image + init_script = base64encode(coder_agent.main.init_script) + hostname = lower(data.coder_workspace.me.name) + }) + } } resource "azurerm_resource_group" "main" { @@ -275,7 +290,7 @@ resource "azurerm_linux_virtual_machine" "main" { sku = "20_04-lts-gen2" version = "latest" } - user_data = base64encode(local.userdata) + user_data = data.cloudinit_config.user_data.rendered tags = { Coder_Provisioned = "true"
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: