diff --git a/mmv1/products/spanner/Database.yaml b/mmv1/products/spanner/Database.yaml index ea33c9ad211c..bcb1c3c21033 100644 --- a/mmv1/products/spanner/Database.yaml +++ b/mmv1/products/spanner/Database.yaml @@ -120,8 +120,6 @@ properties: the values 1d, 24h, 1440m, and 86400s are equivalent. Default value is 1h. If this property is used, you must avoid adding new DDL statements to `ddl` that update the database's version_retention_period. - validation: !ruby/object:Provider::Terraform::Validation - function: ValidateDatabaseRetentionPeriod default_from_api: true - !ruby/object:Api::Type::Array name: 'ddl' diff --git a/mmv1/templates/terraform/constants/spanner_database.go.erb b/mmv1/templates/terraform/constants/spanner_database.go.erb index bc2c1ae45088..926488ac8c68 100644 --- a/mmv1/templates/terraform/constants/spanner_database.go.erb +++ b/mmv1/templates/terraform/constants/spanner_database.go.erb @@ -44,44 +44,6 @@ func resourceSpannerDBDdlCustomDiff(_ context.Context, diff *schema.ResourceDiff return resourceSpannerDBDdlCustomDiffFunc(diff) } -func ValidateDatabaseRetentionPeriod(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - valueError := fmt.Errorf("version_retention_period should be in range [1h, 7d], in a format resembling 1d, 24h, 1440m, or 86400s") - - r := regexp.MustCompile("^(\\d{1}d|\\d{1,3}h|\\d{2,5}m|\\d{4,6}s)$") - if !r.MatchString(value) { - errors = append(errors, valueError) - return - } - - unit := value[len(value)-1:] - multiple := value[:len(value)-1] - num, err := strconv.Atoi(multiple) - if err != nil { - errors = append(errors, valueError) - return - } - - if unit == "d" && (num < 1 || num > 7) { - errors = append(errors, valueError) - return - } - if unit == "h" && (num < 1 || num > 7*24) { - errors = append(errors, valueError) - return - } - if unit == "m" && (num < 1*60 || num > 7*24*60) { - errors = append(errors, valueError) - return - } - if unit == "s" && (num < 1*60*60 || num > 7*24*60*60) { - errors = append(errors, valueError) - return - } - - return -} - func resourceSpannerDBVirtualUpdate(d *schema.ResourceData, resourceSchema map[string]*schema.Schema) bool { // deletion_protection is the only virtual field if d.HasChange("deletion_protection") { diff --git a/mmv1/third_party/terraform/services/spanner/resource_spanner_database_test.go.erb b/mmv1/third_party/terraform/services/spanner/resource_spanner_database_test.go.erb index 3eb94e373be8..75f625c37217 100644 --- a/mmv1/third_party/terraform/services/spanner/resource_spanner_database_test.go.erb +++ b/mmv1/third_party/terraform/services/spanner/resource_spanner_database_test.go.erb @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" - "github.com/hashicorp/terraform-provider-google/google/services/spanner" ) func TestAccSpannerDatabase_basic(t *testing.T) { @@ -466,77 +465,6 @@ resource "google_spanner_database" "basic" { `, instanceName, instanceName, databaseName) } -// Unit Tests for validation of retention period argument -func TestValidateDatabaseRetentionPeriod(t *testing.T) { - t.Parallel() - testCases := map[string]struct { - input string - expectError bool - }{ - // Not valid input - "empty_string": { - input: "", - expectError: true, - }, - "number_with_no_unit": { - input: "1", - expectError: true, - }, - "less_than_1h": { - input: "59m", - expectError: true, - }, - "more_than_7days": { - input: "8d", - expectError: true, - }, - // Valid input - "1_hour_in_secs": { - input: "3600s", - expectError: false, - }, - "1_hour_in_mins": { - input: "60m", - expectError: false, - }, - "1_hour_in_hours": { - input: "1h", - expectError: false, - }, - "7_days_in_secs": { - input: fmt.Sprintf("%ds", 7*24*60*60), - expectError: false, - }, - "7_days_in_mins": { - input: fmt.Sprintf("%dm", 7*24*60), - expectError: false, - }, - "7_days_in_hours": { - input: fmt.Sprintf("%dh", 7*24), - expectError: false, - }, - "7_days_in_days": { - input: "7d", - expectError: false, - }, - } - - for tn, tc := range testCases { - t.Run(tn, func(t *testing.T) { - _, errs := spanner.ValidateDatabaseRetentionPeriod(tc.input, "foobar") - var wantErrCount string - if tc.expectError { - wantErrCount = "1+" - } else { - wantErrCount = "0" - } - if (len(errs) > 0 && tc.expectError == false) || (len(errs) == 0 && tc.expectError == true) { - t.Errorf("failed, expected `%s` test case validation to have %s errors", tn, wantErrCount) - } - }) - } -} - func TestAccSpannerDatabase_deletionProtection(t *testing.T) { acctest.SkipIfVcr(t) t.Parallel()