Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing field to disks and support InstantSnapshot #12946

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion mmv1/products/compute/Disk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ properties:
description: |
The service account used for the encryption request for the given KMS key.
If absent, the Compute Engine Service Agent service account is used.
- name: 'sourceInstantSnapshot'
type: String
description: |
The source instant snapshot used to create this disk. You can provide this as a partial or full URL to the resource.
For example, the following are valid values:

* `https://www.googleapis.com/compute/v1/projects/project/zones/zone/instantSnapshots/instantSnapshot`
* `projects/project/zones/zone/instantSnapshots/instantSnapshot`
* `zones/zone/instantSnapshots/instantSnapshot`

api_name: sourceInstantSnapshot
resource: 'Snapshot'
imports: 'selfLink'
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
- name: 'sourceInstantSnapshotId'
type: String
description: |
The unique ID of the instant snapshot used to create this disk. This value identifies
the exact instant snapshot that was used to create this persistent disk.
For example, if you created the persistent disk from an instant snapshot that was later
deleted and recreated under the same name, the source instant snapshot ID would identify
the exact version of the instant snapshot that was used.
output: true
- name: 'sourceImageId'
type: String
description: |
Expand Down Expand Up @@ -249,7 +272,16 @@ properties:
snapshot ID would identify the exact version of the snapshot that was
used.
output: true

- name: 'sourceStorageObject'
type: String
description: |
The full Google Cloud Storage URI where the disk image is stored.
This file must be a gzip-compressed tarball whose name ends in .tar.gz or virtual machine disk whose name ends in vmdk.
Valid URIs may start with gs:// or https://storage.googleapis.com/.
This flag is not optimized for creating multiple disks from a source storage object.
To create many disks from a source storage object, use gcloud compute images import instead.
api_name: sourceStorageObject
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
- name: 'labelFingerprint'
type: Fingerprint
description: |
Expand Down Expand Up @@ -460,6 +492,27 @@ properties:
description: |
Primary disk for asynchronous disk replication.
required: true
- name: 'architecture'
type: String
The architecture of the disk.
enum_values:
- 'X86_64'
- 'ARM64'
- name: 'params'
type: NestedObject
ignore_read: true
immutable: true
description: |
Additional params passed with the request, but not persisted as part of resource payload
properties:
- name: 'resourceManagerTags'
type: KeyValuePairs
description: |
Resource manager tags to be bound to the disk. Tag keys and values have the
same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id},
and values are in the format tagValues/456.
api_name: resourceManagerTags
ignore_read: true
- name: 'guestOsFeatures'
type: Array
description: |
Expand Down
104 changes: 104 additions & 0 deletions mmv1/products/compute/InstantSnapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
karolgorc marked this conversation as resolved.
Show resolved Hide resolved
name: 'InstantSnapshot'
kind: 'compute#instantSnapshot'
description: |
Represents an instant snapshot resource.

An instant snapshot is an in-place backup of a disk that can be used to rapidly create a new disk in minutes.

Instant snapshots capture data at a specific point in time. They are optimized for rapidly restoring captured
data to a new disk. Use instant snapshots to quickly recover data in cases where the zone and disk are still intact
but the data on the disk has been lost or corrupted
references:
guides:
'Official Documentation': 'https://cloud.google.com/compute/docs/disks/instant-snapshots'
api: 'https://cloud.google.com/compute/docs/reference/rest/v1/instantSnapshots'
docs:
base_url: 'projects/{{project}}/zones/{{zone}}/instantSnapshots'
has_self_link: true
immutable: true
timeouts:
insert_minutes: 20
update_minutes: 20
delete_minutes: 20
async:
actions: ['create', 'delete', 'update']
type: 'OpAsync'
operation:
full_url: 'selfLink'
result:
resource_inside_response: false
collection_url_key: 'items'
iam_policy:
parent_resource_attribute: 'name'
example_config_body: 'templates/terraform/iam/iam_attributes.go.tmpl'
import_format:
- 'projects/{{project}}/zones/{{zone}}/instantSnapshots/{{name}}'
examples:
- name: 'instant_snapshot_basic'
primary_resource_id: 'default'
primary_resource_name: 'fmt.Sprintf("tf-test-instant-snapshot%s", context["random_suffix"])'
vars:
instance_name: 'instant-snapshot'
parameters:
- name: 'sourceDisk'
type: ResourceRef
description: 'A reference to the disk used to create this instant snapshot.'
required: true
immutable: true
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
resource: 'Disk'
imports: 'name'
- name: 'zone'
type: ResourceRef
description: 'A reference to the zone where the disk is located.'
immutable: true
required: true
diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName'
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
resource: 'Zone'
imports: 'name'
properties:
- name: 'creationTimestamp'
type: Time
description: 'Creation timestamp in RFC3339 text format.'
output: true
- name: 'name'
type: String
description: |
Name of the resource; provided by the client when the resource is
created. 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
immutable: true
- name: 'description'
type: String
description: 'An optional description of this resource.'
required: false
- name: 'sourceDiskId'
type: String
description: 'The ID value of the disk used to create this InstantSnapshot.'
output: true
- name: 'diskSizeGb'
type: Integer
description: 'Size of the snapshot, specified in GB.'
output: true
- name: 'labels'
type: KeyValueLabels
description: Labels to apply to this InstantSnapshot.
update_url: 'projects/{{project}}/zones{{zone}}/instantSnapshots/{{name}}/setLabels'
update_verb: 'POST'
- name: 'labelFingerprint'
type: Fingerprint
description: |
The fingerprint used for optimistic locking of this resource. Used
internally during updates.
output: true
update_url: 'projects/{{project}}/zones/{{zone}}/instantSnapshots/{{name}}/setLabels'
karolgorc marked this conversation as resolved.
Show resolved Hide resolved
update_verb: 'POST'
key_expander: ''
10 changes: 10 additions & 0 deletions mmv1/templates/terraform/examples/instant_snapshot_basic.tf.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "google_compute_disk" "foo" {
name = "foo"
type = "pd-ssd"
size = 10
}

resource "google_compute_instant_snapshot" "{{$.PrimaryResourceId}}" {
name = "{{index $.Vars "instance_name"}}"
source_disk = google_compute_disk.foo.self_link
}
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,120 @@ func TestAccComputeDisk_cloneDisk(t *testing.T) {
})
}

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

context_1 := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"architecture": "X86_64",
}
context_2 := map[string]interface{}{
"random_suffix": context_1["random_suffix"],
"architecture": "ARM64",
}
var disk compute.Disk

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_architecture(context_1),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
t, "google_compute_disk.foobar", envvar.GetTestProjectFromEnv(), &disk),
),
},
{
Config: testAccComputeDisk_architecture(context_2),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
t, "google_compute_disk.foobar", envvar.GetTestProjectFromEnv(), &disk),
),
},
},
})
}

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

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"source_storage_object": "",
}

var disk compute.Disk

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_sourceStorageObject(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
t, "google_compute_disk.foobar", envvar.GetTestProjectFromEnv(), &disk),
),
},
},
})
}

func TestAccComputeDisk_resourceManagerTags(t *testing.T) {
t.Parallel()
pid := envvar.GetTestProjectFromEnv()
context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
"project_id": pid,
}

var disk compute.Disk

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_resourceManagerTags(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
t, "google_compute_disk.foobar", pid, &disk),
),
},
},
})
}

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

context := map[string]interface{}{
"random_suffix": acctest.RandString(t, 10),
}

var disk compute.Disk

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeDiskDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeDisk_sourceInstantSnapshot(context),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeDiskExists(
t, "google_compute_disk.foobar", envvar.GetTestProjectFromEnv(), &disk),
),
},
},
})
}


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

Expand Down Expand Up @@ -1902,3 +2016,83 @@ resource "google_compute_disk" "foobar" {
}
`, diskName, accessMode)
}

func testAccComputeDisk_architecture(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_disk" "foobar" {
name = "tf-test-disk-%{random_suffix}"
type = "pd-ssd"
size = 10
zone = "us-central1-a"
architecture = "%{architecture}"
}
`, context)
}

func testAccComputeDisk_sourceInstantSnapshot(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_disk" "to-snapshot" {
name = "tf-test-disk-1-%{random_suffix}"
type = "pd-ssd"
size = 10
zone = "us-central1-a"
}

resource "google_compute_instant_snapshot" "test" {
name = "tf-test-instant-snapshot-%{random_suffix}"
zone = "us-central1-a"
source_disk = google_compute_disk.to-snapshot.id
}

resource "google_compute_disk" "foobar" {
name = "tf-test-disk-2-%{random_suffix}"
type = "pd-ssd"
size = 10
zone = "us-central1-a"
source_instant_snapshot = google_compute_instant_snapshot.test.id
}
`, context)
}

func testAccComputeDisk_sourceStorageObject(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_storage_bucket" "bucket" {
name = "tf-test-bucket-%{random_suffix}"
location = "US"
}

resource "google_compute_disk" "foobar" {
name = "tf-test-disk-%{random_suffix}"
type = "pd-ssd"
size = 10
zone = "us-central1-a"
source_storage_object = "%{source_storage_object}"
}
`, context)
}

func testAccComputeDisk_resourceManagerTags(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_tags_tag_key" "tag_key" {
parent = "projects/%{project_id}"
short_name = "test"
}

resource "google_tags_tag_value" "tag_value" {
parent = "tagKeys/${google_tags_tag_key.tag_key.name}"
short_name = "name"
}

resource "google_compute_disk" "foobar" {
name = "tf-test-disk-%{random_suffix}"
type = "pd-ssd"
size = 10
zone = "us-central1-a"
params {
resource_manager_tags = {
"${google_tags_tag_key.tag_key.id}" = "${google_tags_tag_value.tag_value.id}"
}
}
}
`, context)
}
Loading
Loading