I got it working by changing to:

*dynamic "storage" { *
* for_each = var.storage *
* content { *
* disk_size = storage.value *
*disk_thin_provisioned = true }*
*}*

On Thursday, September 10, 2020 at 6:07:10 PM UTC-5 Manish Garedia wrote:

> Thanks for replying!
>
> I change the variable as you suggested and remove the quotes but now 
> getting this error about disk_size.
>
> variable “storage” {
>    type=list(string)
>  }
>
>
> ✗ packer build  -var ks-file='"ks-2disk.cf"' -var storage='["51200", 
> "25600"]'  .
> Error: 1 error(s) occurred:
>
> ** storage[0].'disk_size' is required*
>
>   on centos.pkr.hcl line 1:
>   (source code not available)
>
> ==> Wait completed after 4 microseconds
>
> ==> Builds finished but no artifacts were created.
>
>
> On Thu, Sep 10, 2020 at 5:52 PM Wilken Rivera <[email protected]> 
> wrote:
>
>> Hi Manish
>>
>> I believe the double quotes around the list may be the issue here.
>>
>> Have you tried removing the quotes?
>>
>> When specifying the list var on the cli you will need to drop the 
>> additional quotes so that it is read in as a list. 
>>
>> -var 'storage=[”51200”,”25600”]’
>>
>>
>> Also for string list types you should specify the type as `list(string)` 
>> as opposed to using a default=[].
>>
>> variable “storage” {
>>    type=list(string)
>>  }
>>
>> Let me know if that helps. 
>>
>>
>> On Sep 10, 2020, at 18:15, Manish Garedia <[email protected]> wrote:
>>
>> Here's what I am trying to achieve it.
>>
>> *dynamic "storage" { *
>> * for_each = var.storage *
>> * content { *
>> * disk_size = storage.key disk_thin_provisioned = true }*
>> *}*
>>
>> and storage is defined as list variable in variables.pkr.hcl
>> *variable "storage" { default = [] }*
>>
>> Running Packer like this:
>> packer build -var ks-file='"ks-2disk.cf"' -var 
>> storage='"["51200","25600"]"' .
>>
>> Getting this error at this time: Error: Extra characters after expression
>>
>> on line 1: (source code not available)
>>
>> An expression was successfully parsed, but extra characters were found 
>> after it.
>>
>> On Wednesday, September 9, 2020 at 1:23:52 PM UTC-5 Manish Garedia wrote:
>>
>>> Thanks for the reply!
>>>
>>> I have converted now everything to hcl2 templates. Can you please 
>>> suggest what's the best way to pass storage as a MAP based on if there is 
>>> going to a single disk or two disk?
>>>
>>> source "vsphere-iso" "centos" {
>>>   CPUs = var.vm-cpu-num
>>>   RAM = var.vm-mem-size
>>>   RAM_reserve_all = false
>>>   boot_command = [
>>>     "<tab> inst.text inst.ks=hd:fd0:/${ var.ks-file } <enter><wait>"
>>>   ]
>>>   boot_order = "disk,cdrom,floppy"
>>>   boot_wait = "10s"
>>>   cluster = var.vsphere-cluster
>>>   communicator = "ssh"
>>>   convert_to_template = true
>>>   datastore = var.vsphere-datastore
>>>   disk_controller_type = ["pvscsi"]
>>>   floppy_files = [
>>>     var.ks-file
>>>   ]
>>>   guest_os_type = "centos7_64Guest"
>>>   host = var.vsphere-host
>>>   insecure_connection = "true"
>>>   iso_paths = [
>>>     var.iso_url
>>>   ]
>>>   network_adapters {
>>>       network = var.vsphere-network
>>>       network_card = "vmxnet3"
>>>     }
>>>   notes = "Build via Packer"
>>>   password = var.vsphere-password
>>>   ssh_password = var.ssh_password
>>>   ssh_username = "root"
>>> *  storage {*
>>> *      disk_size = var.vm-disk-size*
>>> *      disk_thin_provisioned = true*
>>> *    }*
>>> *    storage {*
>>> *        disk_size = var.vm-disk-size2*
>>> *        disk_thin_provisioned = true*
>>> *      }*
>>> *..*
>>> build {
>>>   sources = [
>>>     "source.vsphere-iso.centos"
>>>   ]
>>> }
>>>
>>>
>>>
>>> On Wednesday, September 2, 2020 at 12:47:40 PM UTC-5 Megan Marsh wrote:
>>>
>>>> var-files only support string variables, not maps. If you want to use 
>>>> map variables, consider upgrading to hcl2 templates. 
>>>>
>>>> On Tue, Sep 1, 2020 at 11:17 AM Manish Garedia <[email protected]> 
>>>> wrote:
>>>>
>>>>> Had to wrong json posted. here's the right one.
>>>>>
>>>>>       "storage": [
>>>>>         {
>>>>>           "disk_size": "{{user `vm-disk-size`}}",
>>>>>           "disk_thin_provisioned": true
>>>>>         },
>>>>>        {
>>>>>           "disk_size": "{{user `vm-disk-size`}}",
>>>>>           "disk_thin_provisioned": true
>>>>>         }
>>>>>       ],
>>>>>
>>>>> On Tuesday, September 1, 2020 at 1:15:21 PM UTC-5 Manish Garedia wrote:
>>>>>
>>>>>> Is there any way of using map in var-file:
>>>>>>
>>>>>> I have something like this in packer.json
>>>>>>
>>>>>>       "storage": [
>>>>>>         {
>>>>>>           "disk_size": "{{user `vm-disk-size`}}",
>>>>>>           "disk_thin_provisioned": true
>>>>>>         }
>>>>>>       ],
>>>>>>       "storage": [
>>>>>>         {
>>>>>>           "disk_size": "{{user `vm-disk-size`}}",
>>>>>>           "disk_thin_provisioned": true
>>>>>>         }
>>>>>>       ],
>>>>>>
>>>>>> what's the best way to have this in var-file. FYI, I have tried to 
>>>>>> flatten the json but doesn't work.
>>>>>>
>>>>> -- 
>>>>> This mailing list is governed under the HashiCorp Community Guidelines 
>>>>> - https://www.hashicorp.com/community-guidelines.html. Behavior in 
>>>>> violation of those guidelines may result in your removal from this 
>>>>> mailing 
>>>>> list.
>>>>>  
>>>>> GitHub Issues: https://github.com/hashicorp/packer/issues
>>>>> IRC: #packer-tool on Freenode
>>>>> --- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Packer" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected].
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/packer-tool/960198f1-4c34-4872-836e-70a9909457e0n%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/packer-tool/960198f1-4c34-4872-836e-70a9909457e0n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> -- 
>> This mailing list is governed under the HashiCorp Community Guidelines - 
>> https://www.hashicorp.com/community-guidelines.html. Behavior in 
>> violation of those guidelines may result in your removal from this mailing 
>> list.
>>  
>> GitHub Issues: https://github.com/hashicorp/packer/issues
>> IRC: #packer-tool on Freenode
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Packer" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/packer-tool/0e61754e-d14c-4984-a259-072bacfbe392n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/packer-tool/0e61754e-d14c-4984-a259-072bacfbe392n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> -- 
>> This mailing list is governed under the HashiCorp Community Guidelines - 
>> https://www.hashicorp.com/community-guidelines.html. Behavior in 
>> violation of those guidelines may result in your removal from this mailing 
>> list.
>>  
>> GitHub Issues: https://github.com/hashicorp/packer/issues
>> IRC: #packer-tool on Freenode
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Packer" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/packer-tool/4AF32427-84DF-4D79-A14E-0B2F983A6B3C%40wilkenrivera.com
>>  
>> <https://groups.google.com/d/msgid/packer-tool/4AF32427-84DF-4D79-A14E-0B2F983A6B3C%40wilkenrivera.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/hashicorp/packer/issues
IRC: #packer-tool on Freenode
--- 
You received this message because you are subscribed to the Google Groups 
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/packer-tool/7ce71587-831a-4f5f-9d57-6e674ab1bd5cn%40googlegroups.com.

Reply via email to