Skip to content

Commit bd6209a

Browse files
authored
adding source_instance_deletion_time (#15239)
1 parent 28551d1 commit bd6209a

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
func DataSourceSqlDatabaseInstanceLatestRecoveryTime() *schema.Resource {
1212
return &schema.Resource{
1313
Read: dataSourceSqlDatabaseInstanceLatestRecoveryTimeRead,
14-
1514
Schema: map[string]*schema.Schema{
1615
"instance": {
1716
Type: schema.TypeString,
@@ -29,6 +28,11 @@ func DataSourceSqlDatabaseInstanceLatestRecoveryTime() *schema.Resource {
2928
Computed: true,
3029
Description: `Timestamp, identifies the latest recovery time of the source instance.`,
3130
},
31+
"source_instance_deletion_time": {
32+
Type: schema.TypeString,
33+
Optional: true,
34+
Description: `Timestamp, identifies when the source instance was deleted. If this instance is deleted, then you must set the timestamp.`,
35+
},
3236
},
3337
}
3438
}
@@ -39,23 +43,28 @@ func dataSourceSqlDatabaseInstanceLatestRecoveryTimeRead(d *schema.ResourceData,
3943
if err != nil {
4044
return err
4145
}
42-
4346
fv, err := tpgresource.ParseProjectFieldValue("instances", d.Get("instance").(string), "project", d, config, false)
4447
if err != nil {
4548
return err
4649
}
4750
project := fv.Project
4851
instance := fv.Name
4952

50-
latestRecoveryTime, err := config.NewSqlAdminClient(userAgent).Projects.Instances.GetLatestRecoveryTime(project, instance).Do()
53+
deletionTime := d.Get("source_instance_deletion_time").(string)
54+
55+
latestRecoveryTimeCall := config.NewSqlAdminClient(userAgent).Projects.Instances.GetLatestRecoveryTime(project, instance)
56+
57+
if deletionTime != "" {
58+
latestRecoveryTimeCall = latestRecoveryTimeCall.SourceInstanceDeletionTime(deletionTime)
59+
}
60+
61+
latestRecoveryTime, err := latestRecoveryTimeCall.Do()
5162
if err != nil {
5263
return err
5364
}
54-
5565
if err := d.Set("project", project); err != nil {
5666
return fmt.Errorf("Error setting project: %s", err)
5767
}
58-
5968
if err := d.Set("latest_recovery_time", latestRecoveryTime.LatestRecoveryTime); err != nil {
6069
return fmt.Errorf("Error setting latest_recovery_time: %s", err)
6170
}

mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func TestAccDataSourceSqlDatabaseInstanceLatestRecoveryTime_basic(t *testing.T)
1919
PreCheck: func() { acctest.AccTestPreCheck(t) },
2020
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2121
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
22+
ExternalProviders: map[string]resource.ExternalProvider{
23+
"time": {},
24+
},
2225
Steps: []resource.TestStep{
2326
{
2427
Config: testAccDataSourceSqlDatabaseInstanceLatestRecoveryTime_basic(context),
@@ -52,8 +55,15 @@ resource "google_sql_database_instance" "main" {
5255
deletion_protection = false
5356
}
5457
58+
resource "time_sleep" "wait_for_instance" {
59+
// Wait 30 seconds after the instance is created
60+
depends_on = [google_sql_database_instance.main]
61+
create_duration = "330s"
62+
}
63+
5564
data "google_sql_database_instance_latest_recovery_time" "default" {
56-
instance = resource.google_sql_database_instance.main.name
65+
instance = google_sql_database_instance.main.name
66+
depends_on = [time_sleep.wait_for_instance]
5767
}
5868
`, context)
5969
}

mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,12 @@ API (for read pools, effective_availability_type may differ from availability_ty
12511251
Optional: true,
12521252
Description: `The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the cloned instance ip will be created in the allocated range. The range name must comply with [RFC 1035](https://tools.ietf.org/html/rfc1035). Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.`,
12531253
},
1254+
"source_instance_deletion_time": {
1255+
Type: schema.TypeString,
1256+
Optional: true,
1257+
DiffSuppressFunc: tpgresource.TimestampDiffSuppress(time.RFC3339Nano),
1258+
Description: `The timestamp of when the source instance was deleted for a clone from a deleted instance.`,
1259+
},
12541260
},
12551261
},
12561262
},
@@ -1675,6 +1681,7 @@ func expandCloneContext(configured []interface{}) (*sqladmin.CloneContext, strin
16751681
PreferredZone: _cloneConfiguration["preferred_zone"].(string),
16761682
DatabaseNames: databaseNames,
16771683
AllocatedIpRange: _cloneConfiguration["allocated_ip_range"].(string),
1684+
SourceInstanceDeletionTime: _cloneConfiguration["source_instance_deletion_time"].(string),
16781685
}, _cloneConfiguration["source_instance_name"].(string)
16791686
}
16801687

mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ The optional `point_in_time_restore_context` block supports:
625625

626626
* `allocated_ip_range` - (Optional) The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the cloned instance ip will be created in the allocated range. The range name must comply with [RFC 1035](https://tools.ietf.org/html/rfc1035). Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.
627627

628+
* `source_instance_deletion_time` - (Optional) The timestamp of when the source instance was deleted for a clone from a deleted instance.
629+
630+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
631+
628632
* `database_names` - (Optional) (SQL Server only, use with `point_in_time`) Clone only the specified databases from the source instance. Clone all databases if empty.
629633

630634
The optional `clone` block supports:
@@ -641,6 +645,10 @@ The optional `clone` block supports:
641645

642646
* `allocated_ip_range` - (Optional) The name of the allocated ip range for the private ip CloudSQL instance. For example: "google-managed-services-default". If set, the cloned instance ip will be created in the allocated range. The range name must comply with [RFC 1035](https://tools.ietf.org/html/rfc1035). Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])?.
643647

648+
* `source_instance_deletion_time` - (Optional) The timestamp of when the source instance was deleted for a clone from a deleted instance.
649+
650+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
651+
644652
The optional `restore_backup_context` block supports:
645653
**NOTE:** Restoring from a backup is an imperative action and not recommended via Terraform. Adding or modifying this
646654
block during resource creation/update will trigger the restore action after the resource is created/updated.

0 commit comments

Comments
 (0)