Skip to content

Commit 6cd4b2b

Browse files
committed
fix zone_id and tags
1 parent 1e9464d commit 6cd4b2b

3 files changed

+67
-17
lines changed

cloudstack/resource_cloudstack_disk_offering.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package cloudstack
2121

2222
import (
23+
"fmt"
2324
"strconv"
2425

2526
"github.com/apache/cloudstack-go/v2/cloudstack"
@@ -97,7 +98,6 @@ func resourceCloudStackDiskOffering() *schema.Resource {
9798
"tags": {
9899
Type: schema.TypeString,
99100
Optional: true,
100-
ForceNew: true,
101101
},
102102
"zone_id": {
103103
Type: schema.TypeList,
@@ -386,7 +386,7 @@ func resourceCloudStackDiskOfferingUpdate(d *schema.ResourceData, meta interface
386386
p.SetTags(v.(string))
387387
}
388388
if v, ok := d.GetOk("zone_id"); ok {
389-
p.SetZoneid(v.(string))
389+
p.SetZoneid(fmt.Sprintf("%v", v))
390390
}
391391

392392
// hypervisor qos

cloudstack/resource_cloudstack_service_offering.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package cloudstack
2222
import (
2323
"fmt"
2424
"strconv"
25+
"strings"
2526

2627
"github.com/apache/cloudstack-go/v2/cloudstack"
2728
"github.com/hashicorp/terraform/helper/schema"
@@ -77,13 +78,13 @@ func resourceCloudStackServiceOfferingRead(d *schema.ResourceData, meta interfac
7778
d.Set("offer_ha", s.Offerha)
7879
d.Set("provisioning_type", s.Provisioningtype)
7980
d.Set("root_disk_size", s.Rootdisksize)
80-
// duplicate values
81-
// d.Set("service_offering_details", s.Serviceofferingdetails)
8281
d.Set("storage_policy", s.Vspherestoragepolicy)
8382
d.Set("storage_type", s.Storagetype)
8483
d.Set("system_vm_type", s.Systemvmtype)
8584
d.Set("tags", s.Storagetags)
86-
d.Set("zone_id", s.Zoneid)
85+
if len(s.Zoneid) > 0 {
86+
d.Set("zone_id", strings.Split(s.Zoneid, ","))
87+
}
8788

8889
return nil
8990
}
@@ -104,11 +105,20 @@ func resourceCloudStackServiceOfferingUpdate(d *schema.ResourceData, meta interf
104105
if v, ok := d.GetOk("name"); ok {
105106
p.SetName(v.(string))
106107
}
107-
if v, ok := d.GetOk("storage_tags"); ok {
108+
if v, ok := d.GetOk("tags"); ok {
108109
p.SetStoragetags(v.(string))
109110
}
111+
110112
if v, ok := d.GetOk("zone_id"); ok {
111-
p.SetZoneid(v.(string))
113+
zone_id := v.(*schema.Set).List()
114+
items := make([]string, len(zone_id))
115+
for i, raw := range zone_id {
116+
items[i] = raw.(string)
117+
}
118+
p.SetZoneid(strings.Join(items, ","))
119+
} else {
120+
// Special parameter not documented in spec.
121+
p.SetZoneid("all")
112122
}
113123

114124
_, err := cs.ServiceOffering.UpdateServiceOffering(p)
@@ -191,8 +201,12 @@ func serviceOfferingMergeCommonSchema(s1 map[string]*schema.Schema) map[string]*
191201
Optional: true,
192202
ForceNew: true,
193203
},
204+
"tags": {
205+
Type: schema.TypeString,
206+
Optional: true,
207+
},
194208
"zone_id": {
195-
Type: schema.TypeList,
209+
Type: schema.TypeSet,
196210
Optional: true,
197211
Elem: &schema.Schema{
198212
Type: schema.TypeString,
@@ -225,6 +239,9 @@ func serviceOfferingCreateParams(p *cloudstack.CreateServiceOfferingParams, d *s
225239
if v, ok := d.GetOk("disk_offering_id"); ok {
226240
p.SetDiskofferingid(v.(string))
227241
}
242+
if v, ok := d.GetOk("tags"); ok {
243+
p.SetTags(v.(string))
244+
}
228245

229246
// Features flags
230247
p.SetDynamicscalingenabled(d.Get("dynamic_scaling_enabled").(bool))
@@ -243,7 +260,7 @@ func serviceOfferingCreateParams(p *cloudstack.CreateServiceOfferingParams, d *s
243260
}
244261

245262
if v, ok := d.GetOk("zone_id"); ok {
246-
zone_id := v.([]interface{})
263+
zone_id := v.(*schema.Set).List()
247264
items := make([]string, len(zone_id))
248265
for i, raw := range zone_id {
249266
items[i] = raw.(string)
@@ -268,9 +285,6 @@ func serviceOfferingCreateParams(p *cloudstack.CreateServiceOfferingParams, d *s
268285
tmp, _ := strconv.Atoi(v2.(string))
269286
p.SetRootdisksize(int64(tmp))
270287
}
271-
if v2, ok2 := offering["tags"]; ok2 {
272-
p.SetTags(v2.(string))
273-
}
274288
if v2, ok2 := offering["disk_offering_strictness"]; ok2 {
275289
tmp, _ := strconv.ParseBool(v2.(string))
276290
p.SetDiskofferingstrictness(tmp)
@@ -406,11 +420,6 @@ func serviceOfferingDisk() *schema.Schema {
406420
Computed: true,
407421
ForceNew: true,
408422
},
409-
"tags": {
410-
Type: schema.TypeString,
411-
Optional: true,
412-
ForceNew: true,
413-
},
414423
"storage_type": {
415424
Type: schema.TypeInt,
416425
Required: true,

cloudstack/resource_cloudstack_service_offering_constrained_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ func TestAccServiceOfferingConstrained(t *testing.T) {
3636
resource.TestCheckResourceAttr("cloudstack_service_offering_constrained.constrained1", "name", "constrained1"),
3737
),
3838
},
39+
// Sets zone id to all
40+
// This needs a zone data resource to return the id. Currently it returns the name as the id.
41+
// {
42+
// Config: testAccServiceOfferingCustomConstrained1ZoneAll,
43+
// Check: resource.ComposeTestCheckFunc(
44+
// resource.TestCheckResourceAttr("cloudstack_service_offering_constrained.constrained1", "name", "constrained1"),
45+
// ),
46+
// },
3947
{
4048
Config: testAccServiceOfferingCustomConstrained2,
4149
Check: resource.ComposeTestCheckFunc(
@@ -85,6 +93,7 @@ resource "cloudstack_service_offering_constrained" "constrained1" {
8593
min_memory = 1024
8694
8795
// other
96+
tags = "foo"
8897
host_tags = "test0101,test0202"
8998
network_rate = 1024
9099
deployment_planner = "UserDispersingPlanner"
@@ -94,6 +103,38 @@ resource "cloudstack_service_offering_constrained" "constrained1" {
94103
is_volatile = false
95104
limit_cpu_use = false
96105
offer_ha = false
106+
// zone_id = ["3c4d4404-20d7-453a-a84d-e381074315c7"]
107+
108+
}
109+
`
110+
111+
const testAccServiceOfferingCustomConstrained1ZoneAll = `
112+
resource "cloudstack_service_offering_constrained" "constrained1" {
113+
display_text = "constrained11"
114+
name = "constrained1"
115+
116+
// compute
117+
cpu_speed = 2500
118+
max_cpu_number = 10
119+
min_cpu_number = 2
120+
121+
// memory
122+
max_memory = 4096
123+
min_memory = 1024
124+
125+
// other
126+
tags = "foo1"
127+
host_tags = "test0101,test0202"
128+
network_rate = 1024
129+
deployment_planner = "UserDispersingPlanner"
130+
131+
// Feature flags
132+
dynamic_scaling_enabled = false
133+
is_volatile = false
134+
limit_cpu_use = false
135+
offer_ha = false
136+
137+
zone_id = []
97138
}
98139
`
99140

0 commit comments

Comments
 (0)