diff --git a/mmv1/products/netapp/VolumeSnapshot.yaml b/mmv1/products/netapp/VolumeSnapshot.yaml new file mode 100644 index 000000000000..237c60232763 --- /dev/null +++ b/mmv1/products/netapp/VolumeSnapshot.yaml @@ -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 diff --git a/mmv1/templates/terraform/examples/volume_snapshot_create.tf.erb b/mmv1/templates/terraform/examples/volume_snapshot_create.tf.erb new file mode 100644 index 000000000000..552019daabd5 --- /dev/null +++ b/mmv1/templates/terraform/examples/volume_snapshot_create.tf.erb @@ -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'] %>" +} diff --git a/mmv1/third_party/terraform/services/netapp/resource_netapp_volume_snapshot_test.go b/mmv1/third_party/terraform/services/netapp/resource_netapp_volume_snapshot_test.go new file mode 100644 index 000000000000..7198d08202ea --- /dev/null +++ b/mmv1/third_party/terraform/services/netapp/resource_netapp_volume_snapshot_test.go @@ -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) +}