Skip to content

Commit

Permalink
fix zone_id and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
poddm committed Jan 5, 2024
1 parent 1e9464d commit 6cd4b2b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cloudstack/resource_cloudstack_disk_offering.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package cloudstack

import (
"fmt"
"strconv"

"github.com/apache/cloudstack-go/v2/cloudstack"
Expand Down Expand Up @@ -97,7 +98,6 @@ func resourceCloudStackDiskOffering() *schema.Resource {
"tags": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"zone_id": {
Type: schema.TypeList,
Expand Down Expand Up @@ -386,7 +386,7 @@ func resourceCloudStackDiskOfferingUpdate(d *schema.ResourceData, meta interface
p.SetTags(v.(string))
}
if v, ok := d.GetOk("zone_id"); ok {
p.SetZoneid(v.(string))
p.SetZoneid(fmt.Sprintf("%v", v))
}

// hypervisor qos
Expand Down
39 changes: 24 additions & 15 deletions cloudstack/resource_cloudstack_service_offering.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package cloudstack
import (
"fmt"
"strconv"
"strings"

"github.com/apache/cloudstack-go/v2/cloudstack"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -77,13 +78,13 @@ func resourceCloudStackServiceOfferingRead(d *schema.ResourceData, meta interfac
d.Set("offer_ha", s.Offerha)
d.Set("provisioning_type", s.Provisioningtype)
d.Set("root_disk_size", s.Rootdisksize)
// duplicate values
// d.Set("service_offering_details", s.Serviceofferingdetails)
d.Set("storage_policy", s.Vspherestoragepolicy)
d.Set("storage_type", s.Storagetype)
d.Set("system_vm_type", s.Systemvmtype)
d.Set("tags", s.Storagetags)
d.Set("zone_id", s.Zoneid)
if len(s.Zoneid) > 0 {
d.Set("zone_id", strings.Split(s.Zoneid, ","))
}

return nil
}
Expand All @@ -104,11 +105,20 @@ func resourceCloudStackServiceOfferingUpdate(d *schema.ResourceData, meta interf
if v, ok := d.GetOk("name"); ok {
p.SetName(v.(string))
}
if v, ok := d.GetOk("storage_tags"); ok {
if v, ok := d.GetOk("tags"); ok {
p.SetStoragetags(v.(string))
}

if v, ok := d.GetOk("zone_id"); ok {
p.SetZoneid(v.(string))
zone_id := v.(*schema.Set).List()
items := make([]string, len(zone_id))
for i, raw := range zone_id {
items[i] = raw.(string)
}
p.SetZoneid(strings.Join(items, ","))
} else {
// Special parameter not documented in spec.
p.SetZoneid("all")
}

_, err := cs.ServiceOffering.UpdateServiceOffering(p)
Expand Down Expand Up @@ -191,8 +201,12 @@ func serviceOfferingMergeCommonSchema(s1 map[string]*schema.Schema) map[string]*
Optional: true,
ForceNew: true,
},
"tags": {
Type: schema.TypeString,
Optional: true,
},
"zone_id": {
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -225,6 +239,9 @@ func serviceOfferingCreateParams(p *cloudstack.CreateServiceOfferingParams, d *s
if v, ok := d.GetOk("disk_offering_id"); ok {
p.SetDiskofferingid(v.(string))
}
if v, ok := d.GetOk("tags"); ok {
p.SetTags(v.(string))
}

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

if v, ok := d.GetOk("zone_id"); ok {
zone_id := v.([]interface{})
zone_id := v.(*schema.Set).List()
items := make([]string, len(zone_id))
for i, raw := range zone_id {
items[i] = raw.(string)
Expand All @@ -268,9 +285,6 @@ func serviceOfferingCreateParams(p *cloudstack.CreateServiceOfferingParams, d *s
tmp, _ := strconv.Atoi(v2.(string))
p.SetRootdisksize(int64(tmp))
}
if v2, ok2 := offering["tags"]; ok2 {
p.SetTags(v2.(string))
}
if v2, ok2 := offering["disk_offering_strictness"]; ok2 {
tmp, _ := strconv.ParseBool(v2.(string))
p.SetDiskofferingstrictness(tmp)
Expand Down Expand Up @@ -406,11 +420,6 @@ func serviceOfferingDisk() *schema.Schema {
Computed: true,
ForceNew: true,
},
"tags": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"storage_type": {
Type: schema.TypeInt,
Required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ func TestAccServiceOfferingConstrained(t *testing.T) {
resource.TestCheckResourceAttr("cloudstack_service_offering_constrained.constrained1", "name", "constrained1"),
),
},
// Sets zone id to all
// This needs a zone data resource to return the id. Currently it returns the name as the id.
// {
// Config: testAccServiceOfferingCustomConstrained1ZoneAll,
// Check: resource.ComposeTestCheckFunc(
// resource.TestCheckResourceAttr("cloudstack_service_offering_constrained.constrained1", "name", "constrained1"),
// ),
// },
{
Config: testAccServiceOfferingCustomConstrained2,
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -85,6 +93,7 @@ resource "cloudstack_service_offering_constrained" "constrained1" {
min_memory = 1024
// other
tags = "foo"
host_tags = "test0101,test0202"
network_rate = 1024
deployment_planner = "UserDispersingPlanner"
Expand All @@ -94,6 +103,38 @@ resource "cloudstack_service_offering_constrained" "constrained1" {
is_volatile = false
limit_cpu_use = false
offer_ha = false
// zone_id = ["3c4d4404-20d7-453a-a84d-e381074315c7"]
}
`

const testAccServiceOfferingCustomConstrained1ZoneAll = `
resource "cloudstack_service_offering_constrained" "constrained1" {
display_text = "constrained11"
name = "constrained1"
// compute
cpu_speed = 2500
max_cpu_number = 10
min_cpu_number = 2
// memory
max_memory = 4096
min_memory = 1024
// other
tags = "foo1"
host_tags = "test0101,test0202"
network_rate = 1024
deployment_planner = "UserDispersingPlanner"
// Feature flags
dynamic_scaling_enabled = false
is_volatile = false
limit_cpu_use = false
offer_ha = false
zone_id = []
}
`

Expand Down

0 comments on commit 6cd4b2b

Please sign in to comment.