• Harsh Chouraria's avatar
    Add Backup and Restore tasks for Terraform States · 58a8d4f8
    Harsh Chouraria authored
    Reuses standard file upload storage to cover Terraform
    states backup
    
    Adds a seed for generating terraform state files
    under each project
    
    Manual testing (in local GDK env):
    
    - Verfied seed addition via `bin/rake db:seed_fu FILTER=terraform`
    - Verified seed addition is repeatable, with no-ops if versions
      pre-exist
    - Created backup: `bin/rake gitlab:backup:create`
    - Verified output shows up:
    
    ```
    2021-06-05 23:48:54 +0530 -- Dumping terraform states ...
    2021-06-05 23:48:54 +0530 -- done
    ```
    
    - Verified tar contains terraform_state.tar.gz
    - Verified terraform_state.tar.gz carries content
    - Destroyed all records: `Terraform::State.destroy_all`
    - Deleted all files: `rm -rf shared/terraform_state/*`
    - Performed restore: `bin/rake gitlab:backup:restore`
    - Verified `Terraform::State.all` shows back older records
    - Verified association of builds to some of these records
    - Verified `shared/terraform_state/` is repopulated
    - Verified `Terraform::StateVersion.each do |sv| pp sv.file.read end`
      works and shows the seed-added data
    - Verified skipping of `terraform_state` keyword works:
    
    ```
    2021-06-06 00:11:33 +0530 -- Dumping terraform states ...
    2021-06-06 00:11:33 +0530 -- [SKIPPED]
    ```
    
    Verified with same workflow as above (backup, destroy, delete,
    then restore) that skipped backup variant does not contain
    `terraform_state.tar.gz` and does not show up those files after
    restore
    
    Miscellany:
    
    - Adds a missing test for LFS backups
    - Adds File operation fixes to neighboring tests
      so when they fail RSpec is able to show diffs
    - Modified test validates unknown SKIP values not
      breaking backups
      - This is useful to catch any regressions during
        upgrades where pre-installs scripts may refer
        to a new SKIP value that isn't recognized by
        the old version
    
    Changelog: added
    58a8d4f8
lfs_spec.rb 1022 Bytes