Skip to content

Commit

Permalink
Added backup support for google_filestore_instance (#6742)
Browse files Browse the repository at this point in the history
Co-authored-by: Cameron Thornton <camthornton@google.com>
fixes hashicorp/terraform-provider-google#7655
  • Loading branch information
googlerjk authored Dec 9, 2022
1 parent 25e4cdb commit 2f6206c
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 0 deletions.
114 changes: 114 additions & 0 deletions mmv1/products/filestore/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ objects:
File share capacity in GiB. This must be at least 1024 GiB
for the standard tier, or 2560 GiB for the premium tier.
required: true
- !ruby/object:Api::Type::String
name: 'sourceBackup'
output: true
description: |
The resource name of the backup, in the format
projects/{projectId}/locations/{locationId}/backups/{backupId},
that this file share has been restored from.
- !ruby/object:Api::Type::Array
name: 'nfsExportOptions'
description: |
Expand Down Expand Up @@ -327,3 +334,110 @@ objects:
description: |
The amount of bytes needed to allocate a full copy of the snapshot content.
output: true
- !ruby/object:Api::Resource
name: 'Backup'
create_url: projects/{{project}}/locations/{{location}}/backups?backupId={{name}}
self_link: projects/{{project}}/locations/{{location}}/backups/{{name}}
base_url: projects/{{project}}/locations/{{location}}/backups
update_verb: :PATCH
update_mask: true
description: |
A Google Cloud Filestore backup.
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
'Official Documentation':
'https://cloud.google.com/filestore/docs/backups'
'Creating Backups':
'https://cloud.google.com/filestore/docs/create-backups'
api: 'https://cloud.google.com/filestore/docs/reference/rest/v1/projects.locations.instances.backups'
parameters:
- !ruby/object:Api::Type::String
name: 'location'
description: |
The name of the location of the instance. This can be a region for ENTERPRISE tier instances.
input: true
required: true
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: |
The resource name of the backup. The name must be unique within the specified instance.
The name must be 1-63 characters long, and comply with
RFC1035. Specifically, the name must be 1-63 characters long and match
the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the
first character must be a lowercase letter, and all following
characters must be a dash, lowercase letter, or digit, except the last
character, which cannot be a dash.
required: true
input: true
url_param_only: true
pattern: projects/{{project}}/locations/{{location}}/backups/{{backupId}}
- !ruby/object:Api::Type::String
name: 'description'
description: |
A description of the backup with 2048 characters or less. Requests with longer descriptions will be rejected.
- !ruby/object:Api::Type::Enum
name: 'state'
description: |
The backup state.
values:
- :STATE_UNSPECIFIED
- :FINALIZING
- :CREATING
- :READY
- :DELETING
output: true
- !ruby/object:Api::Type::Time
name: 'createTime'
description: |
The time when the snapshot was created in RFC3339 text format.
output: true
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: |
Resource labels to represent user-provided metadata.
- !ruby/object:Api::Type::String
name: 'capacityGb'
description: |
The amount of bytes needed to allocate a full copy of the snapshot content.
output: true
- !ruby/object:Api::Type::String
name: 'storageBytes'
description: |
The size of the storage used by the backup. As backups share storage, this number is expected to change with backup creation/deletion.
output: true
- !ruby/object:Api::Type::String
name: 'sourceInstance'
description: |
The resource name of the source Cloud Filestore instance, in the format projects/{projectId}/locations/{locationId}/instances/{instanceId}, used to create this backup.
required: true
- !ruby/object:Api::Type::String
name: 'sourceFileShare'
description: |
Name of the file share in the source Cloud Filestore instance that the backup is created from.
input: true
required: true
- !ruby/object:Api::Type::Enum
name: 'sourceInstanceTier'
description: |
The service tier of the source Cloud Filestore instance that this backup is created from.
values:
- :STANDARD
- :PREMIUM
- :BASIC_HDD
- :BASIC_SSD
- :HIGH_SCALE_SSD
- :ENTERPRISE
output: true
- !ruby/object:Api::Type::String
name: 'downloadBytes'
description: |
Amount of bytes that will be downloaded if the backup is restored.
output: true
- !ruby/object:Api::Type::String
name: 'kmsKeyName'
description: |
KMS key name used for data encryption.
output: true
10 changes: 10 additions & 0 deletions mmv1/products/filestore/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ overrides: !ruby/object:Overrides::ResourceOverrides
custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: templates/terraform/constants/filestore.erb
pre_create: templates/terraform/pre_create/filestore_instance.go.erb
Backup: !ruby/object:Overrides::Terraform::ResourceOverride
mutex: "filestore/{{project}}"
error_retry_predicates: ["isNotFilestoreQuotaError"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "filestore_backup_basic"
primary_resource_id: "backup"
vars:
backup_name: "tf-fs-bkup"
instance_name: "tf-fs-inst"
Snapshot: !ruby/object:Overrides::Terraform::ResourceOverride
mutex: "filestore/{{project}}"
error_retry_predicates: ["isNotFilestoreQuotaError"]
Expand Down
31 changes: 31 additions & 0 deletions mmv1/templates/terraform/examples/filestore_backup_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

resource "google_filestore_instance" "instance" {
name = "<%= ctx[:vars]["instance_name"] %>"
location = "us-central1-b"
tier = "BASIC_SSD"

file_shares {
capacity_gb = 2560
name = "share1"
}

networks {
network = "default"
modes = ["MODE_IPV4"]
connect_mode = "DIRECT_PEERING"
}
}

resource "google_filestore_backup" "<%= ctx[:primary_resource_id] %>" {
name = "<%= ctx[:vars]["backup_name"] %>"
location = "us-central1"
source_instance = google_filestore_instance.instance.id
source_file_share = "share1"

description = "This is a filestore backup for the test instance"
labels = {
"files":"label1",
"other-label": "label2"
}
}

115 changes: 115 additions & 0 deletions mmv1/third_party/terraform/tests/resource_filestore_backup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccFilestoreBackup_update(t *testing.T) {
t.Parallel()

instName := fmt.Sprintf("tf-fs-inst-%d", randInt(t))
bkupName := fmt.Sprintf("tf-fs-bkup-%d", randInt(t))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFilestoreBackupDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccFilestoreBackup_create(instName, bkupName),
},
{
ResourceName: "google_filestore_backup.backup",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"location"},
},
{
Config: testAccFilestoreBackup_update(instName, bkupName),
},
{
ResourceName: "google_filestore_backup.backup",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"labels", "description", "location"},
},
},
})
}

func testAccFilestoreBackup_create(instName string, bkupName string) string {
return fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "%s"
location = "us-central1-b"
tier = "BASIC_SSD"
file_shares {
capacity_gb = 2560
name = "share22"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
connect_mode = "DIRECT_PEERING"
}
description = "An instance created during testing."
}
resource "google_filestore_backup" "backup" {
name = "%s"
location = "us-central1"
source_instance = google_filestore_instance.instance.id
source_file_share = "share22"
description = "This is a filestore backup for the test instance"
}
`, instName, bkupName)
}

func testAccFilestoreBackup_update(instName string, bkupName string) string {
return fmt.Sprintf(`
resource "google_filestore_instance" "instance" {
name = "%s"
location = "us-central1-b"
tier = "BASIC_SSD"
file_shares {
capacity_gb = 2560
name = "share22"
}
networks {
network = "default"
modes = ["MODE_IPV4"]
connect_mode = "DIRECT_PEERING"
}
labels = {
"files":"label1",
"other-label": "update"
}
description = "A modified instance during testing."
}
resource "google_filestore_backup" "backup" {
name = "%s"
location = "us-central1"
source_instance = google_filestore_instance.instance.id
source_file_share = "share22"
description = "This is an updated filestore backup for the test instance"
labels = {
"files":"label1",
"other-label": "update"
}
}
`, instName, bkupName)
}

0 comments on commit 2f6206c

Please sign in to comment.