From c5e2eff847f11df6ef8e25591dbd1214a21d6b74 Mon Sep 17 00:00:00 2001 From: Feiyu Shi Date: Sun, 24 May 2020 11:21:45 -0700 Subject: [PATCH] change to []*Resource --- builder/azure/common/template/template.go | 2 +- .../azure/common/template/template_builder.go | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/builder/azure/common/template/template.go b/builder/azure/common/template/template.go index bb430fbb4..7cea53337 100644 --- a/builder/azure/common/template/template.go +++ b/builder/azure/common/template/template.go @@ -12,7 +12,7 @@ type Template struct { ContentVersion *string `json:"contentVersion"` Parameters *map[string]Parameters `json:"parameters"` Variables *map[string]string `json:"variables"` - Resources *[]Resource `json:"resources"` + Resources []*Resource `json:"resources"` } ///////////////////////////////////////////////// diff --git a/builder/azure/common/template/template_builder.go b/builder/azure/common/template/template_builder.go index 60d1e5667..5745d6c3d 100644 --- a/builder/azure/common/template/template_builder.go +++ b/builder/azure/common/template/template_builder.go @@ -228,9 +228,9 @@ func (s *TemplateBuilder) SetPlanInfo(name, product, publisher, promotionCode st promotionCodeVal = to.StringPtr(promotionCode) } - for i, x := range *s.template.Resources { + for i, x := range s.template.Resources { if strings.EqualFold(*x.Type, resourceVirtualMachine) { - (*s.template.Resources)[i].Plan = &Plan{ + s.template.Resources[i].Plan = &Plan{ Name: to.StringPtr(name), Product: to.StringPtr(product), Publisher: to.StringPtr(publisher), @@ -374,8 +374,8 @@ func (s *TemplateBuilder) SetTags(tags *map[string]*string) error { return nil } - for i := range *s.template.Resources { - (*s.template.Resources)[i].Tags = tags + for i := range s.template.Resources { + s.template.Resources[i].Tags = tags } return nil } @@ -406,9 +406,9 @@ func (s *TemplateBuilder) ToJSON() (*string, error) { } func (s *TemplateBuilder) getResourceByType(t string) (*Resource, error) { - for _, x := range *s.template.Resources { + for _, x := range s.template.Resources { if strings.EqualFold(*x.Type, t) { - return &x, nil + return x, nil } } @@ -428,28 +428,28 @@ func (s *TemplateBuilder) toVariable(name string) string { } func (s *TemplateBuilder) addResource(newResource *Resource) error { - for _, resource := range *s.template.Resources { + for _, resource := range s.template.Resources { if *resource.Type == *newResource.Type { return fmt.Errorf("template: found an existing resource of type %s", *resource.Type) } } - resources := append(*s.template.Resources, *newResource) - s.template.Resources = &resources + resources := append(s.template.Resources, newResource) + s.template.Resources = resources return nil } func (s *TemplateBuilder) deleteResourceByType(resourceType string) { - resources := make([]Resource, 0) + resources := make([]*Resource, 0) - for _, resource := range *s.template.Resources { + for _, resource := range s.template.Resources { if *resource.Type == resourceType { continue } resources = append(resources, resource) } - s.template.Resources = &resources + s.template.Resources = resources } func (s *TemplateBuilder) addResourceDependency(resource *Resource, dep string) {