diff --git a/acceptance/bundle/migrate/auto-migrate-clean/output.txt b/acceptance/bundle/migrate/auto-migrate-clean/output.txt index cd07b8b89c6..0526bae7622 100644 --- a/acceptance/bundle/migrate/auto-migrate-clean/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-clean/output.txt @@ -17,10 +17,10 @@ direct_drymigrate_warnings false >>> [CLI] bundle deploy Warn: Direct engine requested in bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11 but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... -Migrated 1 resource to direct deployment engine. Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Migrating state to direct deployment engine (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... +Migrated 1 resource to direct deployment engine. >>> print_migration_telemetry direct_migrated_via_config true diff --git a/acceptance/bundle/migrate/auto-migrate-conversion-failure/databricks.yml b/acceptance/bundle/migrate/auto-migrate-conversion-failure/databricks.yml new file mode 100644 index 00000000000..25e8ccbf913 --- /dev/null +++ b/acceptance/bundle/migrate/auto-migrate-conversion-failure/databricks.yml @@ -0,0 +1,13 @@ +bundle: + name: test-bundle + +resources: + secret_scopes: + my_scope: + name: my-scope + permissions: + # An unknown level: SecretScopeFixups rejects it when it prepares the + # config for the direct engine, so the state conversion fails while the + # terraform deploy itself succeeds. + - level: BOGUS + user_name: someone@example.com diff --git a/acceptance/bundle/migrate/auto-migrate-conversion-failure/out.test.toml b/acceptance/bundle/migrate/auto-migrate-conversion-failure/out.test.toml new file mode 100644 index 00000000000..0938e678987 --- /dev/null +++ b/acceptance/bundle/migrate/auto-migrate-conversion-failure/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] diff --git a/acceptance/bundle/migrate/auto-migrate-conversion-failure/output.txt b/acceptance/bundle/migrate/auto-migrate-conversion-failure/output.txt new file mode 100644 index 00000000000..7fa3a09a55e --- /dev/null +++ b/acceptance/bundle/migrate/auto-migrate-conversion-failure/output.txt @@ -0,0 +1,46 @@ + +=== Not opted in: the conversion failure is reported as a failed dry run +>>> DATABRICKS_BUNDLE_ENGINE=terraform [CLI] bundle deploy +Warning: invalid value "BOGUS" for enum field. Valid values are [READ WRITE MANAGE] + at resources.secret_scopes.my_scope.permissions[0].level + +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Created secret_scopes.my_scope +Created secret_scopes.my_scope.permissions +Files: 5 uploaded, 0 deleted +Resources: 2 created, 0 changed, 0 deleted, 0 unchanged +Warn: post-deploy dry-run migration to direct: unknown permission level "BOGUS" for secret scope +Warn: The warnings above are from a dry-run migration to the direct deployment engine (https://docs.databricks.com/aws/en/dev-tools/bundles/direct). +Your deployment is not affected and works normally, but you may experience these issues when migrating to the direct deployment engine. +Please forward these warnings to dabs-feedback@databricks.com + +>>> print_migration_telemetry +direct_drymigrate_success false +direct_drymigrate_warnings false +direct_migrate_error_template unknown permission level %q for secret scope + +=== Opted in: the same failure stops the automatic migration +>>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy +Warning: invalid value "BOGUS" for enum field. Valid values are [READ WRITE MANAGE] + at resources.secret_scopes.my_scope.permissions[0].level + +Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... +Files: 2 uploaded, 0 deleted +Resources: 0 created, 0 changed, 0 deleted, 2 unchanged +Warn: post-deploy dry-run migration to direct: unknown permission level "BOGUS" for secret scope +Warn: The warnings above are from a dry-run migration to the direct deployment engine (https://docs.databricks.com/aws/en/dev-tools/bundles/direct). +Your deployment is not affected and works normally, but you may experience these issues when migrating to the direct deployment engine. +Please forward these warnings to dabs-feedback@databricks.com +Warn: Direct engine was requested but the dry-run migration reported issues; automatic migration to the direct deployment engine is stopped. Address the issues above or run "databricks bundle deployment migrate" manually. + +>>> print_migration_telemetry +direct_migrate_error true +direct_migrate_error_template unknown permission level %q for secret scope + +=== State is still terraform, so nothing was migrated + +>>> find .databricks/bundle -name resources.json -type f + +>>> find .databricks/bundle -name terraform.tfstate* -type f +.databricks/bundle/default/terraform/terraform.tfstate diff --git a/acceptance/bundle/migrate/auto-migrate-conversion-failure/script b/acceptance/bundle/migrate/auto-migrate-conversion-failure/script new file mode 100644 index 00000000000..efad1c5fab8 --- /dev/null +++ b/acceptance/bundle/migrate/auto-migrate-conversion-failure/script @@ -0,0 +1,20 @@ +export DATABRICKS_BUNDLE_ENGINE= + +# An unknown permission level is only a warning for the terraform deploy, but +# SecretScopeFixups rejects it while preparing the config for the direct engine. +# That is a state conversion failure: no API call is involved, so unlike the +# commit failures it cannot be produced by injecting a fault. + +title "Not opted in: the conversion failure is reported as a failed dry run" +trace DATABRICKS_BUNDLE_ENGINE=terraform $CLI bundle deploy +trace print_migration_telemetry +rm -f out.requests.txt + +title "Opted in: the same failure stops the automatic migration" +trace DATABRICKS_BUNDLE_ENGINE=direct $CLI bundle deploy +trace print_migration_telemetry +rm -f out.requests.txt + +title "State is still terraform, so nothing was migrated\n" +trace find .databricks/bundle -name "resources.json" -type f +trace find .databricks/bundle -name "terraform.tfstate*" -type f diff --git a/acceptance/bundle/migrate/auto-migrate-conversion-failure/test.toml b/acceptance/bundle/migrate/auto-migrate-conversion-failure/test.toml new file mode 100644 index 00000000000..50abf12f70b --- /dev/null +++ b/acceptance/bundle/migrate/auto-migrate-conversion-failure/test.toml @@ -0,0 +1,3 @@ +# The unknown permission level is deliberate; the enum warning is part of what +# this test asserts. +Ignore = [".databricks"] diff --git a/acceptance/bundle/migrate/auto-migrate-direct-only-envvar/output.txt b/acceptance/bundle/migrate/auto-migrate-direct-only-envvar/output.txt index 1254e8c2433..e4502558839 100644 --- a/acceptance/bundle/migrate/auto-migrate-direct-only-envvar/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-direct-only-envvar/output.txt @@ -13,10 +13,10 @@ Resources: 1 created, 0 changed, 0 deleted, 0 unchanged >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... -Migrated 1 resource to direct deployment engine. Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 2 unchanged +Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... +Migrated 1 resource to direct deployment engine. >>> print_migration_telemetry direct_migrated_via_env true diff --git a/acceptance/bundle/migrate/auto-migrate-direct-only/output.txt b/acceptance/bundle/migrate/auto-migrate-direct-only/output.txt index 0811eaca457..a0103ed982b 100644 --- a/acceptance/bundle/migrate/auto-migrate-direct-only/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-direct-only/output.txt @@ -23,10 +23,10 @@ json.plan.resources.instance_pools.pool.action = "skip"; >>> [CLI] bundle deploy Warn: Direct engine requested in bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11 but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... -Migrated 1 resource to direct deployment engine. Files: 3 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 2 unchanged +Migrating state to direct deployment engine (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... +Migrated 1 resource to direct deployment engine. >>> print_migration_telemetry direct_migrated_via_config true diff --git a/acceptance/bundle/migrate/auto-migrate-empty-tfstate/output.txt b/acceptance/bundle/migrate/auto-migrate-empty-tfstate/output.txt index 56061ed71c2..a84f340e2c7 100644 --- a/acceptance/bundle/migrate/auto-migrate-empty-tfstate/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-empty-tfstate/output.txt @@ -3,9 +3,9 @@ >>> [CLI] bundle deploy Warn: Direct engine requested in bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11 but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Removing empty terraform state; direct engine will be used on the next deploy (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... Files: 4 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 0 unchanged +Removing empty terraform state; direct engine will be used on the next deploy (opted in via bundle.engine setting at [TEST_TMP_DIR]/databricks.yml:3:11)... === Terraform state is renamed to .backup; no resources.json (empty state, nothing to persist) diff --git a/acceptance/bundle/migrate/auto-migrate-envvar/output.txt b/acceptance/bundle/migrate/auto-migrate-envvar/output.txt index 8e6b0cc136c..9c741646a7f 100644 --- a/acceptance/bundle/migrate/auto-migrate-envvar/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-envvar/output.txt @@ -14,10 +14,10 @@ direct_drymigrate_warnings false >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... -Migrated 1 resource to direct deployment engine. Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... +Migrated 1 resource to direct deployment engine. >>> print_migration_telemetry direct_migrated_via_env true diff --git a/acceptance/bundle/migrate/auto-migrate-push-failure/output.txt b/acceptance/bundle/migrate/auto-migrate-push-failure/output.txt index 74412d94a92..be57bcbea10 100644 --- a/acceptance/bundle/migrate/auto-migrate-push-failure/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-push-failure/output.txt @@ -14,13 +14,14 @@ direct_drymigrate_warnings false >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... -Warn: automatic migration to direct engine failed: pushing direct state to workspace: access denied: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... +Warn: automatic migration to direct engine failed: pushing direct state to workspace: access denied: /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/state/resources.json >>> print_migration_telemetry direct_migrate_commit_error true +direct_migrate_commit_error_template pushing direct state to workspace: access denied [403 INJECTED] === Local state was NOT rewritten (still terraform) @@ -33,10 +34,10 @@ direct_migrate_commit_error true >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... -Migrated 1 resource to direct deployment engine. Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... +Migrated 1 resource to direct deployment engine. >>> print_migration_telemetry direct_migrated_via_env true diff --git a/acceptance/bundle/migrate/auto-migrate-tfbackup-failure/output.txt b/acceptance/bundle/migrate/auto-migrate-tfbackup-failure/output.txt index 19980cd3060..53e558b0c39 100644 --- a/acceptance/bundle/migrate/auto-migrate-tfbackup-failure/output.txt +++ b/acceptance/bundle/migrate/auto-migrate-tfbackup-failure/output.txt @@ -14,13 +14,14 @@ direct_drymigrate_warnings false >>> DATABRICKS_BUNDLE_ENGINE=direct [CLI] bundle deploy Warn: Direct engine requested in DATABRICKS_BUNDLE_ENGINE environment variable but the existing state uses "terraform". Deploying on "terraform"; will attempt to migrate the state to the direct engine after this deploy. Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/test-bundle/default/files... -Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... -Warn: automatic migration to direct engine failed: pushing direct state to workspace: deleting remote terraform state: Fault injected by test. Files: 2 uploaded, 0 deleted Resources: 0 created, 0 changed, 0 deleted, 1 unchanged +Migrating state to direct deployment engine (opted in via DATABRICKS_BUNDLE_ENGINE environment variable)... +Warn: automatic migration to direct engine failed: pushing direct state to workspace: deleting remote terraform state: Fault injected by test. >>> print_migration_telemetry direct_migrate_commit_error true +direct_migrate_commit_error_template pushing direct state to workspace: deleting remote terraform state: %w [403 INJECTED] === Local state was NOT rewritten (still terraform) diff --git a/acceptance/bundle/migrate/script.prepare b/acceptance/bundle/migrate/script.prepare index 9de2f19d437..27fb59bb8a4 100644 --- a/acceptance/bundle/migrate/script.prepare +++ b/acceptance/bundle/migrate/script.prepare @@ -1,7 +1,12 @@ -# Filter print_telemetry_bool_values output to auto-migration keys -# (direct_drymigrate_*, direct_migrate_*, direct_migrated_via_*). Callers -# clear out.requests.txt themselves; some tests want to keep it for a -# subsequent print_requests.py assertion. +# Filter telemetry output to auto-migration keys (direct_drymigrate_*, +# direct_migrate_*, direct_migrated_via_*), booleans first and then the +# PII-free error template that says which failure a direct_migrate_error or +# direct_drymigrate_success=false was. +# +# Call it right after the deploy whose telemetry you want, so a block covers +# exactly one deploy. It does not clear out.requests.txt: callers do that +# themselves, since some want it kept for a subsequent print_requests.py. print_migration_telemetry() { print_telemetry_bool_values | grep '^direct_' || true + print_telemetry_error_templates | grep '^direct_' || true } diff --git a/acceptance/script.prepare b/acceptance/script.prepare index d71d37aae9b..1dedb40b1da 100644 --- a/acceptance/script.prepare +++ b/acceptance/script.prepare @@ -123,6 +123,12 @@ print_telemetry_bool_values() { jq -r 'select(.path? == "/telemetry-ext") | (.body.protoLogs // [])[] | fromjson | ( (.entry // .) | (.databricks_cli_log.bundle_deploy_event.experimental.bool_values // []) ) | map("\(.key) \(.value)") | .[]' out.requests.txt | grep -v '^engine_terraform_' | sort } +# Print the PII-free error templates the deploy event carries, one " +#