Skip to content

Verify terraform state [RUN ALL RSPEC] [RUN AS-IF-FOSS]

Aakriti Gupta requested to merge ag-verify-terraform-state into master

What does this MR do?

This MR adds verification for terraform states:

  • Add verification through self-service framework for Terraform States, using terraform_state_versions table

  • Add related metrics to API and Prometheus

  • Update metrics doc

I have cross checked with the checklist in the new issue template for adding replication/verification to blob types.

Resolves: #322886 (closed)

Things to todo:

  • Test verification manually
  • Test metrics: replication and verification metrics should now be available in the API, the Admin > Geo > Nodes view, and Prometheus

Manual Testing

Setup

  • All migrations on default db, geo db on locally run gdk
  • FF geo_terraform_state_version_verification is enabled on primary

Observations

  1. Terraform State Version verification shows in UI

Screenshot_2021-05-03_at_15.21.53

Screenshot_2021-05-03_at_15.20.51

  1. Created terraform state and state version records in the db on the primary, e.g.
Terraform::State.new(project_id: 18, name: "terraform-state").save!
Terraform::StateVersion.new(terraform_state_id: 1, version: 1, file_store: 1, file: f).save!
  1. Confirmed - Verification works

Primary

Screenshot_2021-05-03_at_17.19.19

Secondary

Screenshot_2021-05-03_at_17.18.59

All terraform states got replicated and verified.

Metrics

  1. Usage statistics payload includes:
 "enablement": {
      "geo_secondary_web_oauth_users": 1,
      "geo_node_usage": [
        {
          "terraform_state_versions_count": 3,
          "terraform_state_versions_checksum_total_count": null,
          "terraform_state_versions_checksummed_count": null,
          "terraform_state_versions_checksum_failed_count": null,
          "terraform_state_versions_synced_count": 3,
          "terraform_state_versions_failed_count": 0,
          "terraform_state_versions_registry_count": 3,
          "terraform_state_versions_verification_total_count": 3,
          "terraform_state_versions_verified_count": 3,
          "terraform_state_versions_verification_failed_count": 0,
  1. Terraform state versions' related data included in GET /geo_nodes/status API response:
[
  {
    "geo_node_id": 1,
    "terraform_state_versions_count": 3,
    "terraform_state_versions_checksum_total_count": 3,
    "terraform_state_versions_checksummed_count": 3,
    "terraform_state_versions_checksum_failed_count": 0,
    "terraform_state_versions_synced_count": null,
    "terraform_state_versions_failed_count": null,
    "terraform_state_versions_registry_count": null,
    "terraform_state_versions_verification_total_count": null,
    "terraform_state_versions_verified_count": null,
    "terraform_state_versions_verification_failed_count": null,
    "terraform_state_versions_synced_in_percentage": "0.00%",
    "terraform_state_versions_verified_in_percentage": "0.00%",
  },
  {
    "geo_node_id": 5,
    "terraform_state_versions_count": 3,
    "terraform_state_versions_checksum_total_count": null,
    "terraform_state_versions_checksummed_count": null,
    "terraform_state_versions_checksum_failed_count": null,
    "terraform_state_versions_synced_count": 3,
    "terraform_state_versions_failed_count": 0,
    "terraform_state_versions_registry_count": 3,
    "terraform_state_versions_verification_total_count": 3,
    "terraform_state_versions_verified_count": 3,
    "terraform_state_versions_synced_in_percentage": "100.00%",
    "terraform_state_versions_verified_in_percentage": "100.00%",
  }
]

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Michael Kozono

Merge request reports