-
Notifications
You must be signed in to change notification settings - Fork 240
Description
SDK version
Latest
I'm implementing a switchover, where a primary becomes the replica, and the replica becomes the primary in one apply. This causes some issues in testing. After this operation is applied, a refresh or plan is needed to verify that plan is not empty. Currently, acceptance tests say that after applying this config, the plan is both empty and non-empty.
Here's a summary of https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/resource/testing_new_config.go
Line 70: Apply config
Line 117: WorkingDir.CreatePlan()
Line 133:
if !planIsEmpty(plan) && !step.ExpectNonEmptyPlan {
check if plan was not empty
}
At this time, plan is "not empty", we just need a refresh and it will be an empty plan.
...
line 149: we do a refresh. Now, the plan is empty. (we should've done this before we do the plan check in line 133)
line 161: we do another plan after the refresh.
Now, here is why we see "schrodinger's plan"; plan is "both empty and non-empty"
line 188:
else if step.ExpectNonEmptyPlan && planIsEmpty(plan) {
check and expect that plan is empty
}
The plan was non-empty before refresh in line 149, and is now empty.
Terraform Configuration Files
Initially:
resource "google_sql_database_instance" "original-primary" {
name = "%s"
region = "us-east7"
database_version = "SQLSERVER_2019_ENTERPRISE"
deletion_protection = false
root_password = "sqlserver1"
settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"
}
}
resource "google_sql_database_instance" "original-replica" {
name = "%s"
region = "us-west2"
database_version = "SQLSERVER_2019_ENTERPRISE"
master_instance_name = google_sql_database_instance.original-primary.name
deletion_protection = false
root_password = "sqlserver1"
replica_configuration {
cascadable_replica = true
}
settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"
}
}
`, primaryName, replicaName)
...
In the next config step, we apply this config:
resource "google_sql_database_instance" "original-primary" {
name = "%s"
region = "us-east7"
database_version = "SQLSERVER_2019_ENTERPRISE"
deletion_protection = false
root_password = "sqlserver1"
instance_type = "READ_REPLICA_INSTANCE"
master_instance_name = "%s"
replica_configuration {
cascadable_replica = true
}
replica_names = []
settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"
}
}
resource "google_sql_database_instance" "original-replica" {
name = "%s"
region = "us-west2"
database_version = "SQLSERVER_2019_ENTERPRISE"
deletion_protection = false
root_password = "sqlserver1"
instance_type = "CLOUD_SQL_INSTANCE"
replica_names = [google_sql_database_instance.original-primary.name]
settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"
}
}
`, primaryName, replicaName, replicaName)
After applying this config step, a refresh is needed before we do checks.
I have:
{
Config: googleSqlDatabaseInstance_switchover(primaryName, replicaName),
ExpectNonEmptyPlan: true, // I commend and uncomment, and the error says that this step is both empty and non-empty.
},
Expected Behavior
When I commend and uncomment ExpectNonEmptyPlan: true, and the error should say that the step is either empty and non-empty, not BOTH.
Actual Behavior
The error says that the config test step results in an empty, and also non-empty plan.
Steps to Reproduce
Run this test with my pull request (switchover implementation)
GoogleCloudPlatform/magic-modules#11850