diff --git a/cloudstack/resource_cloudstack_disk_offering.go b/cloudstack/resource_cloudstack_disk_offering.go index a4faaaaf..b4b3cdde 100644 --- a/cloudstack/resource_cloudstack_disk_offering.go +++ b/cloudstack/resource_cloudstack_disk_offering.go @@ -20,6 +20,7 @@ package cloudstack import ( + "fmt" "strconv" "github.com/apache/cloudstack-go/v2/cloudstack" @@ -97,7 +98,6 @@ func resourceCloudStackDiskOffering() *schema.Resource { "tags": { Type: schema.TypeString, Optional: true, - ForceNew: true, }, "zone_id": { Type: schema.TypeList, @@ -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 diff --git a/cloudstack/resource_cloudstack_service_offering.go b/cloudstack/resource_cloudstack_service_offering.go index 15c2b6aa..e2f492cc 100644 --- a/cloudstack/resource_cloudstack_service_offering.go +++ b/cloudstack/resource_cloudstack_service_offering.go @@ -22,6 +22,7 @@ package cloudstack import ( "fmt" "strconv" + "strings" "github.com/apache/cloudstack-go/v2/cloudstack" "github.com/hashicorp/terraform/helper/schema" @@ -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 } @@ -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) @@ -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, @@ -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)) @@ -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) @@ -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) @@ -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, diff --git a/cloudstack/resource_cloudstack_service_offering_constrained_test.go b/cloudstack/resource_cloudstack_service_offering_constrained_test.go index b234ead2..28d79be3 100644 --- a/cloudstack/resource_cloudstack_service_offering_constrained_test.go +++ b/cloudstack/resource_cloudstack_service_offering_constrained_test.go @@ -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( @@ -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" @@ -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 = [] } `