Skip to content

[AV-132963] Add local validation for backup and snapshot restore inputs#627

Draft
nimiyajoseph wants to merge 8 commits into
mainfrom
AV-132963-add-local-validation-for-backup-and-snapshot-restore-inputs
Draft

[AV-132963] Add local validation for backup and snapshot restore inputs#627
nimiyajoseph wants to merge 8 commits into
mainfrom
AV-132963-add-local-validation-for-backup-and-snapshot-restore-inputs

Conversation

@nimiyajoseph

@nimiyajoseph nimiyajoseph commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Jira

Description

Summary

This PR adds local Terraform validation coverage for backup, backup schedule, and cloud snapshot restore configuration edge cases that were previously accepted by terraform validate and only failed later during provider/API execution.

Changes include:

  • Reject couchbase-capella_backup.restore during backup creation using resource-level plan validation.
  • Reject couchbase-capella_backup.restore_times during backup creation at plan time.
  • Validate backup.restore.replace_ttl locally with allowed values: none, all, expired.
  • Validate nested backup_schedule.weekly_schedule enum fields locally:
    • day_of_week
    • start_at
    • incremental_every
    • retention_time
  • Add explicit validation coverage for cloud_snapshot_restores.filter:
    • invalid filter name
    • empty filter values

Tests Added

Total new acceptance tests added: 5

New tests:

  1. TestAccBackupResourceRestoreOnCreate
  2. TestAccBackupResourceRestoreInvalidReplaceTTL
  3. TestAccBackupScheduleResourceInvalidIncrementalEvery
  4. TestAccDatasourceCloudSnapshotRestoresEmptyFilterValues
  5. TestAccDatasourceCloudSnapshotRestoresInvalidFilterName

Also updated existing backup schedule negative tests to expect local validation errors instead of API/create-time failures:

  • invalid day_of_week
  • invalid retention_time
  • invalid start_at

Type of Change

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).
  • This change updates the ci/cd workflow.
  • Documentation fix/enhancement.

Manual Testing Approach

How was this change tested and do you have evidence? (REQUIRED: Select at least 1)

  • Manually tested
  • Unit tested
  • Acceptance tested
  • Unable to test / will not test (Please provide comments in section below)

Testing

Testing

Further comments

Copilot AI review requested due to automatic review settings June 2, 2026 11:18
@nimiyajoseph nimiyajoseph requested a review from a team as a code owner June 2, 2026 11:18
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown

No PR template selections were detected. Please make sure to fill out the PR template properly by selecting the appropriate checkboxes.

@factory-droid

factory-droid Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Droid finished @nimiyajoseph's task —— View job


@nimiyajoseph nimiyajoseph self-assigned this Jun 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens plan-time/local validation for backup- and snapshot-restore-related Terraform configurations so invalid inputs are rejected by terraform validate/plan rather than failing later during provider execution/API calls.

Changes:

  • Added ModifyPlan validation to block backup.restore and backup.restore_times when creating a couchbase-capella_backup.
  • Added local enum validation for backup.restore.replace_ttl and for backup_schedule.weekly_schedule fields (day_of_week, start_at, incremental_every, retention_time).
  • Added/updated acceptance tests to assert local validation errors for these edge cases (including cloud snapshot restore datasource filter validation scenarios).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/resources/backup.go Adds ResourceWithModifyPlan and create-time plan validation to reject restore-only fields during initial backup creation.
internal/resources/backup_schema.go Adds OneOf validation for restore.replace_ttl.
internal/resources/backup_schedule_schema.go Adds local enum/range-style validation for weekly schedule fields.
internal/errors/errors.go Introduces a new error constant for “restore must not be set while create backup”.
acceptance_tests/cloud_snapshot_restore_datasource_test.go Adds negative acceptance tests for invalid/empty filter inputs on the list datasource.
acceptance_tests/backup_schedule_acceptance_test.go Updates negative tests to expect local validation errors; adds a new negative test for incremental_every.
acceptance_tests/backup_acceptance_test.go Adds negative tests for restore on create and invalid replace_ttl.

Comment thread internal/resources/backup.go
Comment thread internal/errors/errors.go Outdated
@github-actions github-actions Bot added the bug Something isn't working label Jun 2, 2026

@factory-droid factory-droid Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated all 4 candidate comments against the full diff and existing discussion. None met the reporting gate for a concrete, actionable bug with a realistic trigger path and observable incorrect behavior, so no inline comments were posted.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread internal/resources/backup.go Outdated
Comment thread internal/resources/backup_schema.go Outdated
capellaschema.AddAttr(weeklyScheduleAttrs, "start_at", backupScheduleBuilder, int64Attribute(required), "WeeklySchedule")
capellaschema.AddAttr(weeklyScheduleAttrs, "incremental_every", backupScheduleBuilder, int64Attribute(required), "WeeklySchedule")
capellaschema.AddAttr(weeklyScheduleAttrs, "retention_time", backupScheduleBuilder, stringAttribute([]string{required}), "WeeklySchedule")
capellaschema.AddAttr(weeklyScheduleAttrs, "day_of_week", backupScheduleBuilder, stringAttribute([]string{required}, stringvalidator.OneOf("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday")), "WeeklySchedule")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you did supply the schema name here but also have manually defined the OneOf validators. Was there an issue with the automated validation? If so worth tracking with a ticket I would be happy to pick it up.

@nimiyajoseph nimiyajoseph Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is an issue with the automated validation path for this case.

The generated enum metadata exists, but it is stored under CreateScheduledBackupRequest using nested OpenAPI field paths:
"weeklySchedule.dayOfWeek" "weeklySchedule.startAt" "weeklySchedule.incrementalEvery" "weeklySchedule.retentionTime"

The schema code calls AddAttr on child Terraform fields like:
day_of_week start_at incremental_every retention_time

Current enum lookup converts those to candidates like dayOfWeek, startAt, etc., and only checks exact keys in the selected schema table. It does not match nested generated keys like weeklySchedule.dayOfWeek. So even if we pass "CreateScheduledBackupRequest" into AddAttr, the generated validator is not found for the nested weekly schedule fields. That is why the manual OneOf validators were still needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matty271828 matty271828 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note acceptance test failure looks related to this change:

=== CONT  TestAccBackupResourceRestoreInvalidReplaceTTL
    backup_acceptance_test.go:160: Step 1/1, expected an error with pattern, no match on: Error running pre-apply plan: exit status 1
        
        Error: Invalid Backup Restore Configuration
        
          with couchbase-capella_backup.tf_acc_backup_invalid_replace_ttl_lntibbwgwb,
          on terraform_plugin_test.tf line 34, in resource "couchbase-capella_backup" "tf_acc_backup_invalid_replace_ttl_lntibbwgwb":
          34: 	restore = {
          35: 		target_cluster_id       = "33333333-3333-3333-3333-333333333333"
          36: 		source_cluster_id       = "22222222-2222-2222-2222-222222222222"
          37: 		services                = ["data"]
          38: 		force_updates           = true
          39: 		auto_remove_collections = false
          40: 		replace_ttl             = "forever"
          41: 		replace_ttl_with        = "0"
          42: 		include_data            = "bucket.scope.collection"
          43: 		exclude_data            = null
          44: 		filter_keys             = null
          45: 		filter_values           = null
          46: 		map_data                = null
          47: 	}
        
        restore must not be set during backup creation

@nimiyajoseph nimiyajoseph marked this pull request as draft June 9, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Comment thread internal/resources/backup.go Outdated
Comment thread internal/resources/backup_schedule_schema.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants