-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source: openstack_blockstorage_quotaset_v3
- Loading branch information
1 parent
3a235ee
commit c2d4f94
Showing
5 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
openstack/data_source_openstack_blockstorage_quotaset_v3.go
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,108 @@ | ||
package openstack | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/quotasets" | ||
) | ||
|
||
func dataSourceBlockStorageQuotasetV3() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceBlockStorageQuotasetV3Read, | ||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"project_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"volumes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"snapshots": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"gigabytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"per_volume_gigabytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"backups": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"backup_gigabytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"groups": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"volume_type_quota": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceBlockStorageQuotasetV3Read(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
config := meta.(*Config) | ||
region := GetRegion(d, config) | ||
blockStorageClient, err := config.BlockStorageV3Client(region) | ||
if err != nil { | ||
return diag.Errorf("Error creating OpenStack block storage client: %s", err) | ||
} | ||
|
||
projectID := d.Get("project_id").(string) | ||
|
||
q, err := quotasets.Get(blockStorageClient, projectID).Extract() | ||
if err != nil { | ||
return diag.FromErr(CheckDeleted(d, err, "Error retrieving openstack_blockstorage_quotaset_v3")) | ||
} | ||
|
||
log.Printf("[DEBUG] Retrieved openstack_blockstorage_quotaset_v3 %s: %#v", d.Id(), q) | ||
|
||
id := fmt.Sprintf("%s/%s", projectID, region) | ||
d.SetId(id) | ||
d.Set("project_id", projectID) | ||
d.Set("region", region) | ||
d.Set("volumes", q.Volumes) | ||
d.Set("snapshots", q.Snapshots) | ||
d.Set("gigabytes", q.Gigabytes) | ||
d.Set("per_volume_gigabytes", q.PerVolumeGigabytes) | ||
d.Set("backups", q.Backups) | ||
d.Set("backup_gigabytes", q.BackupGigabytes) | ||
d.Set("groups", q.Groups) | ||
|
||
volumeTypeQuota, _ := blockStorageQuotasetVolTypeQuotaToStr(q.Extra) | ||
if err := d.Set("volume_type_quota", volumeTypeQuota); err != nil { | ||
log.Printf("[WARN] Unable to set openstack_blockstorage_quotaset_v3 %s volume_type_quotas: %s", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
69 changes: 69 additions & 0 deletions
69
openstack/data_source_openstack_blockstorage_quotaset_v3_test.go
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,69 @@ | ||
package openstack | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
func TestAccBlockStorageV3QuotasetDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
testAccPreCheckAdminOnly(t) | ||
}, | ||
ProviderFactories: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccBlockStorageV3QuotasetDataSourceBasic, | ||
}, | ||
{ | ||
Config: testAccBlockStorageV3QuotasetDataSourceSource(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckBlockStorageQuotasetV3DataSourceID("data.openstack_blockstorage_quotaset_v3.source"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "volumes"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "snapshots"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "gigabytes"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "per_volume_gigabytes"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "backups"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "backup_gigabytes"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "groups"), | ||
resource.TestCheckResourceAttrSet("data.openstack_blockstorage_quotaset_v3.source", "volume_type_quota"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckBlockStorageQuotasetV3DataSourceID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find blockstorage quotaset data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("Blockstorage quotaset data source ID not set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const testAccBlockStorageV3QuotasetDataSourceBasic = ` | ||
resource "openstack_identity_project_v3" "project" { | ||
name = "test-quotaset-datasource" | ||
} | ||
` | ||
|
||
func testAccBlockStorageV3QuotasetDataSourceSource() string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "openstack_blockstorage_quotaset_v3" "source" { | ||
project_id = "${openstack_identity_project_v3.project.id}" | ||
} | ||
`, testAccBlockStorageV3QuotasetDataSourceBasic) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
layout: "openstack" | ||
page_title: "OpenStack: openstack_blockstorage_quotaset_v3" | ||
sidebar_current: "docs-openstack-datasource-blockstorage-quotaset-v3" | ||
description: |- | ||
Get information on a BlockStorage Quotaset v3 of a project. | ||
--- | ||
|
||
# openstack\_blockstorage\_quotaset\_v3 | ||
|
||
Use this data source to get the blockstorage quotaset v3 of an OpenStack project. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "openstack_blockstorage_quotaset_v3" "quota" { | ||
project_id = "2e367a3d29f94fd988e6ec54e305ec9d" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `region` - (Optional) The region in which to obtain the V3 Blockstorage client. | ||
If omitted, the `region` argument of the provider is used. | ||
|
||
* `project_id` - (Required) The id of the project to retrieve the quotaset. | ||
|
||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `region` - See Argument Reference above. | ||
* `project_id` - See Argument Reference above. | ||
* `volumes` - The number of volumes that are allowed. | ||
* `snapshots` - The number of snapshots that are allowed. | ||
* `gigabytes` - The size (GB) of volumes and snapshots that are allowed. | ||
* `per_volume_gigabytes` - The size (GB) of volumes that are allowed for each volume. | ||
* `backups` - The number of backups that are allowed. | ||
* `backup_gigabytes` - The size (GB) of backups that are allowed. | ||
* `groups` - The number of groups that are allowed. | ||
* `volume_type_quota` - Map with gigabytes_{volume_type}, snapshots_{volume_type}, volumes_{volume_type} for each volume type. |
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