diff --git a/nutanix/data_source_nutanix_subnets_test.go b/nutanix/data_source_nutanix_subnets_test.go index 9e53d2ef3..1214b0d2a 100644 --- a/nutanix/data_source_nutanix_subnets_test.go +++ b/nutanix/data_source_nutanix_subnets_test.go @@ -21,6 +21,23 @@ func TestAccNutanixSubnetsDataSource_basic(t *testing.T) { }, }) } + +func TestAccNutanixSubnetsDataSource_WithFilters(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccSubnetsDataSourceConfigWithFilters(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "data.nutanix_subnets.test", "entities.0.name", "vlan0_test_2"), + ), + }, + }, + }) +} + func testAccSubnetsDataSourceConfig() string { return fmt.Sprintf(` data "nutanix_clusters" "clusters" {} @@ -59,3 +76,33 @@ data "nutanix_subnets" "test" {} `, randIntBetween(1, 25)) } + +func testAccSubnetsDataSourceConfigWithFilters() string { + return ` + data "nutanix_clusters" "clusters" {} + locals{ + cluster1 = [ + for cluster in data.nutanix_clusters.clusters.entities: + cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL" + ][0] + } + + resource "nutanix_subnet" "test-subnets" { + count = 5 + name = "vlan0_test_${count.index}" + cluster_uuid = local.cluster1 + + vlan_id = count.index + 1 + subnet_type = "VLAN" + + } + + data "nutanix_subnets" "test" { + metadata { + filter = "name==vlan0_test_2" + } + depends_on = [ + nutanix_subnet.test-subnets + ] + }` +} diff --git a/nutanix/data_source_recovery_plan_test.go b/nutanix/data_source_recovery_plan_test.go index 3a7a9f965..f1af3703e 100644 --- a/nutanix/data_source_recovery_plan_test.go +++ b/nutanix/data_source_recovery_plan_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) -func TestAccNutanixRecoveryPlanDataSource_basic(t *testing.T) { +func TestAccRecoveryPlanDataSourceConfig_WithID(t *testing.T) { resourceName := "nutanix_recovery_plan.test" name := acctest.RandomWithPrefix("test-recovery-name-dou") @@ -25,14 +25,14 @@ func TestAccNutanixRecoveryPlanDataSource_basic(t *testing.T) { CheckDestroy: testAccCheckNutanixRecoveryPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccRecoveryPlanDataSourceConfig(name, description, stageUUID), + Config: testAccRecoveryPlanDataSourceConfigWithID(name, description, stageUUID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", name), resource.TestCheckResourceAttr(resourceName, "description", description), ), }, { - Config: testAccRecoveryPlanDataSourceConfig(nameUpdated, descriptionUpdated, stageUUID), + Config: testAccRecoveryPlanDataSourceConfigWithID(nameUpdated, descriptionUpdated, stageUUID), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(resourceName, "name", nameUpdated), resource.TestCheckResourceAttr(resourceName, "description", descriptionUpdated), @@ -42,7 +42,38 @@ func TestAccNutanixRecoveryPlanDataSource_basic(t *testing.T) { }) } -func testAccRecoveryPlanDataSourceConfig(name, description, stageUUID string) string { +func TestAccRecoveryPlanDataSourceConfig_WithName(t *testing.T) { + name := acctest.RandomWithPrefix("test-recovery-name") + nameUpdated := acctest.RandomWithPrefix("test-recovery-name") + description := acctest.RandomWithPrefix("test-recovery-desc") + descriptionUpdated := acctest.RandomWithPrefix("test-recovery-desc") + stageUUID := "bb261302-94db-11ec-b909-0242ac120002" + + resourceName := "nutanix_recovery_plan.test" + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckNutanixRecoveryPlanDestroy, + Steps: []resource.TestStep{ + { + Config: testAccRecoveryPlanDataSourceConfigWithName(name, description, stageUUID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", name), + resource.TestCheckResourceAttr(resourceName, "description", description), + ), + }, + { + Config: testAccRecoveryPlanDataSourceConfigWithName(nameUpdated, descriptionUpdated, stageUUID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "name", nameUpdated), + resource.TestCheckResourceAttr(resourceName, "description", descriptionUpdated), + ), + }, + }, + }) +} + +func testAccRecoveryPlanDataSourceConfigWithID(name, description, stageUUID string) string { return fmt.Sprintf(` resource "nutanix_recovery_plan" "test" { name = "%s" @@ -69,3 +100,31 @@ func testAccRecoveryPlanDataSourceConfig(name, description, stageUUID string) st `, name, description, stageUUID) } + +func testAccRecoveryPlanDataSourceConfigWithName(name, description, stageUUID string) string { + return fmt.Sprintf(` + resource "nutanix_recovery_plan" "test" { + name = "%s" + description = "%s" + stage_list { + stage_work{ + recover_entities{ + entity_info_list{ + categories { + name = "Environment" + value = "Dev" + } + } + } + } + stage_uuid = "%s" + delay_time_secs = 0 + } + parameters{} + } + data "nutanix_recovery_plan" "test" { + recovery_plan_name = nutanix_recovery_plan.test.name + } + +`, name, description, stageUUID) +}