Skip to content

Commit

Permalink
improve on disk data source
Browse files Browse the repository at this point in the history
  • Loading branch information
katia-e committed Sep 6, 2019
1 parent 9a8b8dc commit 6801df8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
3 changes: 1 addition & 2 deletions go.mod
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions go.sum
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
17 changes: 13 additions & 4 deletions ovc/data_source_disk.go
Expand Up @@ -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,
Expand All @@ -35,6 +35,7 @@ func dataSourceOvcDisk() *schema.Resource {
"type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"size_used": {
Type: schema.TypeInt,
Expand All @@ -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
Expand Down
17 changes: 8 additions & 9 deletions vendor/github.com/gig-tech/ovc-sdk-go/ovc/disks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -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
Expand Down

0 comments on commit 6801df8

Please sign in to comment.