3

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.

Nimo
  • 53
  • 2
  • 5
  • also tried it with the **custom_data option** , same result – Nimo Apr 13 '20 at 18:14
  • 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 Apr 13 '20 at 19:27
  • 1
    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 Apr 14 '20 at 01:59
  • 1
    Can you share your cloud-init file to show what you want to provision the VM? Maybe the problem caused by it. – Charles Xu Apr 14 '20 at 03:08
  • 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 Apr 16 '20 at 07:43
  • So after playing around with it, I can confirm that after configuring the cloud init properties as shown above, just use the custom_data: `cloud_init_template = data.template_cloudinit_config.config.rendered` it the VM resource provider. It will run the cloud init on the vm. Also, I'ts important to verify that the deployed distribution does support cloud-init on the Azure platform. – Nimo Apr 16 '20 at 11:25

2 Answers2

0

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

cloud_init_template = data.template_cloudinit_config.config.rendered

Nimo
  • 53
  • 2
  • 5
0

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

cloud_init_template=data.template_cloudinit_config.config.rendered
MERLIN
  • 61
  • 1
  • 13