Skip to content

Commit

Permalink
Support notes on file storage and expose network mount address (#145)
Browse files Browse the repository at this point in the history
* Support notes on file storage
* Expose network mount address as `mountpoint`
  • Loading branch information
sykesm authored and renier committed Apr 27, 2017
1 parent fb01e5c commit ff41d7f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/resources/softlayer_file_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ The following arguments are supported:
* `allowed_ip_addresses` | *array of string*
* Specifies allowed IP addresses. IP addresses should be in the same data center.
* **Optional**
* `notes` | *string*
* Specifies a note to associate with the file storage.
* **Optional**


## Attributes Reference
Expand All @@ -77,3 +80,4 @@ The following attributes are exported:
* `id` - id of the storage.
* `hostname` - The fully qualified domain name of the storage.
* `volumename` - The name of the storage volume.
* `mountpoint` - The network mount address of the storage.
46 changes: 45 additions & 1 deletion softlayer/resource_softlayer_file_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
storageEndurancePackageType = "ADDITIONAL_SERVICES_ENTERPRISE_STORAGE"
storageMask = "id,billingItem.orderItem.order.id"
storageDetailMask = "id,capacityGb,iops,storageType,username,serviceResourceBackendIpAddress,properties[type]" +
",serviceResourceName,allowedIpAddresses,allowedSubnets,allowedVirtualGuests[id,allowedHost[name,credential[username,password]]],allowedHardware[id,allowedHost[name,credential[username,password]]],snapshotCapacityGb,osType"
",serviceResourceName,allowedIpAddresses,allowedSubnets,allowedVirtualGuests[id,allowedHost[name,credential[username,password]]],allowedHardware[id,allowedHost[name,credential[username,password]]],snapshotCapacityGb,osType,notes"
itemMask = "id,capacity,description,units,keyName,prices[id,categories[id,name,categoryCode],capacityRestrictionMinimum,capacityRestrictionMaximum,locationGroupId]"
enduranceType = "Endurance"
performanceType = "Performance"
Expand Down Expand Up @@ -166,6 +166,16 @@ func resourceSoftLayerFileStorage() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"notes": {
Type: schema.TypeString,
Optional: true,
},

"mountpoint": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -307,6 +317,16 @@ func resourceSoftLayerFileStorageRead(d *schema.ResourceData, meta interface{})
d.Set("os_type", *storage.OsType.Name)
}

if storage.Notes != nil {
d.Set("notes", *storage.Notes)
}

mountpoint, err := services.GetNetworkStorageService(sess).Id(storageId).GetFileNetworkMountAddress()
if err != nil {
return fmt.Errorf("Error retrieving storage information: %s", err)
}
d.Set("mountpoint", mountpoint)

return nil
}

Expand Down Expand Up @@ -358,6 +378,14 @@ func resourceSoftLayerFileStorageUpdate(d *schema.ResourceData, meta interface{}
}
}

// Update notes
if d.HasChange("notes") {
err := updateNotes(d, sess, storage)
if err != nil {
return fmt.Errorf("Error updating storage information: %s", err)
}
}

return resourceSoftLayerFileStorageRead(d, meta)
}

Expand Down Expand Up @@ -975,3 +1003,19 @@ func updateAllowedHardwareIds(d *schema.ResourceData, sess *session.Session, sto
}
return nil
}

func updateNotes(d *schema.ResourceData, sess *session.Session, storage datatypes.Network_Storage) error {
id := *storage.Id
notes := d.Get("notes").(string)

if (storage.Notes != nil && *storage.Notes != notes) || (storage.Notes == nil && notes != "") {
_, err := services.GetNetworkStorageService(sess).
Id(id).
EditObject(&datatypes.Network_Storage{Notes: sl.String(notes)})
if err != nil {
return fmt.Errorf("Error adding note to storage (%d): %s", id, err)
}
}

return nil
}
9 changes: 9 additions & 0 deletions softlayer/resource_softlayer_file_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func TestAccSoftLayerFileStorage_Basic(t *testing.T) {
"softlayer_file_storage.fs_endurance", "snapshot_capacity", "10"),
testAccCheckSoftLayerResources("softlayer_file_storage.fs_endurance", "datacenter",
"softlayer_virtual_guest.storagevm1", "datacenter"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_endurance", "notes", "endurance notes"),
resource.TestCheckResourceAttrSet("softlayer_file_storage.fs_endurance", "mountpoint"),
// Performance Storage
testAccCheckSoftLayerFileStorageExists("softlayer_file_storage.fs_performance"),
resource.TestCheckResourceAttr(
Expand All @@ -41,6 +43,8 @@ func TestAccSoftLayerFileStorage_Basic(t *testing.T) {
"softlayer_file_storage.fs_performance", "iops", "100"),
testAccCheckSoftLayerResources("softlayer_file_storage.fs_performance", "datacenter",
"softlayer_virtual_guest.storagevm1", "datacenter"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_performance", "notes", "performance notes"),
resource.TestCheckResourceAttrSet("softlayer_file_storage.fs_performance", "mountpoint"),
),
},

Expand All @@ -51,10 +55,12 @@ func TestAccSoftLayerFileStorage_Basic(t *testing.T) {
resource.TestCheckResourceAttr("softlayer_file_storage.fs_endurance", "allowed_virtual_guest_ids.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_endurance", "allowed_subnets.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_endurance", "allowed_ip_addresses.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_endurance", "notes", "updated endurance notes"),
// Performance Storage
resource.TestCheckResourceAttr("softlayer_file_storage.fs_performance", "allowed_virtual_guest_ids.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_performance", "allowed_subnets.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_performance", "allowed_ip_addresses.#", "1"),
resource.TestCheckResourceAttr("softlayer_file_storage.fs_performance", "notes", ""),
),
},
},
Expand Down Expand Up @@ -111,13 +117,15 @@ resource "softlayer_file_storage" "fs_endurance" {
capacity = 20
iops = 0.25
snapshot_capacity = 10
notes = "endurance notes"
}
resource "softlayer_file_storage" "fs_performance" {
type = "Performance"
datacenter = "${softlayer_virtual_guest.storagevm1.datacenter}"
capacity = 20
iops = 100
notes = "performance notes"
}
`
const testAccCheckSoftLayerFileStorageConfig_update = `
Expand All @@ -144,6 +152,7 @@ resource "softlayer_file_storage" "fs_endurance" {
allowed_subnets = [ "${softlayer_virtual_guest.storagevm1.private_subnet}" ]
allowed_ip_addresses = [ "${softlayer_virtual_guest.storagevm1.ipv4_address_private}" ]
snapshot_capacity = 10
notes = "updated endurance notes"
}
resource "softlayer_file_storage" "fs_performance" {
Expand Down

0 comments on commit ff41d7f

Please sign in to comment.