@@ -49,7 +49,6 @@ func (s *DatasourceCoreSubnetTestSuite) SetupTest() {
4949}
5050
5151func (s * DatasourceCoreSubnetTestSuite ) TestAccDatasourceCoreSubnet_basic () {
52-
5352 resource .Test (s .T (), resource.TestCase {
5453 PreventPostDestroyRefresh : true ,
5554 Providers : s .Providers ,
@@ -62,34 +61,56 @@ func (s *DatasourceCoreSubnetTestSuite) TestAccDatasourceCoreSubnet_basic() {
6261 data "oci_core_subnets" "s" {
6362 compartment_id = "${var.compartment_id}"
6463 vcn_id = "${oci_core_virtual_network.vcn1.id}"
65- depends_on = ["oci_core_subnet.s"]
6664 filter {
6765 name = "availability_domain"
68- values = ["${lookup(data.oci_identity_availability_domains.ADs.availability_domains [1], "name") }"]
66+ values = ["${oci_core_subnet.s.*.availability_domain [1]}"]
6967 }
7068 }` ,
7169 Check : resource .ComposeTestCheckFunc (
7270 resource .TestCheckResourceAttrSet (s .ResourceName , "vcn_id" ),
7371 resource .TestCheckResourceAttr (s .ResourceName , "subnets.#" , "1" ),
74- resource . TestCheckResourceAttrSet (s .ResourceName , "subnets.0.availability_domain" ),
72+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.availability_domain" , "oci_core_subnet.s.1" , " availability_domain" ),
7573 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.cidr_block" , "10.1.21.0/24" ),
7674 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.display_name" , "subnet1" ),
7775 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.dns_label" , "subnet1" ),
78- resource . TestCheckResourceAttrSet (s .ResourceName , "subnets.0.id" ),
76+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.id" , "oci_core_subnet.s.1" , " id" ),
7977 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.prohibit_public_ip_on_vnic" , "false" ),
80- resource . TestCheckResourceAttrSet (s .ResourceName , "subnets.0.route_table_id" ),
78+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.route_table_id" , "oci_core_subnet.s.1" , " route_table_id" ),
8179 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.security_list_ids.#" , "1" ),
8280 resource .TestCheckResourceAttr (s .ResourceName , "subnets.0.state" , string (core .SubnetLifecycleStateAvailable )),
83- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.time_created" ),
84- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.vcn_id" ),
85- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.dhcp_options_id" ),
86- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.virtual_router_ip" ),
87- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.virtual_router_mac" ),
88- resource .TestCheckResourceAttrSet (s .ResourceName , "subnets.0.subnet_domain_name" ),
81+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.time_created" , "oci_core_subnet.s.1" , "time_created" ),
82+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.vcn_id" , "oci_core_subnet.s.1" , "vcn_id" ),
83+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.dhcp_options_id" , "oci_core_subnet.s.1" , "dhcp_options_id" ),
84+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.virtual_router_ip" , "oci_core_subnet.s.1" , "virtual_router_ip" ),
85+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.virtual_router_mac" , "oci_core_subnet.s.1" , "virtual_router_mac" ),
86+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.subnet_domain_name" , "oci_core_subnet.s.1" , "subnet_domain_name" ),
87+ ),
88+ },
89+ // Server-side filtering tests.
90+ {
91+ Config : s .Config + `
92+ data "oci_core_subnets" "s" {
93+ compartment_id = "${var.compartment_id}"
94+ vcn_id = "${oci_core_virtual_network.vcn1.id}"
95+ display_name = "${oci_core_subnet.s.2.display_name}"
96+ }` ,
97+ Check : resource .ComposeTestCheckFunc (
98+ resource .TestCheckResourceAttrSet (s .ResourceName , "vcn_id" ),
99+ resource .TestCheckResourceAttr (s .ResourceName , "subnets.#" , "1" ),
100+ TestCheckResourceAttributesEqual (s .ResourceName , "subnets.0.id" , "oci_core_subnet.s.2" , "id" ),
101+ ),
102+ },
103+ {
104+ Config : s .Config + `
105+ data "oci_core_subnets" "s" {
106+ compartment_id = "${var.compartment_id}"
107+ vcn_id = "${oci_core_virtual_network.vcn1.id}"
108+ state = "${oci_core_subnet.s.0.state}" # Adding implicit dependency
109+ }` ,
110+ Check : resource .ComposeTestCheckFunc (
111+ resource .TestCheckResourceAttrSet (s .ResourceName , "vcn_id" ),
112+ resource .TestCheckResourceAttr (s .ResourceName , "subnets.#" , "3" ),
89113 ),
90- // Work around for terraform bug where depends_on results in "plan was not empty"
91- // https://github.com/hashicorp/terraform/issues/11139
92- ExpectNonEmptyPlan : true ,
93114 },
94115 },
95116 },
0 commit comments