Search code examples
azure-storageterraform-provider-azure

Call to function "format" failed: not enough arguments for "%02d" at 0: need index 1 but have 0 total


I am creating a terraform config, basically a cluster of VM's or even single VM depending on roles. Having an issue when creating a storage account.

Terraform config for storage account creation is as below:

 # Storage Account
    resource "azurerm_storage_account" "tf-sa-grpprd-aos" {
    #  count                    = "${var.count_aos_vm}"
      name                     = "${lower(var.aos_base_hostname)}${format("%02d,2")}${var.storage_account_suffix}01"
      location                 = "${azurerm_resource_group.tf-rg-grpprd-application.location}"
      resource_group_name      = "${azurerm_resource_group.tf-rg-grpprd-application.name}"
      account_tier             = "${var.sto_acc_tier_std}"
      account_replication_type = "${var.sto_acc_rep_type_lrs}"

    }

Error reported is in Title, but it is as below

Error in function call
on aos.tf line 106, in resource "azurerm_storage_account" "tf-sa-grpprd-aos":
name                     = "${lower(var.aos_base_hostname)}${format("%02d,2")}${var.storage_account_suffix}01"
Call to function "format" failed: not enough arguments for "%02d" at 0: need
index 1 but have 0 total.

I refer to the terraform documentation as per below https://www.terraform.io/docs/configuration/functions/format.html

Probably I am not utilizing it the incorrect way? Appreciate if anyone can clarify what blunder I am doing...

Essentially, If I have 5 production app boxes then it should have only one storage account as below grpprodapp01..05 but will have storage account as one grpprodapp01

OR

Even if I have one VM then also it should have only one storage account, so the no of VM's does not matter, it should only one storage account.


Solution

  • Maybe it's a little mistake you make. As the error shows, the function "format" should have one argument, but you give nothing. So if you just want to format the integer number 2 into 02, then you should make the change like below:

    name = "${lower(var.aos_base_hostname)}${format("%02d", 2)}${var.storage_account_suffix}01"
    

    It just corrects your wrong format. But as the description shows, you want the storage accounts name like grpprodapp01..05 with the count. And if the value of the variable var.aos_base_hostname is grpprodapp, then it should be like this:

    name = "${lower(var.aos_base_hostname)}${format("%02d", count.index)}"
    

    If you need any more helps, please let me know.