Skip to content

Commit 0b8428c

Browse files
committed
Fix disk offering create when neither disk_size nor customized is set
1 parent 02e24b1 commit 0b8428c

4 files changed

Lines changed: 19 additions & 6 deletions

File tree

cloudstack/data_source_cloudstack_disk_offering.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ func applyDiskOfferingFilters(diskOffering *cloudstack.DiskOffering, filters *sc
156156
return false, fmt.Errorf("Invalid regex: %s", err)
157157
}
158158
updatedName := strings.ReplaceAll(m["name"].(string), "_", "")
159-
diskOfferingField, ok := diskOfferingJSON[updatedName].(string)
159+
raw, ok := diskOfferingJSON[updatedName]
160160
if !ok {
161-
return false, fmt.Errorf("Field %s is not a string and cannot be filtered", m["name"].(string))
161+
return false, fmt.Errorf("Unknown filter field %s", m["name"].(string))
162162
}
163+
diskOfferingField := fmt.Sprint(raw)
163164
if !r.MatchString(diskOfferingField) {
164165
return false, nil
165166
}

cloudstack/resource_cloudstack_disk_offering.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ func resourceCloudStackDiskOfferingCreate(d *schema.ResourceData, meta interface
119119
p.SetDisksize(int64(v.(int)))
120120
}
121121

122+
customized := false
122123
if v, ok := d.GetOk("customized"); ok {
123-
p.SetCustomized(v.(bool))
124+
customized = v.(bool)
124125
}
126+
if _, ok := d.GetOk("disk_size"); !ok {
127+
customized = true
128+
}
129+
p.SetCustomized(customized)
125130

126131
if v, ok := d.GetOk("storage_type"); ok {
127132
p.SetStoragetype(v.(string))

cloudstack/resource_cloudstack_disk_offering_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func TestAccCloudStackDiskOffering_basic(t *testing.T) {
4545
resource.TestCheckResourceAttr("cloudstack_disk_offering.test1", "storage_type", "shared"),
4646
),
4747
},
48+
{
49+
ResourceName: "cloudstack_disk_offering.test1",
50+
ImportState: true,
51+
ImportStateVerify: true,
52+
},
4853
},
4954
})
5055
}

website/docs/r/disk_offering.html.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ The following arguments are supported:
2828
* `name` - (Required) The name of the disk offering.
2929
* `display_text` - (Required) The display text of the disk offering.
3030
* `disk_size` - (Optional) The size of the disk offering in GB. Conflicts with
31-
`customized`. Changing this forces a new resource to be created.
31+
`customized`. If neither `disk_size` nor `customized` is set, the offering is
32+
created as customized. Changing this forces a new resource to be created.
3233
* `customized` - (Optional) Whether the disk offering allows a custom disk size
33-
to be specified at deployment time. Conflicts with `disk_size`. Defaults to
34-
`false`. Changing this forces a new resource to be created.
34+
to be specified at deployment time. Conflicts with `disk_size`, and is
35+
implied when `disk_size` is omitted. Defaults to `false`. Changing this
36+
forces a new resource to be created.
3537
* `storage_type` - (Optional) The storage type of the disk offering. Values are
3638
`local` and `shared`. Defaults to `shared`. Changing this forces a new
3739
resource to be created.

0 commit comments

Comments
 (0)