Skip to main content

Update Terraform after upgrading Aiven for Caching to Aiven for Valkey™

Update Terraform configuration and state after upgrading from Aiven for Caching to Aiven for Valkey™. Ensure your infrastructure setup accurately reflects the upgraded service for seamless management and deployment.

Prerequisites

Step 1: Modify the Terraform Configuration

  • Replace aiven_redis and aiven_redis_user resources in your configuration with aiven_valkey and aiven_valkey_user.

  • Update Aiven for Caching-specific configuration parameters to their Aiven for Valkey equivalents. For example, change redis_timeout to valkey_timeout.

    Example configuration:

    # Before: Aiven for Caching configuration
    resource "aiven_redis" "caching_service" {
    project = "PROJECT_NAME"
    cloud_name = "CLOUD_REGION"
    plan = "PLAN_NAME"
    service_name = "SERVICE_NAME"
    redis_user_config {
    redis_timeout = 300
    }
    }
    # After: Aiven for Valkey configuration
    resource "aiven_valkey" "caching_service" {
    project = "PROJECT_NAME"
    cloud_name = "CLOUD_REGION"
    plan = "PLAN_NAME"
    service_name = "SERVICE_NAME"
    valkey_user_config {
    valkey_timeout = 300
    }
    }

Step 2: Update the Terraform state

  1. Import each Aiven for Valkey resource into the Terraform state:

    terraform import aiven_valkey.valkey_service PROJECT_NAME/SERVICE_NAME
  2. Import users associated with the Aiven for Valkey service. For each user, run:

    terraform import aiven_valkey_user.user PROJECT_NAME/SERVICE_NAME/USERNAME
  3. Remove any Aiven for Caching resources from the Terraform state to prevent duplicates:

    terraform state rm aiven_redis.caching_service

Step 3: Verify and apply changes

  1. Run terraform plan to confirm that the state and configuration are aligned:

    terraform plan
  2. Apply the changes to finalize the update:

    terraform apply