@@ -42,15 +42,15 @@ var (
4242 "drg_id" : Representation {RepType : Required , Create : `${oci_core_drg.test_drg.id}` },
4343 "defined_tags" : Representation {RepType : Optional , Create : `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}` , Update : `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}` },
4444 "display_name" : Representation {RepType : Optional , Create : `displayName` , Update : `displayName2` },
45- "drg_route_table_id" : Representation {RepType : Optional , Create : `${oci_core_drg_route_table.test_drg_route_table.id}` },
45+ "drg_route_table_id" : Representation {RepType : Optional , Create : `${oci_core_drg_route_table.test_drg_route_table.id}` , Update : `${oci_core_drg_route_table.test_drg_route_table_2.id}` },
4646 "freeform_tags" : Representation {RepType : Optional , Create : map [string ]string {"Department" : "Finance" }, Update : map [string ]string {"Department" : "Accounting" }},
4747 "network_details" : RepresentationGroup {Required , drgAttachmentNetworkDetailsRepresentation },
4848 "lifecycle" : RepresentationGroup {Required , ignoreChangesLBRepresentation },
4949 }
5050 drgAttachmentNetworkDetailsRepresentation = map [string ]interface {}{
5151 "id" : Representation {RepType : Required , Create : `${oci_core_vcn.test_vcn.id}` },
5252 "type" : Representation {RepType : Required , Create : `VCN` },
53- "route_table_id" : Representation {RepType : Required , Create : `${oci_core_route_table.test_route_table.id}` },
53+ "route_table_id" : Representation {RepType : Required , Create : `${oci_core_route_table.test_route_table.id}` , Update : `${oci_core_route_table.test_route_table_2.id}` },
5454 }
5555
5656 drgAttachmentRepresentationNoRouteTable = map [string ]interface {}{
8484 }
8585
8686 DrgAttachmentResourceDependencies = GenerateResourceFromRepresentationMap ("oci_core_drg_route_table" , "test_drg_route_table" , Required , Create , drgRouteTableRepresentation ) +
87+ GenerateResourceFromRepresentationMap ("oci_core_drg_route_table" , "test_drg_route_table_2" , Required , Create , drgRouteTableRepresentation ) +
8788 GenerateResourceFromRepresentationMap ("oci_core_drg" , "test_drg" , Required , Create , drgRepresentation ) +
8889 GenerateResourceFromRepresentationMap ("oci_core_internet_gateway" , "test_internet_gateway" , Required , Create , internetGatewayRepresentation ) +
8990 GenerateResourceFromRepresentationMap ("oci_core_route_table" , "test_route_table" , Required , Create , routeTableRepresentation ) +
91+ GenerateResourceFromRepresentationMap ("oci_core_route_table" , "test_route_table_2" , Required , Create , routeTableRepresentation ) +
9092 GenerateResourceFromRepresentationMap ("oci_core_vcn" , "test_vcn" , Required , Create , vcnRepresentation ) +
9193 DefinedTagsDependencies
9294)
@@ -419,3 +421,84 @@ func drgAttachmentSweepResponseFetchOperation(client *OracleClients, resourceId
419421 })
420422 return err
421423}
424+
425+ // Adding a test case for testing the Update request. Updating both drg_route_table_id from and route_table_id simultaneously.
426+ func TestCoreDrgAttachmentUpdateRequest_basic (t * testing.T ) {
427+ httpreplay .SetScenario ("TestCoreDrgAttachmentResource_basic" )
428+ defer httpreplay .SaveScenario ()
429+ config := testProviderConfig ()
430+
431+ compartmentId := getEnvSettingWithBlankDefault ("compartment_ocid" )
432+ compartmentIdVariableStr := fmt .Sprintf ("variable \" compartment_id\" { default = \" %s\" }\n " , compartmentId )
433+
434+ resourceName := "oci_core_drg_attachment.test_drg_attachment"
435+
436+ var resId , resId2 string
437+ // Save TF content to create resource with optional properties. This has to be exactly the same as the config part in the "create with optionals" step in the test.
438+ SaveConfigContent (config + compartmentIdVariableStr + DrgAttachmentResourceDependencies +
439+ GenerateResourceFromRepresentationMap ("oci_core_drg_attachment" , "test_drg_attachment" , Optional , Create , drgAttachmentRepresentation ), "core" , "drgAttachment" , t )
440+
441+ ResourceTest (t , testAccCheckCoreDrgAttachmentDestroy , []resource.TestStep {
442+ //verify create with optionals
443+ {
444+ Config : config + compartmentIdVariableStr + DrgAttachmentResourceDependencies +
445+ GenerateResourceFromRepresentationMap ("oci_core_drg_attachment" , "test_drg_attachment" , Optional , Create , drgAttachmentRepresentation ),
446+ Check : ComposeAggregateTestCheckFuncWrapper (
447+ resource .TestCheckResourceAttrSet (resourceName , "compartment_id" ),
448+ resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "3" ),
449+ resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName" ),
450+ resource .TestCheckResourceAttrSet (resourceName , "drg_id" ),
451+ resource .TestCheckResourceAttrSet (resourceName , "drg_route_table_id" ),
452+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
453+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
454+ resource .TestCheckResourceAttr (resourceName , "network_details.#" , "1" ),
455+ resource .TestCheckResourceAttrSet (resourceName , "network_details.0.id" ),
456+ resource .TestCheckResourceAttrSet (resourceName , "network_details.0.route_table_id" ),
457+ resource .TestCheckResourceAttr (resourceName , "network_details.0.type" , "VCN" ),
458+ resource .TestCheckResourceAttrSet (resourceName , "route_table_id" ),
459+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
460+ resource .TestCheckResourceAttrSet (resourceName , "vcn_id" ),
461+ func (s * terraform.State ) (err error ) {
462+ resId , err = FromInstanceState (s , resourceName , "id" )
463+ return err
464+ },
465+ ),
466+ },
467+
468+ //verify, updates to updatable parameters
469+ {
470+ Config : config + compartmentIdVariableStr + DrgAttachmentResourceDependencies +
471+ GenerateResourceFromRepresentationMap ("oci_core_drg_attachment" , "test_drg_attachment" , Optional , Update , drgAttachmentRepresentation ),
472+ Check : ComposeAggregateTestCheckFuncWrapper (
473+ resource .TestCheckResourceAttrSet (resourceName , "compartment_id" ),
474+ resource .TestCheckResourceAttr (resourceName , "defined_tags.%" , "3" ),
475+ resource .TestCheckResourceAttr (resourceName , "display_name" , "displayName2" ),
476+ resource .TestCheckResourceAttrSet (resourceName , "drg_id" ),
477+ resource .TestCheckResourceAttrSet (resourceName , "drg_route_table_id" ),
478+ resource .TestCheckResourceAttr (resourceName , "freeform_tags.%" , "1" ),
479+ resource .TestCheckResourceAttrSet (resourceName , "id" ),
480+ resource .TestCheckResourceAttr (resourceName , "network_details.#" , "1" ),
481+ resource .TestCheckResourceAttrSet (resourceName , "network_details.0.id" ),
482+ resource .TestCheckResourceAttrSet (resourceName , "network_details.0.route_table_id" ),
483+ resource .TestCheckResourceAttr (resourceName , "network_details.0.type" , "VCN" ),
484+ resource .TestCheckResourceAttrSet (resourceName , "route_table_id" ),
485+ resource .TestCheckResourceAttrSet (resourceName , "state" ),
486+ resource .TestCheckResourceAttrSet (resourceName , "vcn_id" ),
487+
488+ func (s * terraform.State ) (err error ) {
489+ resId2 , err = FromInstanceState (s , resourceName , "id" )
490+ if resId != resId2 {
491+ return fmt .Errorf ("Resource recreated when it was supposed to be updated." )
492+ }
493+ return err
494+ },
495+ ),
496+ },
497+
498+ //delete, before next create
499+ {
500+ Config : config + compartmentIdVariableStr + DrgAttachmentResourceDependencies +
501+ GenerateResourceFromRepresentationMap ("oci_core_drg_attachment" , "test_drg_attachment" , Optional , Update , drgAttachmentRepresentation ),
502+ },
503+ })
504+ }
0 commit comments