Closed
Description
terraform-plugin-testing version
1.6.0
Relevant provider source code
Migration test that uses an old version 1.11.0
of our provider and then runs a plan operation using latest build.
func TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_maintainsBackwardCompatibility(t *testing.T) {
var (
...
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
CheckDestroy: acc.CheckClusterDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: "1.11.0",
Source: "mongodb/mongodbatlas",
},
},
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "name", name),
),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: config,
ConfigPlanChecks: resource.ConfigPlanChecks{
PostApplyPreRefresh: []plancheck.PlanCheck{
acc.DebugPlan(),
},
},
PlanOnly: true,
},
},
})
}
Relevant attribute definition from version 1.11.0, which was removed in version 1.12.0
.....,
"bi_connector": {
Type: schema.TypeMap,
Optional: true,
Deprecated: "use bi_connector_config instead",
ConflictsWith: []string{"bi_connector_config"},
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
Terraform Configuration Files
Note that bi_connector
attribute is not defined.
resource "mongodbatlas_cluster" "test" {
project_id = mongodbatlas_project.cluster_project.id
name = %[3]q
disk_size_gb = 100
cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "EU_CENTRAL_1"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}
cloud_backup = %[4]t
pit_enabled = %[4]t
retain_backups_enabled = true
auto_scaling_disk_gb_enabled = %[5]t
provider_name = "AWS"
provider_instance_size_name = "M30"
}
Expected Behavior
Test is running successfully with version 1.5.1 of terraform-plugin-testing.
When running this scenario manually no issues are encountered:
- Resource is created with version 1.11.0 and as a result having
"bi_connector": null
defined in the state. - An empty plan is returned when running with the latest version of our provider (which does not have this attribute defined in the schema).
Actual Behavior
2023-12-21T22:45:14.929+0100 [DEBUG] sdk.helper_resource: Stopping providers: test_terraform_path=/Users/agustin.bettati/bin/terraform test_working_directory=/var/folders/d6/zqxkvmcs15gb5xtn30rnxz780000gp/T/plugintest3689099347 test_step_number=2 test_name=TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_maintainsBackwardCompatibility
2023-12-21T22:45:14.929+0100 [ERROR] sdk.helper_resource: Error retrieving state, there may be dangling resources: test_working_directory=/var/folders/d6/zqxkvmcs15gb5xtn30rnxz780000gp/T/plugintest3689099347
error=
| exit status 1
| Failed to marshal state to json: unsupported attribute "bi_connector"
test_step_number=2 test_name=TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_maintainsBackwardCompatibility test_terraform_path=/Users/agustin.bettati/bin/terraform
--- FAIL: TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_maintainsBackwardCompatibility (473.86s)
To provide more context, bi_connector
is an attribute that was removed in version 1.12.0, meaning it is defined in the state as null when the resource is created (not defined in the config) with version 1.11.0, and then when using the latest version (higher than 1.12.0) as the attribute is unknown it would seem to cause an error in the step 2.
Steps to Reproduce
- Two different versions of same provider must be available, and the latest version must have a removed an optional attribute definition.
- Define a migration test using version 1.6.0 of terraform-plugin-testing in which state is created having the removed attribute defined with null value, and then run a plan with latest version.