Skip to content

Commit bec003d

Browse files
committed
2 parents 6e57cd7 + 59e9b08 commit bec003d

13 files changed

Lines changed: 516 additions & 6 deletions

mmv1/products/compute/Instance.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,3 +720,10 @@ properties:
720720
comply with RFC1035.
721721
item_type:
722722
type: String
723+
- name: 'eraseWindowsVssSignature'
724+
type: Boolean
725+
description: |
726+
Specifies whether the disks restored from source snapshots or source machine image should erase Windows specific VSS signature.
727+
min_version: 'beta'
728+
ignore_read: true
729+
default_value: false

mmv1/products/datastream/PrivateConnection.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ examples:
5252
vars:
5353
private_connection_id: 'my-connection'
5454
network_name: 'my-network'
55+
ignore_read_extra:
56+
- 'deletion_policy'
57+
- name: 'datastream_private_connection_force_delete'
58+
primary_resource_id: 'default'
59+
vars:
60+
private_connection_id: 'my-connection'
61+
network_name: 'my-network'
62+
ignore_read_extra:
63+
- 'deletion_policy'
5564
- name: 'datastream_private_connection_psc_interface'
5665
primary_resource_id: 'default'
5766
test_env_vars:
@@ -64,6 +73,17 @@ examples:
6473
network_attachment_name: 'my-network-attachment'
6574
network_name: 'my-network'
6675
subnetwork_name: 'my-subnetwork'
76+
ignore_read_extra:
77+
- 'deletion_policy'
78+
virtual_fields:
79+
- name: 'deletion_policy'
80+
description: |
81+
The deletion policy for the private connection. Setting `FORCE` will also delete any child
82+
routes that belong to this private connection. Setting `DEFAULT` will fail the delete if
83+
child routes exist. Defaults to `FORCE` for backwards compatibility.
84+
Possible values: `DEFAULT`, `FORCE`.
85+
type: String
86+
default_value: "FORCE"
6787
parameters:
6888
- name: 'privateConnectionId'
6989
type: String

mmv1/products/tags/TagKey.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ properties:
125125
126126
Purpose data corresponds to the policy system that the tag is intended for. For example, the GCE_FIREWALL purpose expects data in the following format: `network = "<project-name>/<vpc-name>"`.
127127
immutable: true
128-
ignore_read: true
129128
- name: 'allowedValuesRegex'
130129
type: String
131130
description: |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "google_datastream_private_connection" "{{$.PrimaryResourceId}}" {
2+
display_name = "Connection profile"
3+
location = "us-central1"
4+
private_connection_id = "{{index $.Vars "private_connection_id"}}"
5+
deletion_policy = "FORCE"
6+
7+
labels = {
8+
key = "value"
9+
}
10+
11+
vpc_peering_config {
12+
vpc = google_compute_network.default.id
13+
subnet = "10.0.0.0/29"
14+
}
15+
}
16+
17+
resource "google_compute_network" "default" {
18+
name = "{{index $.Vars "network_name"}}"
19+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Add force=true query param to force deletion of private connection sub resources like Routes
2-
url, err = transport_tpg.AddQueryParams(url, map[string]string{"force": strconv.FormatBool(true)})
3-
if err != nil {
4-
return err
5-
}
1+
// Add force=true query param if deletion_policy is FORCE to delete child routes
2+
if deletionPolicy := d.Get("deletion_policy"); deletionPolicy == "FORCE" {
3+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"force": strconv.FormatBool(true)})
4+
if err != nil {
5+
return err
6+
}
7+
}

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,15 @@ be from 0 to 999,999,999 inclusive.`,
16711671
},
16721672
},
16731673
},
1674+
{{- if ne $.TargetVersionName `ga` }}
1675+
"erase_windows_vss_signature": {
1676+
Type: schema.TypeBool,
1677+
Optional: true,
1678+
ForceNew: true,
1679+
Default: false,
1680+
Description: `Specifies whether the disks restored from source snapshots or source machine image should erase Windows specific VSS signature.`,
1681+
},
1682+
{{- end }}
16741683
},
16751684
CustomizeDiff: customdiff.All(
16761685
tpgresource.DefaultProviderProject,
@@ -1850,6 +1859,9 @@ func expandComputeInstance(project string, d *schema.ResourceData, config *trans
18501859
ReservationAffinity: reservationAffinity,
18511860
KeyRevocationActionType: d.Get("key_revocation_action_type").(string),
18521861
InstanceEncryptionKey: expandComputeInstanceEncryptionKey(d),
1862+
{{- if ne $.TargetVersionName `ga` }}
1863+
EraseWindowsVssSignature: d.Get("erase_windows_vss_signature").(bool),
1864+
{{- end }}
18531865
}, nil
18541866
}
18551867

@@ -2321,6 +2333,16 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
23212333
return fmt.Errorf("Error setting instance_encryption_key: %s", err)
23222334
}
23232335

2336+
{{- if ne $.TargetVersionName `ga` }}
2337+
// If not forced to false, upgrading to a new provider version and subsequently changing a vm property
2338+
// will trigger replacement when erase_windows_vss_signature = null in state is changed to false as part of a refresh
2339+
if _, ok := d.GetOkExists("erase_windows_vss_signature"); !ok {
2340+
if err := d.Set("erase_windows_vss_signature", false); err != nil {
2341+
return fmt.Errorf("Error setting erase_windows_vss_signature: %s", err)
2342+
}
2343+
}
2344+
{{- end }}
2345+
23242346
d.SetId(fmt.Sprintf("projects/%s/zones/%s/instances/%s", project, zone, instance.Name))
23252347

23262348
return nil
@@ -3573,6 +3595,15 @@ func resourceComputeInstanceImportState(d *schema.ResourceData, meta interface{}
35733595
if err != nil {
35743596
return nil, fmt.Errorf("Error constructing id: %s", err)
35753597
}
3598+
3599+
{{- if ne $.TargetVersionName `ga` }}
3600+
// erase_windows_vss_signature is not a property of a vm so force to false on import.
3601+
// If not set, value is null in state and will cause replacement if a vm property is subsequently updated (eg. machine_type).
3602+
if err := d.Set("erase_windows_vss_signature", false); err != nil {
3603+
return nil, fmt.Errorf("Error setting erase_windows_vss_signature: %s", err)
3604+
}
3605+
{{- end }}
3606+
35763607
d.SetId(id)
35773608

35783609
return []*schema.ResourceData{d}, nil

mmv1/third_party/terraform/services/compute/resource_compute_instance_from_machine_image_meta.yaml.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,7 @@ fields:
259259
- field: 'terraform_labels'
260260
provider_only: true
261261
- api_field: 'zone'
262+
{{- if ne $.TargetVersionName "ga" }}
263+
- api_field: 'eraseWindowsVssSignature'
264+
{{- end }}
262265
{{ end }}

mmv1/third_party/terraform/services/compute/resource_compute_instance_from_machine_image_test.go.tmpl

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,54 @@ func TestAccComputeInstanceFromMachineImage_withSourceMachineImageEncryptionKey(
374374
})
375375
}
376376

377+
{{ if ne $.TargetVersionName `ga` -}}
378+
func TestAccComputeInstanceFromMachineImage_VSSWindows(t *testing.T) {
379+
t.Parallel()
380+
381+
var instance compute.Instance
382+
383+
context_1 := map[string]interface{}{
384+
"instance1_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
385+
"image_name": fmt.Sprintf("tf-test-image-%s", acctest.RandString(t, 10)),
386+
"instance2_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
387+
"vss_flag": true,
388+
"guest_flush": true,
389+
}
390+
context_2 := map[string]interface{}{
391+
"instance1_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
392+
"image_name": fmt.Sprintf("tf-test-image-%s", acctest.RandString(t, 10)),
393+
"instance2_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
394+
"vss_flag": false,
395+
"guest_flush": false,
396+
}
397+
398+
acctest.VcrTest(t, resource.TestCase{
399+
PreCheck: func() { acctest.AccTestPreCheck(t) },
400+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
401+
ExternalProviders: map[string]resource.ExternalProvider{
402+
"time": {},
403+
},
404+
CheckDestroy: testAccCheckComputeInstanceFromMachineImageDestroyProducer(t),
405+
Steps: []resource.TestStep{
406+
{
407+
Config: testAccComputeInstanceFromMachineImage_VSSWindows(context_1),
408+
Check: resource.ComposeTestCheckFunc(
409+
testAccCheckComputeInstanceExists(
410+
t, "google_compute_instance_from_machine_image.foobar", &instance),
411+
),
412+
},
413+
{
414+
Config: testAccComputeInstanceFromMachineImage_VSSWindows(context_2),
415+
Check: resource.ComposeTestCheckFunc(
416+
testAccCheckComputeInstanceExists(
417+
t, "google_compute_instance_from_machine_image.foobar", &instance),
418+
),
419+
},
420+
},
421+
})
422+
}
423+
{{- end }}
424+
377425
func testAccCheckComputeInstanceFromMachineImageDestroyProducer(t *testing.T) func(s *terraform.State) error {
378426
return func(s *terraform.State) error {
379427
config := acctest.GoogleProviderConfig(t)
@@ -1440,6 +1488,74 @@ resource "google_compute_instance_from_machine_image" "foobar" {
14401488
`, context)
14411489
}
14421490

1491+
{{ if ne $.TargetVersionName `ga` -}}
1492+
func testAccComputeInstanceFromMachineImage_VSSWindows(context map[string]interface{}) string {
1493+
return acctest.Nprintf(`
1494+
data "google_compute_image" "my_image" {
1495+
provider = google-beta
1496+
1497+
family = "windows-2025"
1498+
project = "windows-cloud"
1499+
}
1500+
1501+
// Takes about 3 minutes for vm to be fully ready
1502+
resource "google_compute_instance" "initialvm" {
1503+
provider = google-beta
1504+
1505+
name = "%{instance1_name}"
1506+
machine_type = "e2-standard-2"
1507+
zone = "us-central1-a"
1508+
1509+
boot_disk {
1510+
initialize_params {
1511+
image = data.google_compute_image.my_image.self_link
1512+
type = "pd-ssd"
1513+
}
1514+
}
1515+
1516+
network_interface {
1517+
network = "default"
1518+
}
1519+
1520+
}
1521+
1522+
// Need to wait for initialvm to be fully ready otherwise snapshot with guest_flush = true will fail.
1523+
resource "time_sleep" "wait_240_seconds" {
1524+
create_duration = "240s"
1525+
depends_on = [google_compute_instance.initialvm]
1526+
}
1527+
1528+
resource "google_compute_machine_image" "foobar" {
1529+
provider = google-beta
1530+
1531+
name = "%{image_name}"
1532+
source_instance = google_compute_instance.initialvm.self_link
1533+
guest_flush = "%{guest_flush}"
1534+
depends_on = [ time_sleep.wait_240_seconds ]
1535+
1536+
// guest_flush is not a property of machine_image and therefore always ends up as false in the state.
1537+
// To properly test erase_windows_vss_signature = true, guest_flush would need to be true.
1538+
// However, after apply, a plan will always show a diff because guest_flush is false in state.
1539+
// We therefore need to ignore this field; otherwise, the test fails
1540+
lifecycle {
1541+
ignore_changes = [guest_flush]
1542+
}
1543+
}
1544+
1545+
resource "google_compute_instance_from_machine_image" "foobar" {
1546+
provider = google-beta
1547+
1548+
name = "%{instance2_name}"
1549+
zone = "us-central1-a"
1550+
1551+
source_machine_image = google_compute_machine_image.foobar.self_link
1552+
1553+
erase_windows_vss_signature = %{vss_flag}
1554+
1555+
}
1556+
`, context)
1557+
}
1558+
{{- end }}
14431559
{{- else }}
14441560
// Magic Modules doesn't let us remove files - blank out beta-only common-compile files for now.
14451561
{{- end }}

mmv1/third_party/terraform/services/compute/resource_compute_instance_from_template_meta.yaml.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,6 @@ fields:
272272
- field: 'terraform_labels'
273273
provider_only: true
274274
- api_field: 'zone'
275+
{{- if ne $.TargetVersionName "ga" }}
276+
- api_field: 'eraseWindowsVssSignature'
277+
{{- end }}

mmv1/third_party/terraform/services/compute/resource_compute_instance_from_template_test.go.tmpl

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,49 @@ func TestAccComputeInstanceFromTemplate_DiskForceAttach(t *testing.T) {
626626
})
627627
}
628628

629+
{{ if ne $.TargetVersionName `ga` -}}
630+
func TestAccComputeInstanceFromTemplate_VSSWindows(t *testing.T) {
631+
t.Parallel()
632+
633+
var instance compute.Instance
634+
635+
context_1 := map[string]interface{}{
636+
"bootdisk_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
637+
"template_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
638+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
639+
"vss_flag": true,
640+
}
641+
context_2 := map[string]interface{}{
642+
"bootdisk_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
643+
"template_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
644+
"instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
645+
"vss_flag": false,
646+
}
647+
648+
acctest.VcrTest(t, resource.TestCase{
649+
PreCheck: func() { acctest.AccTestPreCheck(t) },
650+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
651+
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
652+
Steps: []resource.TestStep{
653+
{
654+
Config: testAccComputeInstanceFromTemplate_VSSWindows(context_1),
655+
Check: resource.ComposeTestCheckFunc(
656+
testAccCheckComputeInstanceExists(
657+
t, "google_compute_instance_from_template.foobar", &instance),
658+
),
659+
},
660+
{
661+
Config: testAccComputeInstanceFromTemplate_VSSWindows(context_2),
662+
Check: resource.ComposeTestCheckFunc(
663+
testAccCheckComputeInstanceExists(
664+
t, "google_compute_instance_from_template.foobar", &instance),
665+
),
666+
},
667+
},
668+
})
669+
}
670+
{{- end }}
671+
629672
func testAccComputeInstanceFromTemplate_basic(instance, template string) string {
630673
return fmt.Sprintf(`
631674
data "google_compute_image" "my_image" {
@@ -2628,3 +2671,54 @@ resource "google_compute_instance_from_template" "foobar" {
26282671
}
26292672
`, context)
26302673
}
2674+
2675+
{{ if ne $.TargetVersionName `ga` -}}
2676+
func testAccComputeInstanceFromTemplate_VSSWindows(context map[string]interface{}) string {
2677+
return acctest.Nprintf(`
2678+
data "google_compute_image" "my_image" {
2679+
provider = google-beta
2680+
2681+
family = "windows-2025"
2682+
project = "windows-cloud"
2683+
}
2684+
2685+
resource "google_compute_disk" "foobarboot" {
2686+
provider = google-beta
2687+
2688+
name = "%{bootdisk_name}"
2689+
image = data.google_compute_image.my_image.self_link
2690+
size = 50
2691+
type = "pd-ssd"
2692+
zone = "us-central1-a"
2693+
}
2694+
2695+
resource "google_compute_instance_template" "foobar" {
2696+
provider = google-beta
2697+
2698+
name = "%{template_name}"
2699+
machine_type = "e2-standard-2"
2700+
2701+
disk {
2702+
source = google_compute_disk.foobarboot.name
2703+
boot = true
2704+
}
2705+
2706+
network_interface {
2707+
network = "default"
2708+
}
2709+
2710+
}
2711+
2712+
resource "google_compute_instance_from_template" "foobar" {
2713+
provider = google-beta
2714+
2715+
name = "%{instance_name}"
2716+
zone = "us-central1-a"
2717+
2718+
source_instance_template = google_compute_instance_template.foobar.self_link
2719+
2720+
erase_windows_vss_signature = %{vss_flag}
2721+
}
2722+
`, context)
2723+
}
2724+
{{- end }}

0 commit comments

Comments
 (0)