forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Support for Snapshot module for Google Cloud Netapp Volume (Go…
…ogleCloudPlatform#9812) * initial snap commit * yaml lint fix * updated test files and descriptions * updated volume snapshot resource name * removed volumesnapshot * updated VolumeSnapshot file name * filename fixes
- Loading branch information
1 parent
9a27a9d
commit f32c913
Showing
3 changed files
with
239 additions
and
0 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,83 @@ | ||
# Copyright 2023 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Resource | ||
name: 'VolumeSnapshot' | ||
description: | | ||
NetApp Volumes helps you manage your data usage with snapshots that can quickly restore lost data. | ||
Snapshots are point-in-time versions of your volume's content. They are resources of volumes and are | ||
instant captures of your data that consume space only for modified data. Because data changes over | ||
time, snapshots usually consume more space as they get older. | ||
NetApp Volumes volumes use just-in-time copy-on-write so that unmodified files in snapshots don't | ||
consume any of the volume's capacity. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Documentation': 'https://cloud.google.com/netapp/volumes/docs/configure-and-use/volume-snapshots/overview' | ||
api: 'https://cloud.google.com/netapp/volumes/docs/reference/rest/v1/projects.locations.volumes.snapshots' | ||
base_url: projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/snapshots | ||
self_link: projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/snapshots/{{name}} | ||
create_url: projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/snapshots?snapshotId={{name}} | ||
update_url: projects/{{project}}/locations/{{location}}/volumes/{{volume_name}}/snapshots/{{name}} | ||
update_verb: :PATCH | ||
update_mask: true | ||
autogen_async: true | ||
async: !ruby/object:Api::OpAsync | ||
operation: !ruby/object:Api::OpAsync::Operation | ||
base_url: '{{op_id}}' | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: 'location' | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
description: | | ||
Name of the snapshot location. Snapshots are child resources of volumes and live in the same location. | ||
- !ruby/object:Api::Type::String | ||
name: 'volume_name' | ||
description: | | ||
The name of the volume to create the snapshot in. | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
- !ruby/object:Api::Type::String | ||
name: 'name' | ||
description: | ||
The name of the snapshot. | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: 'volume_snapshot_create' | ||
primary_resource_id: 'test_snapshot' | ||
vars: | ||
volume_name: 'test-volume' | ||
pool_name: 'test-pool' | ||
network_name: 'test-network' | ||
snap_name: 'testvolumesnap' | ||
test_vars_overrides: | ||
network_name: 'acctest.BootstrapSharedServiceNetworkingConnection(t, "gcnv-network-config-1", acctest.ServiceNetworkWithParentService("netapp.servicenetworking.goog"))' | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: 'description' | ||
description: | | ||
Description for the snapshot. | ||
- !ruby/object:Api::Type::KeyValueLabels | ||
name: 'labels' | ||
description: | | ||
Labels as key value pairs. Example: `{ "owner": "Bob", "department": "finance", "purpose": "testing" }`. | ||
- !ruby/object:Api::Type::Integer | ||
name: 'usedBytes' | ||
description: | | ||
Storage used to store blocks unique to this snapshot. | ||
output: true |
27 changes: 27 additions & 0 deletions
27
mmv1/templates/terraform/examples/volume_snapshot_create.tf.erb
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,27 @@ | ||
resource "google_netapp_storage_pool" "default" { | ||
name = "<%= ctx[:vars]['pool_name'] %>" | ||
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 = "<%= ctx[:vars]['volume_name'] %>" | ||
capacity_gib = 100 | ||
share_name = "<%= ctx[:vars]['volume_name'] %>" | ||
storage_pool = google_netapp_storage_pool.default.name | ||
protocols = ["NFSV3"] | ||
} | ||
|
||
resource "google_netapp_volume_snapshot" "<%= ctx[:primary_resource_id] %>" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
name = "<%= ctx[:vars]['snap_name'] %>" | ||
} | ||
|
||
data "google_compute_network" "default" { | ||
name = "<%= ctx[:vars]['network_name'] %>" | ||
} |
129 changes: 129 additions & 0 deletions
129
mmv1/third_party/terraform/services/netapp/resource_netapp_volume_snapshot_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,129 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package netapp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/hashicorp/terraform-provider-google/google/acctest" | ||
) | ||
|
||
func TestAccNetappVolumeSnapshot_volumeSnapshotCreateExample_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: testAccCheckNetappVolumeSnapshotDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNetappVolumeSnapshot_volumeSnapshotCreateExample_full(context), | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_snapshot.test_snapshot", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"location", "volume_name", "name", "labels", "terraform_labels"}, | ||
}, | ||
{ | ||
Config: testAccNetappVolumeSnapshot_volumeSnapshotCreateExample_update(context), | ||
}, | ||
{ | ||
ResourceName: "google_netapp_volume_snapshot.test_snapshot", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
ImportStateVerifyIgnore: []string{"location", "volume_name", "name", "labels", "terraform_labels"}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNetappVolumeSnapshot_volumeSnapshotCreateExample_full(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_snapshot" "test_snapshot" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
description = "This is a test description" | ||
name = "testvolumesnap%{random_suffix}" | ||
labels = { | ||
key= "test" | ||
value= "snapshot" | ||
} | ||
} | ||
data "google_compute_network" "default" { | ||
name = "%{network_name}" | ||
} | ||
`, context) | ||
} | ||
|
||
func testAccNetappVolumeSnapshot_volumeSnapshotCreateExample_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_snapshot" "test_snapshot" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
description = "This is a update description" | ||
name = "testvolumesnap%{random_suffix}" | ||
labels = { | ||
key= "test" | ||
value= "snapshot_update" | ||
} | ||
} | ||
resource "google_netapp_volume_snapshot" "test_snapshot2" { | ||
depends_on = [google_netapp_volume.default] | ||
location = google_netapp_volume.default.location | ||
volume_name = google_netapp_volume.default.name | ||
description = "This is a update description" | ||
name = "testvolumesnap2%{random_suffix}" | ||
} | ||
data "google_compute_network" "default" { | ||
name = "%{network_name}" | ||
} | ||
`, context) | ||
} |