-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from ans-group/volumes-computed-iops
add ecloud_iops datasource, remove validation func from instance iops
- Loading branch information
Showing
7 changed files
with
141 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# ecloud_iops Data Source | ||
|
||
This resource represents an eCloud IOPS tier | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "ecloud_iops" "iops-300" { | ||
number = 300 | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `iops_id`: ID of IOPS tier | ||
- `availability_zone_id`: ID of Availability Zone that tier is available in | ||
- `name`: Name of IOPS tier | ||
- `level`: IOPS level/limit | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to IOPS tier ID | ||
|
||
- `name`: Name of IOPS tier | ||
- `level`: IOPS level/limit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package ecloud | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ans-group/sdk-go/pkg/connection" | ||
ecloudservice "github.com/ans-group/sdk-go/pkg/service/ecloud" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceIOPS() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceIOPSRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"availability_zone_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"level": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceIOPSRead(d *schema.ResourceData, meta interface{}) error { | ||
service := meta.(ecloudservice.ECloudService) | ||
|
||
params := connection.APIRequestParameters{} | ||
|
||
if id, ok := d.GetOk("iops_id"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("id", connection.EQOperator, []string{id.(string)})) | ||
} | ||
if name, ok := d.GetOk("name"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("name", connection.EQOperator, []string{name.(string)})) | ||
} | ||
if level, ok := d.GetOk("level"); ok { | ||
params.WithFilter(*connection.NewAPIRequestFiltering("level", connection.EQOperator, []string{strconv.Itoa(level.(int))})) | ||
} | ||
|
||
var tiers []ecloudservice.IOPSTier | ||
var err error | ||
if azID, ok := d.GetOk("availability_zone_id"); ok { | ||
tiers, err = service.GetAvailabilityZoneIOPSTiers(azID.(string), params) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving availability zone IOPS tiers: %s", err) | ||
} | ||
} else { | ||
tiers, err = service.GetIOPSTiers(params) | ||
if err != nil { | ||
return fmt.Errorf("Error retrieving IOPS tiers: %s", err) | ||
} | ||
} | ||
|
||
if len(tiers) < 1 { | ||
return errors.New("No IOPS tiers found with provided arguments") | ||
} | ||
|
||
if len(tiers) > 1 { | ||
return errors.New("More than 1 IOPS tier found with provided arguments") | ||
} | ||
|
||
d.SetId(tiers[0].ID) | ||
d.Set("name", tiers[0].Name) | ||
d.Set("level", tiers[0].Level) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ecloud | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceIOPS_basic(t *testing.T) { | ||
level := 300 | ||
config := testAccDataSourceIOPSConfig_basic(level) | ||
resourceName := "data.ecloud_iops.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(resourceName, "level", strconv.Itoa(level)), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceIOPSConfig_basic(level int) string { | ||
return fmt.Sprintf(` | ||
data "ecloud_iops" "test" { | ||
level = "%d" | ||
} | ||
`, level) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters