diff --git a/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time.go b/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time.go index 763b0108304a..66ebddc52318 100644 --- a/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time.go +++ b/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time.go @@ -11,7 +11,6 @@ import ( func DataSourceSqlDatabaseInstanceLatestRecoveryTime() *schema.Resource { return &schema.Resource{ Read: dataSourceSqlDatabaseInstanceLatestRecoveryTimeRead, - Schema: map[string]*schema.Schema{ "instance": { Type: schema.TypeString, @@ -29,6 +28,11 @@ func DataSourceSqlDatabaseInstanceLatestRecoveryTime() *schema.Resource { Computed: true, Description: `Timestamp, identifies the latest recovery time of the source instance.`, }, + "source_instance_deletion_time": { + Type: schema.TypeString, + Optional: true, + Description: `Timestamp, identifies when the source instance was deleted. If this instance is deleted, then you must set the timestamp.`, + }, }, } } @@ -39,7 +43,6 @@ func dataSourceSqlDatabaseInstanceLatestRecoveryTimeRead(d *schema.ResourceData, if err != nil { return err } - fv, err := tpgresource.ParseProjectFieldValue("instances", d.Get("instance").(string), "project", d, config, false) if err != nil { return err @@ -47,15 +50,21 @@ func dataSourceSqlDatabaseInstanceLatestRecoveryTimeRead(d *schema.ResourceData, project := fv.Project instance := fv.Name - latestRecoveryTime, err := config.NewSqlAdminClient(userAgent).Projects.Instances.GetLatestRecoveryTime(project, instance).Do() + deletionTime := d.Get("source_instance_deletion_time").(string) + + latestRecoveryTimeCall := config.NewSqlAdminClient(userAgent).Projects.Instances.GetLatestRecoveryTime(project, instance) + + if deletionTime != "" { + latestRecoveryTimeCall = latestRecoveryTimeCall.SourceInstanceDeletionTime(deletionTime) + } + + latestRecoveryTime, err := latestRecoveryTimeCall.Do() if err != nil { return err } - if err := d.Set("project", project); err != nil { return fmt.Errorf("Error setting project: %s", err) } - if err := d.Set("latest_recovery_time", latestRecoveryTime.LatestRecoveryTime); err != nil { return fmt.Errorf("Error setting latest_recovery_time: %s", err) } diff --git a/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time_test.go b/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time_test.go index 9c08ecfb1b25..7927f41bfa57 100644 --- a/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time_test.go +++ b/mmv1/third_party/terraform/services/sql/data_source_sql_database_instance_latest_recovery_time_test.go @@ -19,6 +19,9 @@ func TestAccDataSourceSqlDatabaseInstanceLatestRecoveryTime_basic(t *testing.T) PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + ExternalProviders: map[string]resource.ExternalProvider{ + "time": {}, + }, Steps: []resource.TestStep{ { Config: testAccDataSourceSqlDatabaseInstanceLatestRecoveryTime_basic(context), @@ -52,8 +55,15 @@ resource "google_sql_database_instance" "main" { deletion_protection = false } +resource "time_sleep" "wait_for_instance" { + // Wait 30 seconds after the instance is created + depends_on = [google_sql_database_instance.main] + create_duration = "330s" +} + data "google_sql_database_instance_latest_recovery_time" "default" { - instance = resource.google_sql_database_instance.main.name + instance = google_sql_database_instance.main.name + depends_on = [time_sleep.wait_for_instance] } `, context) } diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl index 4a62558b6fa0..d02487c81d95 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.tmpl @@ -1251,6 +1251,12 @@ API (for read pools, effective_availability_type may differ from availability_ty Optional: true, 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])?.`, }, + "source_instance_deletion_time": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: tpgresource.TimestampDiffSuppress(time.RFC3339Nano), + Description: `The timestamp of when the source instance was deleted for a clone from a deleted instance.`, + }, }, }, }, @@ -1675,6 +1681,7 @@ func expandCloneContext(configured []interface{}) (*sqladmin.CloneContext, strin PreferredZone: _cloneConfiguration["preferred_zone"].(string), DatabaseNames: databaseNames, AllocatedIpRange: _cloneConfiguration["allocated_ip_range"].(string), + SourceInstanceDeletionTime: _cloneConfiguration["source_instance_deletion_time"].(string), }, _cloneConfiguration["source_instance_name"].(string) } diff --git a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown index b62b8e234a4d..5eca1beeb10d 100644 --- a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown @@ -625,6 +625,10 @@ The optional `point_in_time_restore_context` block supports: * `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])?. +* `source_instance_deletion_time` - (Optional) The timestamp of when the source instance was deleted for a clone from a deleted instance. + + 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". + * `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. The optional `clone` block supports: @@ -641,6 +645,10 @@ The optional `clone` block supports: * `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])?. +* `source_instance_deletion_time` - (Optional) The timestamp of when the source instance was deleted for a clone from a deleted instance. + + 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". + The optional `restore_backup_context` block supports: **NOTE:** Restoring from a backup is an imperative action and not recommended via Terraform. Adding or modifying this block during resource creation/update will trigger the restore action after the resource is created/updated.