@@ -926,6 +926,106 @@ func (s *ResourceCoreInstanceTestSuite) TestAccResourceCoreInstance_failedByTime
926926 })
927927}
928928
929+ func (s * ResourceCoreInstanceTestSuite ) TestAccResourceCoreInstance_fetchVnicWhenStopped () {
930+
931+ resourceName := "oci_core_instance.t"
932+ config := s .Config + `
933+ resource "oci_core_instance" "t" {
934+ availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
935+ compartment_id = "${var.compartment_id}"
936+ subnet_id = "${oci_core_subnet.t.id}"
937+ hostname_label = "hostname1"
938+ image = "${var.InstanceImageOCID[var.region]}"
939+ shape = "VM.Standard2.1"
940+ defined_tags = "${map(
941+ "${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value"
942+ )}"
943+ freeform_tags = { "Department" = "Accounting"}
944+ metadata = {
945+ ssh_authorized_keys = "${var.ssh_public_key}"
946+ user_data = "ZWNobyBoZWxsbw=="
947+ }
948+ extended_metadata = {
949+ keyA = "valA"
950+ keyB = "{\"keyB1\": \"valB1\", \"keyB2\": {\"keyB2\": \"valB2\"}}"
951+ }
952+ timeouts {
953+ create = "15m"
954+ }
955+ state = "STOPPED"
956+ }`
957+
958+ resource .Test (s .T (), resource.TestCase {
959+ Providers : s .Providers ,
960+ Steps : []resource.TestStep {
961+ // verify fetching vnic details for an instance that is in stopped state
962+ {
963+ Config : config ,
964+ Check : resource .ComposeAggregateTestCheckFunc (
965+ resource .TestCheckResourceAttrSet (s .ResourceName , "id" ),
966+ resource .TestCheckResourceAttrSet (s .ResourceName , "availability_domain" ),
967+ resource .TestCheckResourceAttrSet (s .ResourceName , "time_created" ),
968+ resource .TestCheckResourceAttrSet (s .ResourceName , "public_ip" ),
969+ resource .TestCheckResourceAttrSet (s .ResourceName , "private_ip" ),
970+ resource .TestCheckResourceAttrSet (s .ResourceName , "display_name" ),
971+ resource .TestCheckResourceAttrSet (s .ResourceName , "image" ),
972+ resource .TestCheckResourceAttr (s .ResourceName , "launch_mode" , "NATIVE" ),
973+ resource .TestCheckResourceAttr (s .ResourceName , "launch_options.#" , "1" ),
974+ resource .TestCheckResourceAttr (s .ResourceName , "launch_options.0.boot_volume_type" , "ISCSI" ),
975+ resource .TestCheckResourceAttr (s .ResourceName , "launch_options.0.firmware" , "UEFI_64" ),
976+ resource .TestCheckResourceAttr (s .ResourceName , "launch_options.0.network_type" , "VFIO" ),
977+ resource .TestCheckResourceAttr (s .ResourceName , "launch_options.0.remote_data_volume_type" , "PARAVIRTUALIZED" ),
978+ // only set if specified
979+ resource .TestCheckNoResourceAttr (s .ResourceName , "ipxe_script" ),
980+ resource .TestCheckResourceAttrSet (s .ResourceName , "subnet_id" ),
981+ resource .TestCheckResourceAttr (s .ResourceName , "hostname_label" , "hostname1" ),
982+ resource .TestCheckResourceAttr (s .ResourceName , "shape" , "VM.Standard2.1" ),
983+ resource .TestCheckResourceAttr (s .ResourceName , "metadata.%" , "2" ),
984+ resource .TestCheckResourceAttr (s .ResourceName , "metadata.user_data" , "ZWNobyBoZWxsbw==" ),
985+ resource .TestCheckResourceAttrSet (s .ResourceName , "metadata.ssh_authorized_keys" ),
986+ resource .TestCheckResourceAttr (s .ResourceName , "extended_metadata.%" , "2" ),
987+ resource .TestCheckResourceAttr (s .ResourceName , "extended_metadata.keyA" , "valA" ),
988+ resource .TestCheckResourceAttr (s .ResourceName , "extended_metadata.keyB" , "{\" keyB1\" : \" valB1\" , \" keyB2\" : {\" keyB2\" : \" valB2\" }}" ),
989+ resource .TestCheckResourceAttr (s .ResourceName , "defined_tags.%" , "1" ),
990+ resource .TestCheckResourceAttr (s .ResourceName , "freeform_tags.%" , "1" ),
991+ resource .TestCheckResourceAttrSet (s .ResourceName , "region" ),
992+ resource .TestCheckResourceAttr (s .ResourceName , "create_vnic_details.#" , "1" ),
993+ resource .TestCheckResourceAttrSet (s .ResourceName , "create_vnic_details.0.display_name" ),
994+ resource .TestCheckResourceAttrSet (s .ResourceName , "create_vnic_details.0.hostname_label" ),
995+ resource .TestCheckResourceAttrSet (s .ResourceName , "create_vnic_details.0.private_ip" ),
996+ resource .TestCheckResourceAttr (s .ResourceName , "create_vnic_details.0.skip_source_dest_check" , "false" ),
997+ resource .TestCheckResourceAttr (s .ResourceName , "create_vnic_details.0.assign_public_ip" , "true" ),
998+ resource .TestCheckResourceAttr (s .ResourceName , "state" , string (core .InstanceLifecycleStateStopped )),
999+ resource .TestCheckResourceAttr (s .ResourceName , "source_details.#" , "1" ),
1000+ resource .TestCheckResourceAttr (s .ResourceName , "source_details.0.source_type" , "image" ),
1001+ resource .TestCheckResourceAttrSet (s .ResourceName , "source_details.0.source_id" ),
1002+ resource .TestCheckNoResourceAttr (s .ResourceName , "preserve_boot_volume" ),
1003+ func (ts * terraform.State ) (err error ) {
1004+ _ , err = fromInstanceState (ts , s .ResourceName , "id" )
1005+ return err
1006+ },
1007+ ),
1008+ },
1009+ // verify resource import when instance state is STOPPED
1010+ {
1011+ Config : config ,
1012+ ImportState : true ,
1013+ ImportStateVerify : true ,
1014+ ImportStateVerifyIgnore : []string {
1015+ // TODO: extended_metadata intentionally not set in resource Gets, even though supported
1016+ // by GetInstance calls. Remove this when the issue is resolved.
1017+ "extended_metadata" ,
1018+ "hostname_label" ,
1019+ "is_pv_encryption_in_transit_enabled" ,
1020+ "subnet_id" ,
1021+ "source_details.0.kms_key_id" , //TODO: Service is not returning this value, remove when the service returns it. COM-26394
1022+ },
1023+ ResourceName : resourceName ,
1024+ },
1025+ },
1026+ })
1027+ }
1028+
9291029func TestResourceCoreInstanceTestSuite (t * testing.T ) {
9301030 if httpreplay .ModeRecordReplay () {
9311031 t .Skip ("Skip TestResourceCoreInstanceTestSuite in HttpReplay mode." )
0 commit comments