Skip to content

Commit f74f1cb

Browse files
authored
Merge pull request #65 from cezarsa/tags
Add back support for tags in resources
2 parents 2782cca + 34d541d commit f74f1cb

14 files changed

+105
-104
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ $ make test
5656
In order to run the full suite of Acceptance tests you will need to run the CloudStack Simulator. Please follow these steps to prepare an environment for running the Acceptance tests:
5757

5858
```sh
59-
$ docker pull svanharmelen/simulator:4.11.2.0
60-
$ docker run -d -p 8080:8080 --name cloudstack svanharmelen/simulator:4.11.2.0
59+
$ docker pull svanharmelen/simulator:4.12.0.0
60+
$ docker run -d -p 8080:8080 --name cloudstack svanharmelen/simulator:4.12.0.0
6161
```
6262

6363
When Docker started the container you can go to http://localhost:8080/client and login to the CloudStack UI as user `admin` with password `password`. It can take a few minutes for the container is fully ready, so you probably need to wait and refresh the page for a few minutes before the login page is shown.

cloudstack/data_source_cloudstack_template.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func dataSourceCloudstackTemplate() *schema.Resource {
6363
Computed: true,
6464
},
6565

66-
// "tags": tagsSchema(),
66+
"tags": tagsSchema(),
6767
},
6868
}
6969
}
@@ -118,11 +118,11 @@ func templateDescriptionAttributes(d *schema.ResourceData, template *cloudstack.
118118
d.Set("name", template.Name)
119119
d.Set("size", template.Size)
120120

121-
// tags := make(map[string]interface{})
122-
// for _, tag := range template.Tags {
123-
// tags[tag.Key] = tag.Value
124-
// }
125-
// d.Set("tags", tags)
121+
tags := make(map[string]interface{})
122+
for _, tag := range template.Tags {
123+
tags[tag.Key] = tag.Value
124+
}
125+
d.Set("tags", tags)
126126

127127
return nil
128128
}

cloudstack/resource_cloudstack_disk.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func resourceCloudStackDisk() *schema.Resource {
7272
ForceNew: true,
7373
},
7474

75-
// "tags": tagsSchema(),
75+
"tags": tagsSchema(),
7676
},
7777
}
7878
}
@@ -131,11 +131,11 @@ func resourceCloudStackDiskCreate(d *schema.ResourceData, meta interface{}) erro
131131
d.SetId(r.Id)
132132

133133
// Set tags if necessary
134-
// err = setTags(cs, d, "Volume")
135-
// if err != nil {
136-
// return fmt.Errorf("Error setting tags on the new disk %s: %s", name, err)
137-
// }
138-
// d.SetPartial("tags")
134+
err = setTags(cs, d, "Volume")
135+
if err != nil {
136+
return fmt.Errorf("Error setting tags on the new disk %s: %s", name, err)
137+
}
138+
d.SetPartial("tags")
139139

140140
if d.Get("attach").(bool) {
141141
if err := resourceCloudStackDiskAttach(d, meta); err != nil {
@@ -171,11 +171,11 @@ func resourceCloudStackDiskRead(d *schema.ResourceData, meta interface{}) error
171171
d.Set("attach", v.Virtualmachineid != "") // If attached this contains a virtual machine ID
172172
d.Set("size", int(v.Size/(1024*1024*1024))) // Needed to get GB's again
173173

174-
// tags := make(map[string]interface{})
175-
// for _, tag := range v.Tags {
176-
// tags[tag.Key] = tag.Value
177-
// }
178-
// d.Set("tags", tags)
174+
tags := make(map[string]interface{})
175+
for _, tag := range v.Tags {
176+
tags[tag.Key] = tag.Value
177+
}
178+
d.Set("tags", tags)
179179

180180
setValueOrID(d, "disk_offering", v.Diskofferingname, v.Diskofferingid)
181181
setValueOrID(d, "project", v.Project, v.Projectid)
@@ -261,13 +261,13 @@ func resourceCloudStackDiskUpdate(d *schema.ResourceData, meta interface{}) erro
261261
}
262262

263263
// Check is the tags have changed and if so, update the tags
264-
// if d.HasChange("tags") {
265-
// err := updateTags(cs, d, "Volume")
266-
// if err != nil {
267-
// return fmt.Errorf("Error updating tags on disk %s: %s", name, err)
268-
// }
269-
// d.SetPartial("tags")
270-
// }
264+
if d.HasChange("tags") {
265+
err := updateTags(cs, d, "Volume")
266+
if err != nil {
267+
return fmt.Errorf("Error updating tags on disk %s: %s", name, err)
268+
}
269+
d.SetPartial("tags")
270+
}
271271

272272
d.Partial(false)
273273

cloudstack/resource_cloudstack_disk_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestAccCloudStackDisk_basic(t *testing.T) {
2323
testAccCheckCloudStackDiskExists(
2424
"cloudstack_disk.foo", &disk),
2525
testAccCheckCloudStackDiskAttributes(&disk),
26-
// testAccCheckResourceTags(&disk),
26+
testAccCheckResourceTags(&disk),
2727
),
2828
},
2929
},
@@ -187,9 +187,9 @@ resource "cloudstack_disk" "foo" {
187187
attach = false
188188
disk_offering = "Small"
189189
zone = "Sandbox-simulator"
190-
#tags = {
191-
# terraform-tag = "true"
192-
#}
190+
tags = {
191+
terraform-tag = "true"
192+
}
193193
}`
194194

195195
const testAccCloudStackDisk_update = `

cloudstack/resource_cloudstack_instance.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func resourceCloudStackInstance() *schema.Resource {
152152
Default: false,
153153
},
154154

155-
// "tags": tagsSchema(),
155+
"tags": tagsSchema(),
156156
},
157157
}
158158
}
@@ -284,9 +284,9 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
284284
d.SetId(r.Id)
285285

286286
// Set tags if necessary
287-
// if err = setTags(cs, d, "userVm"); err != nil {
288-
// return fmt.Errorf("Error setting tags on the new instance %s: %s", name, err)
289-
// }
287+
if err = setTags(cs, d, "userVm"); err != nil {
288+
return fmt.Errorf("Error setting tags on the new instance %s: %s", name, err)
289+
}
290290

291291
// Set the connection info for any configured provisioners
292292
d.SetConnInfo(map[string]string{
@@ -377,11 +377,11 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
377377
d.Set("security_group_names", groups)
378378
}
379379

380-
// tags := make(map[string]interface{})
381-
// for _, tag := range vm.Tags {
382-
// tags[tag.Key] = tag.Value
383-
// }
384-
// d.Set("tags", tags)
380+
tags := make(map[string]interface{})
381+
for _, tag := range vm.Tags {
382+
tags[tag.Key] = tag.Value
383+
}
384+
d.Set("tags", tags)
385385

386386
setValueOrID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
387387
setValueOrID(d, "template", vm.Templatename, vm.Templateid)
@@ -580,12 +580,12 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
580580
}
581581

582582
// Check is the tags have changed and if so, update the tags
583-
// if d.HasChange("tags") {
584-
// if err := updateTags(cs, d, "UserVm"); err != nil {
585-
// return fmt.Errorf("Error updating tags on instance %s: %s", name, err)
586-
// }
587-
// d.SetPartial("tags")
588-
// }
583+
if d.HasChange("tags") {
584+
if err := updateTags(cs, d, "UserVm"); err != nil {
585+
return fmt.Errorf("Error updating tags on instance %s: %s", name, err)
586+
}
587+
d.SetPartial("tags")
588+
}
589589

590590
d.Partial(false)
591591

cloudstack/resource_cloudstack_instance_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestAccCloudStackInstance_basic(t *testing.T) {
2525
testAccCheckCloudStackInstanceAttributes(&instance),
2626
resource.TestCheckResourceAttr(
2727
"cloudstack_instance.foobar", "user_data", "0cf3dcdc356ec8369494cb3991985ecd5296cdd5"),
28-
// testAccCheckResourceTags(&instance),
28+
testAccCheckResourceTags(&instance),
2929
),
3030
},
3131
},
@@ -307,9 +307,9 @@ resource "cloudstack_instance" "foobar" {
307307
zone = "Sandbox-simulator"
308308
user_data = "foobar\nfoo\nbar"
309309
expunge = true
310-
#tags = {
311-
# terraform-tag = "true"
312-
#}
310+
tags = {
311+
terraform-tag = "true"
312+
}
313313
}`
314314

315315
const testAccCloudStackInstance_stopped = `

cloudstack/resource_cloudstack_ipaddress.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func resourceCloudStackIPAddress() *schema.Resource {
5353
Computed: true,
5454
},
5555

56-
// "tags": tagsSchema(),
56+
"tags": tagsSchema(),
5757
},
5858
}
5959
}
@@ -107,10 +107,10 @@ func resourceCloudStackIPAddressCreate(d *schema.ResourceData, meta interface{})
107107
d.SetId(r.Id)
108108

109109
// Set tags if necessary
110-
// err = setTags(cs, d, "PublicIpAddress")
111-
// if err != nil {
112-
// return fmt.Errorf("Error setting tags on the IP address: %s", err)
113-
// }
110+
err = setTags(cs, d, "PublicIpAddress")
111+
if err != nil {
112+
return fmt.Errorf("Error setting tags on the IP address: %s", err)
113+
}
114114

115115
return resourceCloudStackIPAddressRead(d, meta)
116116
}
@@ -151,11 +151,11 @@ func resourceCloudStackIPAddressRead(d *schema.ResourceData, meta interface{}) e
151151
setValueOrID(d, "zone", ip.Zonename, ip.Zoneid)
152152
}
153153

154-
// tags := make(map[string]interface{})
155-
// for _, tag := range ip.Tags {
156-
// tags[tag.Key] = tag.Value
157-
// }
158-
// d.Set("tags", tags)
154+
tags := make(map[string]interface{})
155+
for _, tag := range ip.Tags {
156+
tags[tag.Key] = tag.Value
157+
}
158+
d.Set("tags", tags)
159159

160160
setValueOrID(d, "project", ip.Project, ip.Projectid)
161161

cloudstack/resource_cloudstack_ipaddress_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestAccCloudStackIPAddress_basic(t *testing.T) {
2222
Check: resource.ComposeTestCheckFunc(
2323
testAccCheckCloudStackIPAddressExists(
2424
"cloudstack_ipaddress.foo", &ipaddr),
25-
// testAccCheckResourceTags(&ipaddr),
25+
testAccCheckResourceTags(&ipaddr),
2626
),
2727
},
2828
},
@@ -109,9 +109,9 @@ resource "cloudstack_network" "foo" {
109109
110110
resource "cloudstack_ipaddress" "foo" {
111111
network_id = "${cloudstack_network.foo.id}"
112-
#tags = {
113-
# terraform-tag = "true"
114-
#}
112+
tags = {
113+
terraform-tag = "true"
114+
}
115115
}`
116116

117117
const testAccCloudStackIPAddress_vpc = `

cloudstack/resource_cloudstack_network.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func resourceCloudStackNetwork() *schema.Resource {
129129
ForceNew: true,
130130
},
131131

132-
// "tags": tagsSchema(),
132+
"tags": tagsSchema(),
133133
},
134134
}
135135
}
@@ -235,10 +235,10 @@ func resourceCloudStackNetworkCreate(d *schema.ResourceData, meta interface{}) e
235235
d.SetId(r.Id)
236236

237237
// Set tags if necessary
238-
// if err = setTags(cs, d, "network"); err != nil {
239-
// return fmt.Errorf("Error setting tags: %v", err)
240-
// }
241-
// d.SetPartial("tags")
238+
if err = setTags(cs, d, "network"); err != nil {
239+
return fmt.Errorf("Error setting tags: %v", err)
240+
}
241+
d.SetPartial("tags")
242242

243243
if d.Get("source_nat_ip").(bool) {
244244
// Create a new parameter struct
@@ -305,11 +305,11 @@ func resourceCloudStackNetworkRead(d *schema.ResourceData, meta interface{}) err
305305
}
306306
d.Set("acl_id", n.Aclid)
307307

308-
// tags := make(map[string]interface{})
309-
// for _, tag := range n.Tags {
310-
// tags[tag.Key] = tag.Value
311-
// }
312-
// d.Set("tags", tags)
308+
tags := make(map[string]interface{})
309+
for _, tag := range n.Tags {
310+
tags[tag.Key] = tag.Value
311+
}
312+
d.Set("tags", tags)
313313

314314
setValueOrID(d, "network_offering", n.Networkofferingname, n.Networkofferingid)
315315
setValueOrID(d, "project", n.Project, n.Projectid)
@@ -400,11 +400,11 @@ func resourceCloudStackNetworkUpdate(d *schema.ResourceData, meta interface{}) e
400400
}
401401

402402
// Update tags if they have changed
403-
// if d.HasChange("tags") {
404-
// if err := updateTags(cs, d, "Network"); err != nil {
405-
// return fmt.Errorf("Error updating tags on ACL %s: %s", name, err)
406-
// }
407-
// }
403+
if d.HasChange("tags") {
404+
if err := updateTags(cs, d, "Network"); err != nil {
405+
return fmt.Errorf("Error updating tags on ACL %s: %s", name, err)
406+
}
407+
}
408408

409409
return resourceCloudStackNetworkRead(d, meta)
410410
}

cloudstack/resource_cloudstack_network_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestAccCloudStackNetwork_basic(t *testing.T) {
2323
testAccCheckCloudStackNetworkExists(
2424
"cloudstack_network.foo", &network),
2525
testAccCheckCloudStackNetworkBasicAttributes(&network),
26-
// testAccCheckResourceTags(&network),
26+
testAccCheckResourceTags(&network),
2727
),
2828
},
2929
},
@@ -245,9 +245,9 @@ resource "cloudstack_network" "foo" {
245245
cidr = "10.1.1.0/24"
246246
network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
247247
zone = "Sandbox-simulator"
248-
#tags = {
249-
# terraform-tag = "true"
250-
#}
248+
tags = {
249+
terraform-tag = "true"
250+
}
251251
}`
252252

253253
const testAccCloudStackNetwork_project = `

0 commit comments

Comments
 (0)