2
votes

Trying to create a VM with cloudinit but without any success. Docs on terraform doesnt provide any usefull information how to do it on Azure. Found this post and tried to do the same:
Using cloud-init on an Azure VM to mount a data disk fails
also tried Terraform docs:
https://www.terraform.io/docs/providers/template/d/cloudinit_config.html
Each time I try I receive the following error:
An argument named "cloud_init_template" is not expected here.
or
An argument named "user_data_base64" is not expected here.

Block of code with relevant code:

provider "azurerm" {

    version = "2.2.0"
    features{}

}
#############################
# Cloud config configuration#
#############################
data "template_file" "cloudconfig" {
  template = file("${path.module}/cloud-init.tpl")

  vars  {
   timezone = var.timezone
   password = data.azurerm_key_vault_secret.vaultsecret.value
   tpot_flavor = var.tpot_flavor
   web_user = var.web_user
   web_password = var.web_password
  }
}

data "template_cloudinit_config" "config" {
  gzip          = true
  base64_encode = true

  part {
    content_type = "text/cloud-config"
    content      = data.template_file.cloudconfig.rendered
  }
}

module "azure-vms" {

    source = "./modules/azure-vms"
    tpot_hostname = "${var.name}-Tpot"
    location = azurerm_resource_group.rg.location
    rg-name = azurerm_resource_group.rg.name
    admin_password = data.azurerm_key_vault_secret.vaultsecret.value
     cloud_init_template = data.template_cloudinit_config.config.rendered

}

I've also tried the same with user_data_base64
It's the same error message. I'll appreciate if someone knows what is the right way to deploy a vm with cloudinit on azure.

2
also tried it with the custom_data option , same result - Nimo
So after pocking around a bit more I finally managed to find the solution in the docs. The required option is custom_data. But although everything was deployed, the cloud init didn't perform what it's intended to.... - Nimo
For the error, it means you lack the custom_data = var.cloud_init_template in your VM module. Since you solve it, you can post your answer to close this question. You need request a new thread for new question. - Nancy Xiong
Can you share your cloud-init file to show what you want to provision the VM? Maybe the problem caused by it. - Charles Xu
Do you still work on this problem? I didn't see any updates. If you do not work on this problem anymore, then add the answer to display the solution or just delete it. - Charles Xu

2 Answers

0
votes

The correct way to use cloud config in the VM resource provider is:

cloud_init_template = data.template_cloudinit_config.config.rendered

0
votes

You're not doing the correct way to use cloud config.

cloud_init_template=data.template_cloudinit_config.config.rendered