Skip to content

Commit 3c3f2ff

Browse files
chore: add tagsToMap function
1 parent e5af399 commit 3c3f2ff

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

cloudstack/data_source_cloudstack_instance.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,7 @@ func instanceDescriptionAttributes(d *schema.ResourceData, instance *cloudstack.
155155
d.Set("zone_id", instance.Zoneid)
156156
d.Set("nic", []interface{}{map[string]string{"ip_address": instance.Nic[0].Ipaddress}})
157157

158-
tags := make(map[string]interface{})
159-
for _, tag := range instance.Tags {
160-
tags[tag.Key] = tag.Value
161-
}
162-
d.Set("tags", tags)
158+
d.Set("tags", tagsToMap(instance.Tags))
163159

164160
return nil
165161
}

cloudstack/data_source_cloudstack_ipaddress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func ipAddressDescriptionAttributes(d *schema.ResourceData, publicIpAddress *clo
124124
d.Set("project", publicIpAddress.Project)
125125
d.Set("ip_address", publicIpAddress.Ipaddress)
126126
d.Set("is_source_nat", publicIpAddress.Issourcenat)
127-
d.Set("tags", publicIpAddress.Tags)
127+
d.Set("tags", tagsToMap(publicIpAddress.Tags))
128128

129129
return nil
130130
}

cloudstack/data_source_cloudstack_vpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func vpcDescriptionAttributes(d *schema.ResourceData, vpc *cloudstack.VPC) error
123123
d.Set("network_domain", vpc.Networkdomain)
124124
d.Set("project", vpc.Project)
125125
d.Set("zone_name", vpc.Zonename)
126-
d.Set("tags", vpc.Tags)
126+
d.Set("tags", tagsToMap(vpc.Tags))
127127

128128
return nil
129129
}

cloudstack/resource_cloudstack_instance.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,7 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
482482
d.Set("security_group_names", groups)
483483
}
484484

485-
tags := make(map[string]interface{})
486-
for _, tag := range vm.Tags {
487-
tags[tag.Key] = tag.Value
488-
}
489-
d.Set("tags", tags)
485+
d.Set("tags", tagsToMap(vm.Tags))
490486

491487
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
492488
setValueOrID(d, "template", vm.Templatename, vm.Templateid)

cloudstack/tags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,11 @@ func tagsFromSchema(m map[string]interface{}) map[string]string {
111111
}
112112
return result
113113
}
114+
115+
func tagsToMap(tags []cloudstack.Tags) map[string]string {
116+
result := make(map[string]string, len(tags))
117+
for _, tag := range tags {
118+
result[tag.Key] = tag.Value
119+
}
120+
return result
121+
}

0 commit comments

Comments
 (0)