Passing Tags & Run_tags Blocks in var-file : Is This Possible?

26 views
Skip to first unread message

Jimster

unread,
Oct 16, 2019, 4:31:24 AM10/16/19
to Packer
Hi,

Been tasked with cleaning up packer code to remove duplication of explicit values in our working  build .json files - and use a few general var-files that will contain the relevant DEV, TEST and PROD instance types, vpc details, disk sizes etc.

One of the builders sections we use are tags (and run_tags) of the format:

"run_tags": {
           "Environment":      "DEV",
           "Application":      "Dave",
           "Tier":             "Web App",
           "Function":         "Dev Dave Web App",
           "Version":          "1.0",
           "CostCentre":       "0300 3246",
           "BusinessUnit":     "AppServices",
           "Project":          "DaveMigration to AWS",
           "Product":          "IIS Server for Dave",
           "SupportEmail":     "Da...@dave.com",
           "ComplianceDomain": "YES",
           "DataClass":        "5",
           "ProvisionedBy":    "Packer",
           "ProvisionedWho":   "Da...@dave.com",
           "ProjectName":      "Dave",
           "Name":             "Dave Dev Web Box"
       },

I'm not sure if or how I can include these arrays in a var-file.  Ideally the build file wants to refer to these as some kind of user variable e.g. in line with the usual ones:
    "builders": [{
       "type":             "amazon-ebs",

        "region":           "{{ user `DEV_server_region`}}",
       "source_ami":       "{{ user `DEV_server_source_ami`}}",
       "tags":             "{{ user `DEV_dave_tags`}}",  <== WHATEVER FORMAT THIS SHOULD BE IN FOR A TAG BLOCK (Array?)
       "instance_type":    "{{ user `DEV_server_instance_type`}}",
       "winrm_use_ssl":    true,
       "winrm_insecure":   true
   }],

I've tried to capture these tag arrays in the var-file as so (snippet):
...

"PROD_server_user_data_file":       "./USERDATA2.0.txt",

    "CA_server_run_tags": [{
           "Environment":      "DEV",
           "Application":      "Dave",
           "Tier":             "Web App",
           "Function":         "Dev Dave Web App",
           "Version":          "1.0",
           "CostCentre":       "0300 3246",
           "BusinessUnit":     "AppServices",
           "Project":          "DaveMigration to AWS",
           "Product":          "IIS Server for Dave",
           "SupportEmail":     "Da...@dave.com",
           "ComplianceDomain": "YES",
           "DataClass":        "5",
           "ProvisionedBy":    "Packer",
           "ProvisionedWho":   "Da...@dave.com",
           "ProjectName":      "Dave",
           "Name":             "Dave Dev Web Box"
    }]


But I get:
packer validate -var-file .\dave_vars.json .\build_var_test_Dave.json
invalid value ".\\dave_vars.json" for flag -var-file: Error reading variables in '.\dave_vars.json': json: cannot unmarshal array into Go value of type string

Can someone please advise on how best to include (if possible) these tags and run_tags arrays into the var-file and refer to the resulting user array variable properly in the builder file?

Thanks,
Jimster

Rickard von Essen

unread,
Oct 16, 2019, 5:14:06 AM10/16/19
to packe...@googlegroups.com
No, currently this is not supported. Only single values and arrays 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/mitchellh/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 packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/8975abcb-e431-4005-8e76-b40f6b048e8f%40googlegroups.com.

Jimster

unread,
Oct 16, 2019, 5:38:14 AM10/16/19
to Packer
Rickard,

Appreciate the prompt reply.

With that in mind, I'll probably use Powershell scripting or AWS CLI in the Providers section to set the tags, using a specific tag file to read from , for the relevant build.

Jim
Reply all
Reply to author
Forward
0 new messages