From 1bf34282635bd3cf1b3683283cf941fe04afff62 Mon Sep 17 00:00:00 2001 From: Aleksey Hariton Date: Thu, 18 Apr 2019 17:44:33 +0300 Subject: [PATCH 1/2] Add tags to instance --- builder/cloudstack/config.go | 2 ++ builder/cloudstack/step_create_instance.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/builder/cloudstack/config.go b/builder/cloudstack/config.go index f74a89502..00f79618b 100644 --- a/builder/cloudstack/config.go +++ b/builder/cloudstack/config.go @@ -59,6 +59,8 @@ type Config struct { TemplateScalable bool `mapstructure:"template_scalable"` TemplateTag string `mapstructure:"template_tag"` + Tags map[string]string `mapstructure:"tags"` + ctx interpolate.Context } diff --git a/builder/cloudstack/step_create_instance.go b/builder/cloudstack/step_create_instance.go index d20b19f56..73aaa2133 100644 --- a/builder/cloudstack/step_create_instance.go +++ b/builder/cloudstack/step_create_instance.go @@ -149,6 +149,20 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) // Store the instance ID so we can remove it later. state.Put("instance_id", instance.Id) + // Set instance tags + if config.Tags != nil { + resourceID := []string{instance.Id} + tp := client.Resourcetags.NewCreateTagsParams(resourceID, "UserVm", config.Tags) + + _, err = client.Resourcetags.CreateTags(tp) + + if err != nil { + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + } + return multistep.ActionContinue } From d9960fdaebfb064ca7789821af49ddeed14d3da5 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 3 Jun 2019 15:13:49 -0700 Subject: [PATCH 2/2] use length instead of a nil test. --- builder/cloudstack/step_create_instance.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/cloudstack/step_create_instance.go b/builder/cloudstack/step_create_instance.go index 73aaa2133..890edd3a1 100644 --- a/builder/cloudstack/step_create_instance.go +++ b/builder/cloudstack/step_create_instance.go @@ -150,7 +150,7 @@ func (s *stepCreateInstance) Run(ctx context.Context, state multistep.StateBag) state.Put("instance_id", instance.Id) // Set instance tags - if config.Tags != nil { + if len(config.Tags) > 0 { resourceID := []string{instance.Id} tp := client.Resourcetags.NewCreateTagsParams(resourceID, "UserVm", config.Tags)