diff --git a/go.mod b/go.mod index 9bc29ff..1c729b1 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,10 @@ module github.com/gig-tech/terraform-provider-ovc go 1.11 require ( - github.com/gig-tech/ovc-sdk-go v1.4.0 + github.com/gig-tech/ovc-sdk-go v1.4.1 github.com/hashicorp/terraform v0.11.13 github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/kr/pretty v0.1.0 // indirect - github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.4.0 // indirect golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect diff --git a/go.sum b/go.sum index ede7338..14ca2ae 100644 --- a/go.sum +++ b/go.sum @@ -46,10 +46,8 @@ github.com/dnaeon/go-vcr v0.0.0-20170218072653-87d4990451a8/go.mod h1:aBB1+wY4s9 github.com/dylanmei/iso8601 v0.1.0/go.mod h1:w9KhXSgIyROl1DefbMYIE7UVSIvELTbMrCfx+QkYnoQ= github.com/dylanmei/winrmtest v0.0.0-20170819153634-c2fbb09e6c08/go.mod h1:VBVDFSBXCIW8JaHQpI8lldSKfYaLMzP9oyq6IJ4fhzY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/gig-tech/ovc-sdk-go v1.4.0 h1:APfEA6qg9tipbR5qLvXoT47Qg48Z4m1T6bmKJM9Q7yU= -github.com/gig-tech/ovc-sdk-go v1.4.0/go.mod h1:LPuRHlsQFu6t/SK+bs15exO4tR+JxpAZoYaAdSqs2wA= -github.com/gig-tech/ovc-sdk-go v1.4.1-0.20190905131340-0ae5e082b722 h1:zNblJr/ggNNxUKxI5SE+72E7p5TUxY0cx2AsnSXvw0w= -github.com/gig-tech/ovc-sdk-go v1.4.1-0.20190905131340-0ae5e082b722/go.mod h1:LPuRHlsQFu6t/SK+bs15exO4tR+JxpAZoYaAdSqs2wA= +github.com/gig-tech/ovc-sdk-go v1.4.1 h1:d+onDFcYP+8FHLhtoKYyRle0fZHf5Z85yUUnfv+l0zA= +github.com/gig-tech/ovc-sdk-go v1.4.1/go.mod h1:LPuRHlsQFu6t/SK+bs15exO4tR+JxpAZoYaAdSqs2wA= github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo= github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg= @@ -190,7 +188,6 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/spf13/afero v1.0.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/ovc/data_source_disk.go b/ovc/data_source_disk.go index 54f6ead..7676325 100644 --- a/ovc/data_source_disk.go +++ b/ovc/data_source_disk.go @@ -20,9 +20,9 @@ func dataSourceOvcDisk() *schema.Resource { Type: schema.TypeInt, Computed: true, }, - "account_id": { + "account": { Type: schema.TypeString, - Required: true, + Optional: true, }, "name": { Type: schema.TypeString, @@ -35,6 +35,7 @@ func dataSourceOvcDisk() *schema.Resource { "type": { Type: schema.TypeString, Computed: true, + Optional: true, }, "size_used": { Type: schema.TypeInt, @@ -46,12 +47,20 @@ func dataSourceOvcDisk() *schema.Resource { func dataSourceOvcDiskRead(d *schema.ResourceData, m interface{}) error { client := m.(*ovc.Client) - var disk *ovc.DiskInfo var err error + var accountID int + account := d.Get("account") + if account != "" { + accountID, err = client.Accounts.GetIDByName(account.(string)) + if err != nil { + return err + } + } + var disk *ovc.DiskInfo if v, ok := d.GetOk("disk_id"); ok { disk, err = client.Disks.Get(v.(string)) } else { - disk, err = client.Disks.GetByName(d.Get("name").(string), d.Get("account_id").(string)) + disk, err = client.Disks.GetByName(d.Get("name").(string), accountID, d.Get("type").(string)) } if err != nil { return err diff --git a/vendor/github.com/gig-tech/ovc-sdk-go/ovc/disks.go b/vendor/github.com/gig-tech/ovc-sdk-go/ovc/disks.go index 43d4939..bc285a3 100644 --- a/vendor/github.com/gig-tech/ovc-sdk-go/ovc/disks.go +++ b/vendor/github.com/gig-tech/ovc-sdk-go/ovc/disks.go @@ -89,9 +89,9 @@ type DiskList []struct { // endpoints of the OVC API type DiskService interface { Resize(*DiskConfig) error - List(int) (*DiskList, error) + List(int, string) (*DiskList, error) Get(string) (*DiskInfo, error) - GetByName(string, string) (*DiskInfo, error) + GetByName(string, int, string) (*DiskInfo, error) Create(*DiskConfig) (string, error) CreateAndAttach(*DiskConfig) (string, error) Attach(*DiskAttachConfig) error @@ -107,9 +107,12 @@ type DiskServiceOp struct { } // List all disks -func (s *DiskServiceOp) List(accountID int) (*DiskList, error) { +func (s *DiskServiceOp) List(accountID int, diskType string) (*DiskList, error) { diskMap := make(map[string]interface{}) diskMap["accountId"] = accountID + if len(diskType) != 0 { + diskMap["type"] = diskType + } diskJSON, err := json.Marshal(diskMap) if err != nil { return nil, err @@ -289,12 +292,8 @@ func (s *DiskServiceOp) Get(diskID string) (*DiskInfo, error) { } // GetByName gets a disk by its name -func (s *DiskServiceOp) GetByName(name string, accountID string) (*DiskInfo, error) { - aid, err := strconv.Atoi(accountID) - if err != nil { - return nil, err - } - disks, err := s.client.Disks.List(aid) +func (s *DiskServiceOp) GetByName(name string, accountID int, diskType string) (*DiskInfo, error) { + disks, err := s.client.Disks.List(accountID, diskType) if err != nil { return nil, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 6bc8698..92255bb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -48,7 +48,7 @@ github.com/blang/semver github.com/davecgh/go-spew/spew # github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go -# github.com/gig-tech/ovc-sdk-go v1.4.1-0.20190905131340-0ae5e082b722 +# github.com/gig-tech/ovc-sdk-go v1.4.1 github.com/gig-tech/ovc-sdk-go/ovc # github.com/go-ini/ini v1.25.4 github.com/go-ini/ini