OpsLevel / terraform-provider-opslevel

Terraform provider for OpsLevel.com
https://registry.terraform.io/providers/OpsLevel/opslevel/latest/docs
MIT License
8 stars 5 forks source link

State Schema Version problem #417

Closed rocktavious closed 2 weeks ago

rocktavious commented 1 month ago

A customer was trying to use our 1.2.1 release and ran into this error message

╷
│ Error: Unable to Read Previously Saved State for UpgradeResourceState
│ 
│   with module.infrastructure_catalog.opslevel_infrastructure.mysql_auth_78982b18,
│   on infrastructure-catalog/databases.tf line 1, in resource "opslevel_infrastructure" "mysql_auth_78982b18":
│    1: resource "opslevel_infrastructure" "mysql_auth_78982b18" {
│ 
│ There was an error reading the saved resource state using the prior
│ resource schema defined for version 0 upgrade.
│ 
│ Please report this to the provider developer:
│ 
│ AttributeName("provider_data"): invalid JSON, expected "[", got "{"

The configuration was

resource "opslevel_infrastructure" "mysql_auth_XXXXX" {
  schema = "Database"
  owner  = var.teams["shared_services"].id
  provider_data = {
    account = "prod-dbs"
    name    = "gcp"
    type    = "CloudSQL"
    url     = "https://console.cloud.google.com/sql/instances/mysql-auth-XXXXX/overview?project=prod-dbs"
  }
  data = jsonencode({
    external_id                     = "mysql-auth-XXXXXX"
    name                            = "auth MySQL (mysql-auth)" # database-name (instance-name prefix)
    zone                            = "us-east-4a"
    engine                          = "MySQL"
    publicly_accessible             = false
    instance_type                   = "db-n1-standard-8"
    maintenance_window              = "Saturday"
    multi_zone_availability_enabled = true # Highly available (regional)
  })
}

Not entirely sure if this is a state upgrader problem or if we didn't handle the schema version correctly.

rocktavious commented 1 month ago

The customer downgraded to 1.1.0 and it fixed / worked.

bassco commented 1 month ago

We experienced a similar issue when attempting the jump from 1.1.1 to 1.2.3 for resource opslevel_check_repository_file

Error: Unable to Read Previously Saved State for UpgradeResourceState

  with opslevel_check_repository_file.adr-m-0004,
  on adr_m_0004.tf line 112, in resource "opslevel_check_repository_file" "adr-m-0004":
 112: resource "opslevel_check_repository_file" "adr-m-0004" {

There was an error reading the saved resource state using the prior resource
schema defined for version 0 upgrade.

Please report this to the provider developer:

AttributeName("file_contents_predicate"): invalid JSON, expected "[", got "{"

Here is the snippet

resource "opslevel_check_repository_file" "adr-m-0004" {
  name              = "ADR-M-0004-has-serverless-or-lambda-file"
  enable_on         = "2024-08-31T00:00:00.000000Z"
  use_absolute_root = false

  category         = opslevel_rubric_category.repository.id
  level            = opslevel_rubric_level.gold.id
  owner            = data.opslevel_team.core_tech_engineering_operations.id
  filter           = opslevel_filter.adr-m-0004.id
  directory_search = false
  filepaths = [
    "serverless.yaml",
    "serverless.yml",
    "atlantis/infrastructure/advertstatisticserver-lambda.tf",
    "atlantis/infrastructure/loadfromreservoir-lambda.tf",
    "terraform/infrastructure/lambda.tf"
  ]
  file_contents_predicate = {
    type = "does_not_exist"
  }
  notes = "See here for more information about the compliance with the ADR: [REDACTED]

  lifecycle {
    ignore_changes = [
      enabled,
      enable_on
    ]
  }
}

Using 1.1.1 here is the redacted state for this object.

terragrunt state show opslevel_check_repository_file.adr-m-0004
# opslevel_check_repository_file.adr-m-0004:
resource "opslevel_check_repository_file" "adr-m-0004" {
    category                = "REDACTED"
    description             = "None of these repo files 'serverless.yaml', 'serverless.yml', 'atlantis/infrastructure/advertstatisticserver-lambda.tf', 'atlantis/infrastructure/loadfromreservoir-lambda.tf', 'terraform/infrastructure/lambda.tf' exists."
    directory_search        = false
    enable_on               = "2024-08-31T00:00:00.000000Z"
    enabled                 = false
    file_contents_predicate = {
        type = "does_not_exist"
    }
    filepaths               = [
        "serverless.yaml",
        "serverless.yml",
        "atlantis/infrastructure/advertstatisticserver-lambda.tf",
        "atlantis/infrastructure/loadfromreservoir-lambda.tf",
        "terraform/infrastructure/lambda.tf",
    ]
    filter                  = "REDACTED"
    id                      = "REDACTED"
    level                   = "REDACTED"
    name                    = "ADR-M-0004-has-serverless-or-lambda-file"
    notes                   = "See here for more information about the compliance with the ADR: REDACTED"
    owner                   = "REDACTED"
    use_absolute_root       = false
}

Other affected resources in our codebase:

HTH the investigation

davidbloss commented 3 weeks ago

Similar issue reported here in customer-support-issues

rocktavious commented 2 weeks ago

Released 1.1.4 as a stop gap for jumping to 1.2.5

rocktavious commented 2 weeks ago

Add a callout in our migration guide