forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource_compute_instance.go
3283 lines (2915 loc) · 115 KB
/
resource_compute_instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package compute
import (
"context"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/mitchellh/hashstructure"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"github.com/hashicorp/terraform-provider-google/google/verify"
"google.golang.org/api/compute/v1"
)
func IpCidrRangeDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
// The range may be a:
// A) single IP address (e.g. 10.2.3.4)
// B) CIDR format string (e.g. 10.1.2.0/24)
// C) netmask (e.g. /24)
//
// For A) and B), no diff to suppress, they have to match completely.
// For C), The API picks a network IP address and this creates a diff of the form:
// network_interface.0.alias_ip_range.0.ip_cidr_range: "10.128.1.0/24" => "/24"
// We should only compare the mask portion for this case.
if len(new) > 0 && new[0] == '/' {
oldNetmaskStartPos := strings.LastIndex(old, "/")
if oldNetmaskStartPos != -1 {
oldNetmask := old[strings.LastIndex(old, "/"):]
if oldNetmask == new {
return true
}
}
}
return false
}
var (
advancedMachineFeaturesKeys = []string{
"advanced_machine_features.0.enable_nested_virtualization",
"advanced_machine_features.0.threads_per_core",
"advanced_machine_features.0.turbo_mode",
"advanced_machine_features.0.visible_core_count",
"advanced_machine_features.0.performance_monitoring_unit",
"advanced_machine_features.0.enable_uefi_networking",
}
bootDiskKeys = []string{
"boot_disk.0.auto_delete",
"boot_disk.0.device_name",
"boot_disk.0.disk_encryption_key_raw",
"boot_disk.0.kms_key_self_link",
"boot_disk.0.initialize_params",
"boot_disk.0.mode",
"boot_disk.0.source",
}
initializeParamsKeys = []string{
"boot_disk.0.initialize_params.0.size",
"boot_disk.0.initialize_params.0.type",
"boot_disk.0.initialize_params.0.image",
"boot_disk.0.initialize_params.0.labels",
"boot_disk.0.initialize_params.0.resource_manager_tags",
"boot_disk.0.initialize_params.0.provisioned_iops",
"boot_disk.0.initialize_params.0.provisioned_throughput",
"boot_disk.0.initialize_params.0.enable_confidential_compute",
"boot_disk.0.initialize_params.0.storage_pool",
"boot_disk.0.initialize_params.0.resource_policies",
}
schedulingKeys = []string{
"scheduling.0.on_host_maintenance",
"scheduling.0.automatic_restart",
"scheduling.0.preemptible",
"scheduling.0.node_affinities",
"scheduling.0.min_node_cpus",
"scheduling.0.provisioning_model",
"scheduling.0.instance_termination_action",
"scheduling.0.termination_time",
"scheduling.0.availability_domain",
"scheduling.0.max_run_duration",
"scheduling.0.on_instance_stop_action",
"scheduling.0.local_ssd_recovery_timeout",
}
shieldedInstanceConfigKeys = []string{
"shielded_instance_config.0.enable_secure_boot",
"shielded_instance_config.0.enable_vtpm",
"shielded_instance_config.0.enable_integrity_monitoring",
}
)
// This checks if the project provided in subnetwork's self_link matches
// the project provided in subnetwork_project not to produce a confusing plan diff.
func validateSubnetworkProject(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
// separate func to allow unit testing
return ValidateSubnetworkProjectFunc(d)
}
func ValidateSubnetworkProjectFunc(d tpgresource.TerraformResourceDiff) error {
oldCount, newCount := d.GetChange("network_interface.#")
if oldCount.(int) != newCount.(int) {
return nil
}
for i := 0; i < newCount.(int); i++ {
prefix := fmt.Sprintf("network_interface.%d", i)
subnetworkProject := d.Get(prefix + ".subnetwork_project")
subnetwork := d.Get(prefix + ".subnetwork")
_, err := tpgresource.GetRelativePath(subnetwork.(string))
if err != nil {
log.Printf("[DEBUG] Subnetwork %q is not a selflink", subnetwork)
return nil
}
if tpgresource.GetProjectFromRegionalSelfLink(subnetwork.(string)) != subnetworkProject.(string) {
return fmt.Errorf("project in subnetwork's self_link %q must match subnetwork_project %q", subnetwork, subnetworkProject)
}
}
return nil
}
// network_interface.[d].network_ip can only change when subnet/network
// is also changing. Validate that if network_ip is changing this scenario
// holds up to par.
func forceNewIfNetworkIPNotUpdatable(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
// separate func to allow unit testing
return forceNewIfNetworkIPNotUpdatableFunc(d)
}
func forceNewIfNetworkIPNotUpdatableFunc(d tpgresource.TerraformResourceDiff) error {
oldCount, newCount := d.GetChange("network_interface.#")
if oldCount.(int) != newCount.(int) {
return nil
}
for i := 0; i < newCount.(int); i++ {
prefix := fmt.Sprintf("network_interface.%d", i)
networkKey := prefix + ".network"
oldN, newN := d.GetChange(networkKey)
subnetworkKey := prefix + ".subnetwork"
oldS, newS := d.GetChange(subnetworkKey)
subnetworkProjectKey := prefix + ".subnetwork_project"
networkIPKey := prefix + ".network_ip"
if d.HasChange(networkIPKey) && d.Get(networkIPKey).(string) != "" {
if tpgresource.CompareSelfLinkOrResourceName("", oldS.(string), newS.(string), nil) && !d.HasChange(subnetworkProjectKey) && tpgresource.CompareSelfLinkOrResourceName("", oldN.(string), newN.(string), nil) {
if err := d.ForceNew(networkIPKey); err != nil {
return err
}
}
}
}
return nil
}
// User may specify AUTOMATIC using any case; the API will accept it and return an empty string.
func ComputeInstanceMinCpuPlatformEmptyOrAutomaticDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
old = strings.ToLower(old)
new = strings.ToLower(new)
defaultVal := "automatic"
return (old == "" && new == defaultVal) || (new == "" && old == defaultVal)
}
func ResourceComputeInstance() *schema.Resource {
return &schema.Resource{
Create: resourceComputeInstanceCreate,
Read: resourceComputeInstanceRead,
Update: resourceComputeInstanceUpdate,
Delete: resourceComputeInstanceDelete,
Importer: &schema.ResourceImporter{
State: resourceComputeInstanceImportState,
},
SchemaVersion: 6,
MigrateState: ResourceComputeInstanceMigrateState,
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},
// A compute instance is more or less a superset of a compute instance
// template. Please attempt to maintain consistency with the
// resource_compute_instance_template schema when updating this one.
Schema: map[string]*schema.Schema{
"boot_disk": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
MaxItems: 1,
Description: `The boot disk for the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"auto_delete": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: bootDiskKeys,
Default: true,
Description: `Whether the disk will be auto-deleted when the instance is deleted.`,
},
"device_name": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: bootDiskKeys,
Computed: true,
ForceNew: true,
Description: `Name with which attached disk will be accessible under /dev/disk/by-id/`,
},
"disk_encryption_key_raw": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: bootDiskKeys,
ForceNew: true,
ConflictsWith: []string{"boot_disk.0.kms_key_self_link"},
Sensitive: true,
Description: `A 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to encrypt this disk. Only one of kms_key_self_link and disk_encryption_key_raw may be set.`,
},
"disk_encryption_key_sha256": {
Type: schema.TypeString,
Computed: true,
Description: `The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.`,
},
"interface": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"SCSI", "NVME"}, false),
Description: `The disk interface used for attaching this disk. One of SCSI or NVME. (This field is shared with attached_disk and only used for specific cases, please don't specify this field without advice from Google.)`,
},
"kms_key_self_link": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: bootDiskKeys,
ForceNew: true,
ConflictsWith: []string{"boot_disk.0.disk_encryption_key_raw"},
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
Computed: true,
Description: `The self_link of the encryption key that is stored in Google Cloud KMS to encrypt this disk. Only one of kms_key_self_link and disk_encryption_key_raw may be set.`,
},
"initialize_params": {
Type: schema.TypeList,
Optional: true,
AtLeastOneOf: bootDiskKeys,
Computed: true,
ForceNew: true,
MaxItems: 1,
Description: `Parameters with which a disk was created alongside the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"size": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(1),
Description: `The size of the image in gigabytes.`,
},
"type": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
Description: `The Google Compute Engine disk type. Such as pd-standard, pd-ssd or pd-balanced.`,
},
"image": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
DiffSuppressFunc: DiskImageDiffSuppress,
Description: `The image from which this disk was initialised.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
Description: `A set of key/value label pairs assigned to the disk.`,
},
"resource_manager_tags": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
AtLeastOneOf: initializeParamsKeys,
Description: `A map of resource manager tags. Resource manager 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. The field is ignored (both PUT & PATCH) when empty.`,
},
"resource_policies": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
ForceNew: true,
Computed: true,
AtLeastOneOf: initializeParamsKeys,
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
MaxItems: 1,
Description: `A list of self_links of resource policies to attach to the instance's boot disk. Modifying this list will cause the instance to recreate. Currently a max of 1 resource policy is supported.`,
},
"provisioned_iops": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
Description: `Indicates how many IOPS to provision for the disk. This sets the number of I/O operations per second that the disk can handle.`,
},
"provisioned_throughput": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
Computed: true,
ForceNew: true,
Description: `Indicates how much throughput to provision for the disk. This sets the number of throughput mb per second that the disk can handle.`,
},
"enable_confidential_compute": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
ForceNew: true,
Description: `A flag to enable confidential compute mode on boot disk`,
},
"storage_pool": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: initializeParamsKeys,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareResourceNames,
Description: `The URL of the storage pool in which the new disk is created`,
},
},
},
},
"mode": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: bootDiskKeys,
ForceNew: true,
Default: "READ_WRITE",
ValidateFunc: validation.StringInSlice([]string{"READ_WRITE", "READ_ONLY"}, false),
Description: `Read/write mode for the disk. One of "READ_ONLY" or "READ_WRITE".`,
},
"source": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: bootDiskKeys,
Computed: true,
ForceNew: true,
ConflictsWith: []string{"boot_disk.initialize_params"},
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The name or self_link of the disk attached to this instance.`,
},
},
},
},
"machine_type": {
Type: schema.TypeString,
Required: true,
Description: `The machine type to create.`,
DiffSuppressFunc: tpgresource.CompareResourceNames,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidateRFC1035Name(1, 63),
Description: `The name of the instance. One of name or self_link must be provided.`,
},
"network_interface": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Description: `The networks attached to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The name or self_link of the network attached to this interface.`,
},
"subnetwork": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The name or self_link of the subnetwork attached to this interface.`,
},
"network_attachment": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The URL of the network attachment that this interface should connect to in the following format: projects/{projectNumber}/regions/{region_name}/networkAttachments/{network_attachment_name}.`,
},
"subnetwork_project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The project in which the subnetwork belongs.`,
},
"network_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The private IP address assigned to the instance.`,
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the interface`,
},
"nic_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"GVNIC", "VIRTIO_NET", "IDPF", "MRDMA", "IRDMA"}, false),
Description: `The type of vNIC to be used on this interface. Possible values:GVNIC, VIRTIO_NET, IDPF, MRDMA, and IRDMA`,
},
"access_config": {
Type: schema.TypeList,
Optional: true,
Description: `Access configurations, i.e. IPs via which this instance can be accessed via the Internet.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nat_ip": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The IP address that is be 1:1 mapped to the instance's network ip.`,
},
"network_tier": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The networking tier used for configuring this instance. One of PREMIUM or STANDARD.`,
},
"public_ptr_domain_name": {
Type: schema.TypeString,
Optional: true,
Description: `The DNS domain name for the public PTR record.`,
},
},
},
},
"alias_ip_range": {
Type: schema.TypeList,
Optional: true,
Description: `An array of alias IP ranges for this network interface.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_cidr_range": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: IpCidrRangeDiffSuppress,
Description: `The IP CIDR range represented by this alias IP range.`,
},
"subnetwork_range_name": {
Type: schema.TypeString,
Optional: true,
Description: `The subnetwork secondary range name specifying the secondary range from which to allocate the IP CIDR range for this alias IP range.`,
},
},
},
},
"stack_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"IPV4_ONLY", "IPV4_IPV6", "IPV6_ONLY", ""}, false),
Description: `The stack type for this network interface to identify whether the IPv6 feature is enabled or not. If not specified, IPV4_ONLY will be used.`,
},
"ipv6_access_type": {
Type: schema.TypeString,
Computed: true,
Description: `One of EXTERNAL, INTERNAL to indicate whether the IP can be accessed from the Internet. This field is always inherited from its subnetwork.`,
},
"ipv6_access_config": {
Type: schema.TypeList,
Optional: true,
Description: `An array of IPv6 access configurations for this interface. Currently, only one IPv6 access config, DIRECT_IPV6, is supported. If there is no ipv6AccessConfig specified, then this instance will have no external IPv6 Internet access.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network_tier": {
Type: schema.TypeString,
Required: true,
Description: `The service-level to be provided for IPv6 traffic when the subnet has an external subnet. Only PREMIUM tier is valid for IPv6`,
},
"public_ptr_domain_name": {
Type: schema.TypeString,
Optional: true,
Description: `The domain name to be used when creating DNSv6 records for the external IPv6 ranges.`,
},
"external_ipv6": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: ipv6RepresentationDiffSuppress,
Description: `The first IPv6 address of the external IPv6 range associated with this instance, prefix length is stored in externalIpv6PrefixLength in ipv6AccessConfig. To use a static external IP address, it must be unused and in the same region as the instance's zone. If not specified, Google Cloud will automatically assign an external IPv6 address from the instance's subnetwork.`,
},
"external_ipv6_prefix_length": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: `The prefix length of the external IPv6 range.`,
},
"name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: `The name of this access configuration. In ipv6AccessConfigs, the recommended name is External IPv6.`,
},
},
},
},
"internal_ipv6_prefix_length": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: `The prefix length of the primary internal IPv6 range.`,
},
"ipv6_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: ipv6RepresentationDiffSuppress,
Description: `An IPv6 internal network address for this network interface. If not specified, Google Cloud will automatically assign an internal IPv6 address from the instance's subnetwork.`,
},
"queue_count": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `The networking queue count that's specified by users for the network interface. Both Rx and Tx queues will be set to this number. It will be empty if not specified.`,
},
},
},
},
"network_performance_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
Description: `Configures network performance settings for the instance. If not specified, the instance will be created with its default network performance configuration.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"total_egress_bandwidth_tier": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"TIER_1", "DEFAULT"}, false),
Description: `The egress bandwidth tier to enable. Possible values:TIER_1, DEFAULT`,
},
},
},
},
"allow_stopping_for_update": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, allows Terraform to stop the instance to update its properties. If you try to update a property that requires stopping the instance without setting this field, the update will fail.`,
},
"attached_disk": {
Type: schema.TypeList,
Optional: true,
Description: `List of disks attached to the instance`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"source": {
Type: schema.TypeString,
Required: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The name or self_link of the disk attached to this instance.`,
},
"device_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Name with which the attached disk is accessible under /dev/disk/by-id/`,
},
"mode": {
Type: schema.TypeString,
Optional: true,
Default: "READ_WRITE",
ValidateFunc: validation.StringInSlice([]string{"READ_WRITE", "READ_ONLY"}, false),
Description: `Read/write mode for the disk. One of "READ_ONLY" or "READ_WRITE".`,
},
"disk_encryption_key_raw": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: `A 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to encrypt this disk. Only one of kms_key_self_link and disk_encryption_key_raw may be set.`,
},
"kms_key_self_link": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
Computed: true,
Description: `The self_link of the encryption key that is stored in Google Cloud KMS to encrypt this disk. Only one of kms_key_self_link and disk_encryption_key_raw may be set.`,
},
"disk_encryption_key_sha256": {
Type: schema.TypeString,
Computed: true,
Description: `The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied encryption key that protects this resource.`,
},
},
},
},
"can_ip_forward": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: `Whether sending and receiving of packets with non-matching source or destination IPs is allowed.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `A brief description of the resource.`,
},
"deletion_protection": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: `Whether deletion protection is enabled on this instance.`,
},
"enable_display": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether the instance has virtual displays enabled.`,
},
"guest_accelerator": {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
Description: `List of the type and count of accelerator cards attached to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `The number of the guest accelerator cards exposed to this instance.`,
},
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: `The accelerator type resource exposed to this instance. E.g. nvidia-tesla-k80.`,
},
},
},
},
"params": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ForceNew: true,
Description: `Stores additional params passed with the request, but not persisted as part of resource payload.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"resource_manager_tags": {
Type: schema.TypeMap,
Optional: true,
Description: `A map of resource manager tags. Resource manager 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. The field is ignored (both PUT & PATCH) when empty.`,
},
},
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `A set of key/value label pairs assigned to the instance.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
},
"terraform_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `The combination of labels configured directly on the resource and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"metadata": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `Metadata key/value pairs made available within the instance.`,
},
"metadata_startup_script": {
Type: schema.TypeString,
Optional: true,
Description: `Metadata startup scripts made available within the instance.`,
},
"min_cpu_platform": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The minimum CPU platform specified for the VM instance.`,
DiffSuppressFunc: ComputeInstanceMinCpuPlatformEmptyOrAutomaticDiffSuppress,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: `The ID of the project in which the resource belongs. If self_link is provided, this value is ignored. If neither self_link nor project are provided, the provider project is used.`,
},
"scheduling": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Description: `The scheduling strategy being used by the instance.`,
Elem: &schema.Resource{
// !!! IMPORTANT !!!
// We have a custom diff function for the scheduling block due to issues with Terraform's
// diff on schema.Set. If changes are made to this block, they must be reflected in that
// method. See schedulingHasChangeWithoutReboot in compute_instance_helpers.go
Schema: map[string]*schema.Schema{
"on_host_maintenance": {
Type: schema.TypeString,
Optional: true,
Computed: true,
AtLeastOneOf: schedulingKeys,
Description: `Describes maintenance behavior for the instance. One of MIGRATE or TERMINATE,`,
},
"automatic_restart": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: schedulingKeys,
Default: true,
Description: `Specifies if the instance should be restarted if it was terminated by Compute Engine (not a user).`,
},
"preemptible": {
Type: schema.TypeBool,
Optional: true,
Default: false,
AtLeastOneOf: schedulingKeys,
ForceNew: true,
Description: `Whether the instance is preemptible.`,
},
"node_affinities": {
Type: schema.TypeSet,
Optional: true,
AtLeastOneOf: schedulingKeys,
Elem: instanceSchedulingNodeAffinitiesElemSchema(),
DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress(""),
Description: `Specifies node affinities or anti-affinities to determine which sole-tenant nodes your instances and managed instance groups will use as host systems.`,
},
"min_node_cpus": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: schedulingKeys,
},
"provisioning_model": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
AtLeastOneOf: schedulingKeys,
Description: `Whether the instance is spot. If this is set as SPOT.`,
},
"instance_termination_action": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: schedulingKeys,
Description: `Specifies the action GCE should take when SPOT VM is preempted.`,
},
"termination_time": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
AtLeastOneOf: schedulingKeys,
Description: `Specifies the timestamp, when the instance will be terminated,
in RFC3339 text format. If specified, the instance termination action
will be performed at the termination time.`,
},
"availability_domain": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: schedulingKeys,
Description: `Specifies the availability domain, which this instance should be scheduled on.`,
},
"max_run_duration": {
Type: schema.TypeList,
Optional: true,
Description: `The timeout for new network connections to hosts.`,
MaxItems: 1,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"seconds": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `Span of time at a resolution of a second.
Must be from 0 to 315,576,000,000 inclusive.`,
},
"nanos": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Span of time that's a fraction of a second at nanosecond
resolution. Durations less than one second are represented
with a 0 seconds field and a positive nanos field. Must
be from 0 to 999,999,999 inclusive.`,
},
},
},
},
"on_instance_stop_action": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ForceNew: true,
Description: `Defines the behaviour for instances with the instance_termination_action.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"discard_local_ssd": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, the contents of any attached Local SSD disks will be discarded.`,
Default: false,
ForceNew: true,
},
},
},
},
"local_ssd_recovery_timeout": {
Type: schema.TypeList,
Optional: true,
Description: `Specifies the maximum amount of time a Local Ssd Vm should wait while
recovery of the Local Ssd state is attempted. Its value should be in
between 0 and 168 hours with hour granularity and the default value being 1
hour.`,
MaxItems: 1,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"seconds": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: `Span of time at a resolution of a second.
Must be from 0 to 315,576,000,000 inclusive.`,
},
"nanos": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Description: `Span of time that's a fraction of a second at nanosecond
resolution. Durations less than one second are represented
with a 0 seconds field and a positive nanos field. Must
be from 0 to 999,999,999 inclusive.`,
},
},
},
},
},
},
},
"scratch_disk": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `The scratch disks attached to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"device_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `Name with which the attached disk is accessible under /dev/disk/by-id/`,
},
"interface": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"SCSI", "NVME"}, false),
Description: `The disk interface used for attaching this disk. One of SCSI or NVME.`,
},
"size": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(375),
Default: 375,
Description: `The size of the disk in gigabytes. One of 375 or 3000.`,
},
},
},
},
"service_account": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
DiffSuppressFunc: serviceAccountDiffSuppress,
Description: `The service account to attach to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"email": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: `The service account e-mail address.`,
},
"scopes": {