forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_sql_database_instance.go
More file actions
3553 lines (3230 loc) · 138 KB
/
resource_sql_database_instance.go
File metadata and controls
3553 lines (3230 loc) · 138 KB
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
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: Handwritten ***
//
// ----------------------------------------------------------------------------
//
// This code is generated by Magic Modules using the following:
//
// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl
//
// DO NOT EDIT this file directly. Any changes made to this file will be
// overwritten during the next generation cycle.
//
// ----------------------------------------------------------------------------
package sql
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"slices"
"strconv"
"strings"
"time"
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-google/google/services/servicenetworking"
"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/googleapi"
sqladmin "google.golang.org/api/sqladmin/v1beta4"
)
// Match fully-qualified or relative URLs
const privateNetworkLinkRegex = "^(?:http(?:s)?://.+/)?projects/(" + verify.ProjectRegex + ")/global/networks/((?:[a-z](?:[-a-z0-9]*[a-z0-9])?))$"
var sqlDatabaseAuthorizedNetWorkSchemaElem *schema.Resource = &schema.Resource{
Schema: map[string]*schema.Schema{
"expiration_time": {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"value": {
Type: schema.TypeString,
Required: true,
},
},
}
var sqlDatabaseFlagSchemaElem *schema.Resource = &schema.Resource{
Schema: map[string]*schema.Schema{
"value": {
Type: schema.TypeString,
Required: true,
Description: `Value of the flag.`,
},
"name": {
Type: schema.TypeString,
Required: true,
Description: `Name of the flag.`,
},
},
}
var (
backupConfigurationKeys = []string{
"settings.0.backup_configuration.0.binary_log_enabled",
"settings.0.backup_configuration.0.enabled",
"settings.0.backup_configuration.0.start_time",
"settings.0.backup_configuration.0.location",
"settings.0.backup_configuration.0.point_in_time_recovery_enabled",
"settings.0.backup_configuration.0.backup_retention_settings",
"settings.0.backup_configuration.0.transaction_log_retention_days",
"settings.0.backup_configuration.0.backup_tier",
}
connectionPoolConfigKeys = []string{
"settings.0.connection_pool_config.0.connection_pooling_enabled",
"settings.0.connection_pool_config.0.flags",
}
ipConfigurationKeys = []string{
"settings.0.ip_configuration.0.authorized_networks",
"settings.0.ip_configuration.0.ipv4_enabled",
"settings.0.ip_configuration.0.private_network",
"settings.0.ip_configuration.0.allocated_ip_range",
"settings.0.ip_configuration.0.enable_private_path_for_google_cloud_services",
"settings.0.ip_configuration.0.psc_config",
"settings.0.ip_configuration.0.ssl_mode",
"settings.0.ip_configuration.0.server_ca_mode",
"settings.0.ip_configuration.0.server_ca_pool",
"settings.0.ip_configuration.0.custom_subject_alternative_names",
}
maintenanceWindowKeys = []string{
"settings.0.maintenance_window.0.day",
"settings.0.maintenance_window.0.hour",
"settings.0.maintenance_window.0.update_track",
}
replicaConfigurationKeys = []string{
"replica_configuration.0.cascadable_replica",
"replica_configuration.0.ca_certificate",
"replica_configuration.0.client_certificate",
"replica_configuration.0.client_key",
"replica_configuration.0.connect_retry_interval",
"replica_configuration.0.dump_file_path",
"replica_configuration.0.failover_target",
"replica_configuration.0.master_heartbeat_period",
"replica_configuration.0.password",
"replica_configuration.0.ssl_cipher",
"replica_configuration.0.username",
"replica_configuration.0.verify_server_certificate",
}
insightsConfigKeys = []string{
"settings.0.insights_config.0.query_insights_enabled",
"settings.0.insights_config.0.query_string_length",
"settings.0.insights_config.0.record_application_tags",
"settings.0.insights_config.0.record_client_address",
"settings.0.insights_config.0.query_plans_per_minute",
}
sqlServerAuditConfigurationKeys = []string{
"settings.0.sql_server_audit_config.0.bucket",
"settings.0.sql_server_audit_config.0.retention_interval",
"settings.0.sql_server_audit_config.0.upload_interval",
}
readPoolAutoScaleConfigKeys = []string{
"settings.0.read_pool_auto_scale_config.0.enabled",
"settings.0.read_pool_auto_scale_config.0.min_node_count",
"settings.0.read_pool_auto_scale_config.0.max_node_count",
"settings.0.read_pool_auto_scale_config.0.target_metrics",
"settings.0.read_pool_auto_scale_config.0.disable_scale_in",
"settings.0.read_pool_auto_scale_config.0.scale_in_cooldown_seconds",
"settings.0.read_pool_auto_scale_config.0.scale_out_cooldown_seconds",
}
)
func nodeCountCustomDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
autoScaleEnabled := d.Get("settings.0.read_pool_auto_scale_config.0.enabled").(bool)
if !autoScaleEnabled {
// Keep the diff
return nil
}
currentNodeCountI, _ := d.GetChange("node_count")
currentNodeCount := currentNodeCountI.(int)
minNodeCount := d.Get("settings.0.read_pool_auto_scale_config.0.min_node_count").(int)
maxNodeCount := d.Get("settings.0.read_pool_auto_scale_config.0.max_node_count").(int)
if currentNodeCount < minNodeCount {
// Node count will only be less than min node count if min node count is being increased.
// Set node count to be new min node count.
return d.SetNew("node_count", minNodeCount)
}
if currentNodeCount > maxNodeCount {
// Node count will only be greater than max node count if max node count is being descreased.
// Set node count to be new max node count.
return d.SetNew("node_count", maxNodeCount)
}
// Otherwise when autoscaling is enabled, ignore the node count in config.
return d.Clear("node_count")
}
func diskSizeCutomizeDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
key := "settings.0.disk_size"
old, new := d.GetChange(key)
// It's okay to remove size entirely.
if old == nil || new == nil {
return nil
}
autoResizeI, exists := d.GetOkExists("settings.0.disk_autoresize")
autoResize := !exists || autoResizeI.(bool)
if old.(int) <= new.(int) {
// If a resize up, always allow it - keep the diff.
return nil
}
if autoResize {
// Allow having disk size larger in the state than in config if auto resize is enabled.
// Delete the diff.
err := d.Clear(key)
if err != nil {
return err
}
return nil
}
// If we are here, we are trying to shrink the disk with auto resize disabled and no ignore changes on disk size.
// This will force a new resource.
if err := d.ForceNew(key); err != nil {
return err
}
return nil
}
func ResourceSqlDatabaseInstance() *schema.Resource {
return &schema.Resource{
Create: resourceSqlDatabaseInstanceCreate,
Read: resourceSqlDatabaseInstanceRead,
Update: resourceSqlDatabaseInstanceUpdate,
Delete: resourceSqlDatabaseInstanceDelete,
Importer: &schema.ResourceImporter{
State: resourceSqlDatabaseInstanceImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(90 * time.Minute),
Update: schema.DefaultTimeout(90 * time.Minute),
Delete: schema.DefaultTimeout(90 * time.Minute),
},
CustomizeDiff: customdiff.All(
tpgresource.DefaultProviderProject,
diskSizeCutomizeDiff,
customdiff.ForceNewIf("master_instance_name", func(_ context.Context, d *schema.ResourceDiff, meta interface{}) bool {
// If we set master but this is not the new master of a switchover, require replacement and warn user.
return !isSwitchoverFromOldPrimarySide(d)
}),
customdiff.ForceNewIf("replica_configuration.0.cascadable_replica", func(_ context.Context, d *schema.ResourceDiff, meta interface{}) bool {
return !isSwitchoverFromOldPrimarySide(d)
}),
customdiff.IfValueChange("instance_type", isReplicaPromoteRequested, checkPromoteConfigurationsAndUpdateDiff),
privateNetworkCustomizeDiff,
pitrSupportDbCustomizeDiff,
nodeCountCustomDiff,
),
Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: `The region the instance will sit in. Note, Cloud SQL is not available in all regions. A valid region must be provided to use this resource. If a region is not provided in the resource definition, the provider region will be used instead, but this will be an apply-time error for instances if the provider region is not supported with Cloud SQL. If you choose not to provide the region argument for this resource, make sure you understand this.`,
},
"deletion_protection": {
Type: schema.TypeBool,
Default: true,
Optional: true,
Description: `Used to block Terraform from deleting a SQL Instance. Defaults to true.`,
},
"final_backup_description": {
Type: schema.TypeString,
Optional: true,
Description: `The description of final backup if instance enable create final backup during instance deletion. `,
},
"settings": {
Type: schema.TypeList,
Optional: true,
Computed: true,
AtLeastOneOf: []string{"settings", "clone", "point_in_time_restore_context"},
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeInt,
Computed: true,
Description: `Used to make sure changes to the settings block are atomic.`,
},
"tier": {
Type: schema.TypeString,
Required: true,
Description: `The machine type to use. See tiers for more details and supported versions. Postgres supports only shared-core machine types, and custom machine types such as db-custom-2-13312. See the Custom Machine Type Documentation to learn about specifying custom machine types.`,
},
"edition": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"ENTERPRISE", "ENTERPRISE_PLUS"}, false),
Description: `The edition of the instance, can be ENTERPRISE or ENTERPRISE_PLUS.`,
},
"advanced_machine_features": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threads_per_core": {
Type: schema.TypeInt,
Optional: true,
Description: `The number of threads per physical core. Can be 1 or 2.`,
},
},
},
},
"data_cache_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: `Data cache configurations.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"data_cache_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: `Whether data cache is enabled for the instance.`,
},
},
},
},
"activation_policy": {
Type: schema.TypeString,
Optional: true,
Default: "ALWAYS",
Description: `This specifies when the instance should be active. Can be either ALWAYS, NEVER or ON_DEMAND.`,
},
"active_directory_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Required: true,
Description: `Domain name of the Active Directory for SQL Server (e.g., mydomain.com).`,
},
},
},
},
"deny_maintenance_period": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"end_date": {
Type: schema.TypeString,
Required: true,
Description: `End date before which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`,
},
"start_date": {
Type: schema.TypeString,
Required: true,
Description: `Start date after which maintenance will not take place. The date is in format yyyy-mm-dd i.e., 2020-11-01, or mm-dd, i.e., 11-01`,
},
"time": {
Type: schema.TypeString,
Required: true,
Description: `Time in UTC when the "deny maintenance period" starts on start_date and ends on end_date. The time is in format: HH:mm:SS, i.e., 00:00:00`,
},
},
},
},
"sql_server_audit_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bucket": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `The name of the destination bucket (e.g., gs://mybucket).`,
},
"retention_interval": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `How long to keep generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"..`,
},
"upload_interval": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: sqlServerAuditConfigurationKeys,
Description: `How often to upload generated audit files. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".`,
},
},
},
},
"time_zone": {
Type: schema.TypeString,
Optional: true,
Description: `The time_zone to be used by the database engine (supported only for SQL Server), in SQL Server timezone format.`,
},
"availability_type": {
Type: schema.TypeString,
Optional: true,
Default: "ZONAL",
ValidateFunc: validation.StringInSlice([]string{"REGIONAL", "ZONAL"}, false),
Description: `The availability type of the Cloud SQL instance, high availability
(REGIONAL) or single zone (ZONAL). For all instances, ensure that
settings.backup_configuration.enabled is set to true.
For MySQL instances, ensure that settings.backup_configuration.binary_log_enabled is set to true.
For Postgres instances, ensure that settings.backup_configuration.point_in_time_recovery_enabled
is set to true. Defaults to ZONAL.
For read pool instances, this field is read-only. The availability type is changed by specifying
the number of nodes (node_count).`,
},
"effective_availability_type": {
Type: schema.TypeString,
Computed: true,
Description: `The availability type of the Cloud SQL instance, high availability
(REGIONAL) or single zone (ZONAL). This field always contains the value that is reported by the
API (for read pools, effective_availability_type may differ from availability_type).`,
},
"backup_configuration": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"binary_log_enabled": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
Description: `True if binary logging is enabled. If settings.backup_configuration.enabled is false, this must be as well. Can only be used with MySQL.`,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
Description: `True if backup configuration is enabled.`,
},
"start_time": {
Type: schema.TypeString,
Optional: true,
// start_time is randomly assigned if not set
Computed: true,
AtLeastOneOf: backupConfigurationKeys,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
Description: `HH:MM format time indicating when backup configuration starts.`,
},
"location": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
Description: `Location of the backup configuration.`,
},
"point_in_time_recovery_enabled": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
Description: `True if Point-in-time recovery is enabled.`,
},
"transaction_log_retention_days": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
Description: `The number of days of transaction logs we retain for point in time restore, from 1-7. (For PostgreSQL Enterprise Plus instances, from 1 to 35.)`,
},
"backup_retention_settings": {
Type: schema.TypeList,
Optional: true,
AtLeastOneOf: backupConfigurationKeys,
Computed: true,
DiffSuppressFunc: EnhancedBackupManagerDiffSuppressFunc,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"retained_backups": {
Type: schema.TypeInt,
Required: true,
Description: `Number of backups to retain.`,
},
"retention_unit": {
Type: schema.TypeString,
Optional: true,
Default: "COUNT",
Description: `The unit that 'retainedBackups' represents. Defaults to COUNT`,
},
},
},
},
"backup_tier": {
Type: schema.TypeString,
Computed: true,
Description: `Backup tier that manages the backups for the instance.`,
},
},
},
},
"collation": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The name of server instance collation.`,
},
"database_flags": {
Type: schema.TypeSet,
Optional: true,
Set: schema.HashResource(sqlDatabaseFlagSchemaElem),
Elem: sqlDatabaseFlagSchemaElem,
},
"disk_autoresize": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: `Enables auto-resizing of the storage size. Defaults to true.`,
},
"disk_autoresize_limit": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: `The maximum size, in GB, to which storage capacity can be automatically increased. The default value is 0, which specifies that there is no limit.`,
},
"enable_google_ml_integration": {
Type: schema.TypeBool,
Optional: true,
Description: `Enables Vertex AI Integration.`,
},
"enable_dataplex_integration": {
Type: schema.TypeBool,
Optional: true,
Description: `Enables Dataplex Integration.`,
},
"disk_size": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: `The size of data disk, in GB. Size of a running instance cannot be reduced but can be increased. The minimum value is 10GB for PD_SSD, PD_HDD and 20GB for HYPERDISK_BALANCED.`,
},
"disk_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
DiffSuppressFunc: caseDiffDashSuppress,
Description: `The type of supported data disk is tier dependent and can be PD_SSD or PD_HDD or HYPERDISK_BALANCED.`,
},
"connection_pool_config": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Description: `The managed connection pool setting for a Cloud SQL instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"connection_pooling_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether Managed Connection Pool is enabled for this instance.`,
},
"flags": {
Type: schema.TypeSet,
Optional: true,
Set: schema.HashResource(sqlDatabaseFlagSchemaElem),
Elem: sqlDatabaseFlagSchemaElem,
Description: `List of connection pool configuration flags`,
},
},
},
},
"ip_configuration": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"authorized_networks": {
Type: schema.TypeSet,
Optional: true,
Set: schema.HashResource(sqlDatabaseAuthorizedNetWorkSchemaElem),
Elem: sqlDatabaseAuthorizedNetWorkSchemaElem,
AtLeastOneOf: ipConfigurationKeys,
},
"ipv4_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
AtLeastOneOf: ipConfigurationKeys,
Description: `Whether this Cloud SQL instance should be assigned a public IPV4 address. At least ipv4_enabled must be enabled or a private_network must be configured.`,
},
"private_network": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.OrEmpty(verify.ValidateRegexp(privateNetworkLinkRegex)),
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
AtLeastOneOf: ipConfigurationKeys,
Description: `The VPC network from which the Cloud SQL instance is accessible for private IP. For example, projects/myProject/global/networks/default. Specifying a network enables private IP. At least ipv4_enabled must be enabled or a private_network must be configured. This setting can be updated, but it cannot be removed after it is set.`,
},
"allocated_ip_range": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: ipConfigurationKeys,
Description: `The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the instance ip will be created in the allocated range. The range name must comply with RFC 1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.`,
},
"enable_private_path_for_google_cloud_services": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: ipConfigurationKeys,
Description: `Whether Google Cloud services such as BigQuery are allowed to access data in this Cloud SQL instance over a private IP connection. SQLSERVER database type is not supported.`,
},
"psc_config": {
Type: schema.TypeSet,
Optional: true,
Description: `PSC settings for a Cloud SQL instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"psc_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `Whether PSC connectivity is enabled for this instance.`,
},
"allowed_consumer_projects": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: `List of consumer projects that are allow-listed for PSC connections to this instance. This instance can be connected to with PSC from any network in these projects. Each consumer project in this list may be represented by a project number (numeric) or by a project id (alphanumeric).`,
},
"network_attachment_uri": {
Type: schema.TypeString,
Optional: true,
Description: `Name of network attachment resource used to authorize a producer service to connect a PSC interface to the consumer's VPC. For example: "projects/myProject/regions/myRegion/networkAttachments/myNetworkAttachment". This is required to enable outbound connection on a PSC instance.`,
},
"psc_auto_connections": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"consumer_service_project_id": {
Type: schema.TypeString,
Optional: true,
Description: `The project ID of consumer service project of this consumer endpoint.`,
},
"consumer_network": {
Type: schema.TypeString,
Required: true,
Description: `The consumer network of this consumer endpoint. This must be a resource path that includes both the host project and the network name. The consumer host project of this network might be different from the consumer service project.`,
},
"consumer_network_status": {
Type: schema.TypeString,
Computed: true,
Description: `The connection policy status of the consumer network.`,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
Description: `The IP address of the consumer endpoint.`,
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: `The connection status of the consumer endpoint.`,
},
},
},
Description: `A comma-separated list of networks or a comma-separated list of network-project pairs. Each project in this list is represented by a project number (numeric) or by a project ID (alphanumeric). This allows Private Service Connect connections to be created automatically for the specified networks.`,
},
},
},
},
"ssl_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"ALLOW_UNENCRYPTED_AND_ENCRYPTED", "ENCRYPTED_ONLY", "TRUSTED_CLIENT_CERTIFICATE_REQUIRED"}, false),
Description: `Specify how SSL connection should be enforced in DB connections.`,
AtLeastOneOf: ipConfigurationKeys,
},
"server_ca_mode": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"CA_MODE_UNSPECIFIED", "GOOGLE_MANAGED_INTERNAL_CA", "GOOGLE_MANAGED_CAS_CA", "CUSTOMER_MANAGED_CAS_CA"}, false),
Description: `Specify how the server certificate's Certificate Authority is hosted.`,
AtLeastOneOf: ipConfigurationKeys,
},
"server_ca_pool": {
Type: schema.TypeString,
Optional: true,
Description: `The resource name of the server CA pool for an instance with "CUSTOMER_MANAGED_CAS_CA" as the "server_ca_mode".`,
AtLeastOneOf: ipConfigurationKeys,
},
"custom_subject_alternative_names": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Set: schema.HashString,
Description: `The custom subject alternative names for an instance with "CUSTOMER_MANAGED_CAS_CA" as the "server_ca_mode".`,
AtLeastOneOf: ipConfigurationKeys,
},
},
},
},
"location_preference": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"follow_gae_application": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: []string{"settings.0.location_preference.0.follow_gae_application", "settings.0.location_preference.0.zone"},
Description: `A Google App Engine application whose zone to remain in. Must be in the same region as this instance.`,
},
"zone": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: []string{"settings.0.location_preference.0.follow_gae_application", "settings.0.location_preference.0.zone"},
Description: `The preferred compute engine zone.`,
},
"secondary_zone": {
Type: schema.TypeString,
Optional: true,
Description: `The preferred Compute Engine zone for the secondary/failover`,
},
},
},
},
"maintenance_window": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"day": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 7),
AtLeastOneOf: maintenanceWindowKeys,
Description: `Day of week (1-7), starting on Monday`,
},
"hour": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 23),
AtLeastOneOf: maintenanceWindowKeys,
Description: `Hour of day (0-23), ignored if day not set`,
},
"update_track": {
Type: schema.TypeString,
Optional: true,
AtLeastOneOf: maintenanceWindowKeys,
Description: `Receive updates after one week (canary) or after two weeks (stable) or after five weeks (week5) of notification.`,
},
},
},
Description: `Declares a one-hour maintenance window when an Instance can automatically restart to apply updates. The maintenance window is specified in UTC time.`,
},
"pricing_plan": {
Type: schema.TypeString,
Optional: true,
Default: "PER_USE",
Description: `Pricing plan for this instance, can only be PER_USE.`,
},
"user_labels": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: `A set of key/value user label pairs to assign to the instance.`,
},
"insights_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"query_insights_enabled": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: insightsConfigKeys,
Description: `True if Query Insights feature is enabled.`,
},
"query_string_length": {
Type: schema.TypeInt,
Optional: true,
Default: 1024,
ValidateFunc: validation.IntBetween(1, 1048576),
AtLeastOneOf: insightsConfigKeys,
Description: `Maximum query length stored in bytes. Between 256 and 4500. Default to 1024. For Enterprise Plus instances, from 1 to 1048576.`,
},
"record_application_tags": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: insightsConfigKeys,
Description: `True if Query Insights will record application tags from query when enabled.`,
},
"record_client_address": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: insightsConfigKeys,
Description: `True if Query Insights will record client address when enabled.`,
},
"query_plans_per_minute": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validation.IntBetween(0, 200),
AtLeastOneOf: insightsConfigKeys,
Description: `Number of query execution plans captured by Insights per minute for all queries combined. Between 0 and 20. Default to 5. For Enterprise Plus instances, from 0 to 200.`,
},
},
},
Description: `Configuration of Query Insights.`,
},
"password_validation_policy": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_length": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 2147483647),
Description: `Minimum number of characters allowed.`,
},
"complexity": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"COMPLEXITY_DEFAULT", "COMPLEXITY_UNSPECIFIED"}, false),
Description: `Password complexity.`,
},
"reuse_interval": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 2147483647),
Description: `Number of previous passwords that cannot be reused.`,
},
"disallow_username_substring": {
Type: schema.TypeBool,
Optional: true,
Description: `Disallow username as a part of the password.`,
},
"password_change_interval": {
Type: schema.TypeString,
Optional: true,
Description: `Minimum interval after which the password can be changed. This flag is only supported for PostgresSQL.`,
},
"enable_password_policy": {
Type: schema.TypeBool,
Required: true,
Description: `Whether the password policy is enabled or not.`,
},
},
},
},
"connector_enforcement": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"NOT_REQUIRED", "REQUIRED"}, false),
Description: `Enables the enforcement of Cloud SQL Auth Proxy or Cloud SQL connectors for all the connections. If enabled, all the direct connections are rejected.`,
},
"deletion_protection_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `Configuration to protect against accidental instance deletion.`,
},
"retain_backups_on_delete": {
Type: schema.TypeBool,
Optional: true,
Description: `When this parameter is set to true, Cloud SQL retains backups of the instance even after the instance is deleted. The ON_DEMAND backup will be retained until customer deletes the backup or the project. The AUTOMATED backup will be retained based on the backups retention setting.`,
},
"final_backup_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Description: `When this parameter is set to true, the final backup is enabled for the instance`,
},
"retention_days": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 36135),
Description: `The number of days to retain the final backup after the instance deletion. The valid range is between 1 and 365. For instances managed by BackupDR, the valid range is between 1 day and 99 years. The final backup will be purged at (time_of_instance_deletion + retention_days).`,
},
},
},
Description: `Config used to determine the final backup settings for the instance`,
},
"read_pool_auto_scale_config": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `True if Read Pool Auto Scale is enabled.`,
},
"max_node_count": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 20),
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `Maximum number of nodes in the read pool. If set to lower than current node count, node count will be updated.`,
},
"min_node_count": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 20),
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `Minimum number of nodes in the read pool. If set to higher than current node count, node count will be updated.`,
},
"target_metrics": {
Type: schema.TypeSet,
Optional: true,
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `Target metrics for Read Pool Auto Scale.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"metric": {
Type: schema.TypeString,
Optional: true,
Description: `Metric name for Read Pool Auto Scale.`,
},
"target_value": {
Type: schema.TypeFloat,
Optional: true,
Description: `Target value for Read Pool Auto Scale.`,
},
},
},
},
"disable_scale_in": {
Type: schema.TypeBool,
Optional: true,
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `True if auto scale in is disabled.`,
},
"scale_in_cooldown_seconds": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `The cooldown period for scale in operations.`,
},
"scale_out_cooldown_seconds": {
Type: schema.TypeInt,
Optional: true,
AtLeastOneOf: readPoolAutoScaleConfigKeys,
Description: `The cooldown period for scale out operations.`,
},
},
},
Description: `Configuration of Read Pool Auto Scale.`,
},
},
},
Description: `The settings to use for the database. The configuration is detailed below.`,
},
"connection_name": {
Type: schema.TypeString,
Computed: true,
Description: `The connection name of the instance to be used in connection strings. For example, when connecting with Cloud SQL Proxy.`,
},
"maintenance_version": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: `Maintenance version.`,
DiffSuppressFunc: maintenanceVersionDiffSuppress,
},
"available_maintenance_versions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: `Available Maintenance versions.`,