-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new resource netapp volumes quotaRules (#12665) (#9248)
[upstream:8bb1c8041552dd3991c32a01f2f517dac5c58079] Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
14ffde6
commit 4826017
Showing
8 changed files
with
1,322 additions
and
2 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,3 @@ | ||
```release-note:new-resource | ||
`google_netapp_volume_quota_rule` | ||
``` |
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
129 changes: 129 additions & 0 deletions
129
google-beta/services/netapp/resource_netapp_volume_quotaRule_sweeper.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,129 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
package netapp | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/envvar" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/sweeper" | ||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" | ||
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" | ||
) | ||
|
||
func init() { | ||
sweeper.AddTestSweepers("NetappVolumeQuotaRule", testSweepNetappVolumeQuotaRule) | ||
} | ||
|
||
// At the time of writing, the CI only passes us-central1 as the region | ||
func testSweepNetappVolumeQuotaRule(region string) error { | ||
resourceName := "NetappVolumeQuotaRule" | ||
log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s", resourceName) | ||
|
||
config, err := sweeper.SharedConfigForRegion(region) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error getting shared config for region: %s", err) | ||
return err | ||
} | ||
|
||
err = config.LoadAndValidate(context.Background()) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error loading: %s", err) | ||
return err | ||
} | ||
|
||
t := &testing.T{} | ||
billingId := envvar.GetTestBillingAccountFromEnv(t) | ||
|
||
regions := []string{"us-central1", "us-west2", "us-east4"} | ||
for _, r := range regions { | ||
log.Printf("[INFO][SWEEPER_LOG] Starting sweeper for %s in %s", resourceName, r) | ||
|
||
// Setup variables to replace in list template | ||
d := &tpgresource.ResourceDataMock{ | ||
FieldsInSchema: map[string]interface{}{ | ||
"project": config.Project, | ||
"region": r, | ||
"location": r, | ||
"zone": "-", | ||
"billing_account": billingId, | ||
}, | ||
} | ||
|
||
listTemplate := strings.Split("https://netapp.googleapis.com/v1/projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/quotaRules", "?")[0] | ||
listUrl, err := tpgresource.ReplaceVars(d, config, listTemplate) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error preparing sweeper list url: %s", err) | ||
continue | ||
} | ||
|
||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "GET", | ||
Project: config.Project, | ||
RawURL: listUrl, | ||
UserAgent: config.UserAgent, | ||
}) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error in response from request %s: %s", listUrl, err) | ||
continue | ||
} | ||
|
||
resourceList, ok := res["volumeQuotaRules"] | ||
if !ok { | ||
log.Printf("[INFO][SWEEPER_LOG] Nothing found in response.") | ||
continue | ||
} | ||
|
||
rl := resourceList.([]interface{}) | ||
|
||
log.Printf("[INFO][SWEEPER_LOG] Found %d items in %s list response.", len(rl), resourceName) | ||
// Keep count of items that aren't sweepable for logging. | ||
nonPrefixCount := 0 | ||
for _, ri := range rl { | ||
obj := ri.(map[string]interface{}) | ||
if obj["name"] == nil { | ||
log.Printf("[INFO][SWEEPER_LOG] %s resource name was nil", resourceName) | ||
continue | ||
} | ||
|
||
name := tpgresource.GetResourceNameFromSelfLink(obj["name"].(string)) | ||
// Skip resources that shouldn't be sweeped | ||
if !sweeper.IsSweepableTestResource(name) { | ||
nonPrefixCount++ | ||
continue | ||
} | ||
|
||
deleteTemplate := "https://netapp.googleapis.com/v1/projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/quotaRules/{{name}}" | ||
deleteUrl, err := tpgresource.ReplaceVars(d, config, deleteTemplate) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err) | ||
continue | ||
} | ||
deleteUrl = deleteUrl + name | ||
|
||
// Don't wait on operations as we may have a lot to delete | ||
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "DELETE", | ||
Project: config.Project, | ||
RawURL: deleteUrl, | ||
UserAgent: config.UserAgent, | ||
}) | ||
if err != nil { | ||
log.Printf("[INFO][SWEEPER_LOG] Error deleting for url %s : %s", deleteUrl, err) | ||
} else { | ||
log.Printf("[INFO][SWEEPER_LOG] Sent delete request for %s resource: %s", resourceName, name) | ||
} | ||
} | ||
|
||
if nonPrefixCount > 0 { | ||
log.Printf("[INFO][SWEEPER_LOG] %d items were non-sweepable and skipped.", nonPrefixCount) | ||
} | ||
} | ||
|
||
return nil | ||
} |
227 changes: 227 additions & 0 deletions
227
google-beta/services/netapp/resource_netapp_volume_quotaRule_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,227 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package netapp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
|
||
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" | ||
) | ||
|
||
func TestAccNetappVolumeQuotaRule_netappVolumeQuotaRuleBasicExample_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
context := map[string]interface{}{ | ||
"network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "gcnv-network-config-1", acctest.ServiceNetworkWithParentService("netapp.servicenetworking.goog")), | ||
"random_suffix": acctest.RandString(t, 10), | ||
} | ||
|
||
acctest.VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { acctest.AccTestPreCheck(t) }, | ||
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), | ||
CheckDestroy: testAccCheckNetappVolumeQuotaRuleDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNetappVolumeQuotaRule_netappVolumeQuotaRuleFull(context), | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_default_user_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_default_group_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_individual_user_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_individual_group_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
Config: testAccNetappVolumeQuotaRule_netappVolumeQuotaRuleFull_update(context), | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_default_user_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_default_group_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_individual_user_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_quota_rule.test_individual_group_quota_rule", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "volume_name"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNetappVolumeQuotaRule_netappVolumeQuotaRuleFull(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_netapp_storage_pool" "default" { | ||
name = "tf-test-test-pool%{random_suffix}" | ||
location = "us-west2" | ||
service_level = "PREMIUM" | ||
capacity_gib = 2048 | ||
network = data.google_compute_network.default.id | ||
} | ||
resource "google_netapp_volume" "default" { | ||
location = google_netapp_storage_pool.default.location | ||
name = "tf-test-test-volume%{random_suffix}" | ||
capacity_gib = 100 | ||
share_name = "tf-test-test-volume%{random_suffix}" | ||
storage_pool = google_netapp_storage_pool.default.name | ||
protocols = ["NFSV3"] | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_default_user_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-default-user-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "DEFAULT_USER_QUOTA" | ||
disk_limit_mib = 15 | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_default_group_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-default-group-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
labels = { | ||
key = "test" | ||
value = "quota_rule" | ||
} | ||
type = "DEFAULT_GROUP_QUOTA" | ||
disk_limit_mib = 20 | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_individual_user_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-individual-user-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "INDIVIDUAL_USER_QUOTA" | ||
disk_limit_mib = 25 | ||
target = "001" | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_individual_group_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-individual-group-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "INDIVIDUAL_GROUP_QUOTA" | ||
disk_limit_mib = 30 | ||
target = "011" | ||
} | ||
data "google_compute_network" "default" { | ||
name = "%{network_name}" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccNetappVolumeQuotaRule_netappVolumeQuotaRuleFull_update(context map[string]interface{}) string { | ||
return acctest.Nprintf(` | ||
resource "google_netapp_storage_pool" "default" { | ||
name = "tf-test-test-pool%{random_suffix}" | ||
location = "us-west2" | ||
service_level = "PREMIUM" | ||
capacity_gib = 2048 | ||
network = data.google_compute_network.default.id | ||
} | ||
resource "google_netapp_volume" "default" { | ||
location = google_netapp_storage_pool.default.location | ||
name = "tf-test-test-volume%{random_suffix}" | ||
capacity_gib = 100 | ||
share_name = "tf-test-test-volume%{random_suffix}" | ||
storage_pool = google_netapp_storage_pool.default.name | ||
protocols = ["NFSV3"] | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_default_user_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-default-user-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "DEFAULT_USER_QUOTA" | ||
disk_limit_mib = 35 | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_default_group_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-default-group-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
labels = { | ||
key = "test" | ||
value = "quota_rule" | ||
} | ||
type = "DEFAULT_GROUP_QUOTA" | ||
disk_limit_mib = 40 | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_individual_user_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-individual-user-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "INDIVIDUAL_USER_QUOTA" | ||
disk_limit_mib = 45 | ||
target = "001" | ||
} | ||
resource "google_netapp_volume_quota_rule" "test_individual_group_quota_rule" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "tf-individual-group-quota-rule%{random_suffix}" | ||
description = "This is a test description" | ||
type = "INDIVIDUAL_GROUP_QUOTA" | ||
disk_limit_mib = 50 | ||
target = "011" | ||
} | ||
data "google_compute_network" "default" { | ||
name = "%{network_name}" | ||
} | ||
`, context) | ||
} |
Oops, something went wrong.