@@ -6,6 +6,7 @@ package golden_gate
66import (
77 "context"
88 "fmt"
9+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910 "strings"
1011 "time"
1112
@@ -24,10 +25,10 @@ func GoldenGateConnectionAssignmentResource() *schema.Resource {
2425 Importer : & schema.ResourceImporter {
2526 State : schema .ImportStatePassthrough ,
2627 },
27- Timeouts : tfresource .DefaultTimeout ,
28- Create : createGoldenGateConnectionAssignment ,
29- Read : readGoldenGateConnectionAssignment ,
30- Delete : deleteGoldenGateConnectionAssignment ,
28+ Timeouts : tfresource .DefaultTimeout ,
29+ CreateContext : createGoldenGateConnectionAssignmentWithContext ,
30+ ReadContext : readGoldenGateConnectionAssignmentWithContext ,
31+ DeleteContext : deleteGoldenGateConnectionAssignmentWithContext ,
3132 Schema : map [string ]* schema.Schema {
3233 // Required
3334 "connection_id" : {
@@ -74,29 +75,29 @@ func GoldenGateConnectionAssignmentResource() *schema.Resource {
7475 }
7576}
7677
77- func createGoldenGateConnectionAssignment ( d * schema.ResourceData , m interface {}) error {
78+ func createGoldenGateConnectionAssignmentWithContext ( ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
7879 sync := & GoldenGateConnectionAssignmentResourceCrud {}
7980 sync .D = d
8081 sync .Client = m .(* client.OracleClients ).GoldenGateClient ()
8182
82- return tfresource .CreateResource ( d , sync )
83+ return tfresource .HandleDiagError ( m , tfresource . CreateResourceWithContext ( ctx , d , sync ) )
8384}
8485
85- func readGoldenGateConnectionAssignment ( d * schema.ResourceData , m interface {}) error {
86+ func readGoldenGateConnectionAssignmentWithContext ( ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
8687 sync := & GoldenGateConnectionAssignmentResourceCrud {}
8788 sync .D = d
8889 sync .Client = m .(* client.OracleClients ).GoldenGateClient ()
8990
90- return tfresource .ReadResource ( sync )
91+ return tfresource .HandleDiagError ( m , tfresource . ReadResourceWithContext ( ctx , sync ) )
9192}
9293
93- func deleteGoldenGateConnectionAssignment ( d * schema.ResourceData , m interface {}) error {
94+ func deleteGoldenGateConnectionAssignmentWithContext ( ctx context. Context , d * schema.ResourceData , m interface {}) diag. Diagnostics {
9495 sync := & GoldenGateConnectionAssignmentResourceCrud {}
9596 sync .D = d
9697 sync .Client = m .(* client.OracleClients ).GoldenGateClient ()
9798 sync .DisableNotFoundRetries = true
9899
99- return tfresource .DeleteResource ( d , sync )
100+ return tfresource .HandleDiagError ( m , tfresource . DeleteResourceWithContext ( ctx , d , sync ) )
100101}
101102
102103type GoldenGateConnectionAssignmentResourceCrud struct {
@@ -120,7 +121,7 @@ func (s *GoldenGateConnectionAssignmentResourceCrud) DeletedTarget() []string {
120121 return []string {}
121122}
122123
123- func (s * GoldenGateConnectionAssignmentResourceCrud ) Create ( ) error {
124+ func (s * GoldenGateConnectionAssignmentResourceCrud ) CreateWithContext ( ctx context. Context ) error {
124125 request := oci_golden_gate.CreateConnectionAssignmentRequest {}
125126
126127 if connectionId , ok := s .D .GetOkExists ("connection_id" ); ok {
@@ -139,7 +140,7 @@ func (s *GoldenGateConnectionAssignmentResourceCrud) Create() error {
139140 }
140141
141142 request .RequestMetadata .RetryPolicy = tfresource .GetRetryPolicy (s .DisableNotFoundRetries , "golden_gate" )
142- response , err := s .Client .CreateConnectionAssignment (context . Background () , request )
143+ response , err := s .Client .CreateConnectionAssignment (ctx , request )
143144
144145 if err != nil {
145146 return err
@@ -153,15 +154,15 @@ func (s *GoldenGateConnectionAssignmentResourceCrud) Create() error {
153154 }
154155 // Wait until it finishes
155156
156- _ , err = connectionAssignmentWaitForWorkRequest (workId , "goldengateconnectionassignment" ,
157+ _ , err = connectionAssignmentWaitForWorkRequest (ctx , workId , "goldengateconnectionassignment" ,
157158 oci_golden_gate .ActionTypeCreated , s .D .Timeout (schema .TimeoutCreate ), s .DisableNotFoundRetries , s .Client )
158159
159160 if err != nil {
160161 return err
161162 }
162163 s .D .SetId (* response .ConnectionAssignment .Id )
163164
164- return s .Get ( )
165+ return s .GetWithContext ( ctx )
165166}
166167
167168func connectionAssignmentWorkRequestShouldRetryFunc (timeout time.Duration ) func (response oci_common.OCIOperationResponse ) bool {
@@ -187,7 +188,7 @@ func connectionAssignmentWorkRequestShouldRetryFunc(timeout time.Duration) func(
187188 }
188189}
189190
190- func connectionAssignmentWaitForWorkRequest (wId * string , entityType string , action oci_golden_gate.ActionTypeEnum ,
191+ func connectionAssignmentWaitForWorkRequest (ctx context. Context , wId * string , entityType string , action oci_golden_gate.ActionTypeEnum ,
191192 timeout time.Duration , disableFoundRetries bool , client * oci_golden_gate.GoldenGateClient ) (* string , error ) {
192193 retryPolicy := tfresource .GetRetryPolicy (disableFoundRetries , "golden_gate" )
193194 retryPolicy .ShouldRetryOperation = connectionAssignmentWorkRequestShouldRetryFunc (timeout )
@@ -206,7 +207,7 @@ func connectionAssignmentWaitForWorkRequest(wId *string, entityType string, acti
206207 },
207208 Refresh : func () (interface {}, string , error ) {
208209 var err error
209- response , err = client .GetWorkRequest (context . Background () ,
210+ response , err = client .GetWorkRequest (ctx ,
210211 oci_golden_gate.GetWorkRequestRequest {
211212 WorkRequestId : wId ,
212213 RequestMetadata : oci_common.RequestMetadata {
@@ -253,15 +254,15 @@ func getErrorFromGoldenGateConnectionAssignmentWorkRequest(client *oci_golden_ga
253254 return workRequestErr
254255}
255256
256- func (s * GoldenGateConnectionAssignmentResourceCrud ) Get ( ) error {
257+ func (s * GoldenGateConnectionAssignmentResourceCrud ) GetWithContext ( ctx context. Context ) error {
257258 request := oci_golden_gate.GetConnectionAssignmentRequest {}
258259
259260 tmp := s .D .Id ()
260261 request .ConnectionAssignmentId = & tmp
261262
262263 request .RequestMetadata .RetryPolicy = tfresource .GetRetryPolicy (s .DisableNotFoundRetries , "golden_gate" )
263264
264- response , err := s .Client .GetConnectionAssignment (context . Background () , request )
265+ response , err := s .Client .GetConnectionAssignment (ctx , request )
265266 if err != nil {
266267 return err
267268 }
@@ -270,7 +271,7 @@ func (s *GoldenGateConnectionAssignmentResourceCrud) Get() error {
270271 return nil
271272}
272273
273- func (s * GoldenGateConnectionAssignmentResourceCrud ) Delete ( ) error {
274+ func (s * GoldenGateConnectionAssignmentResourceCrud ) DeleteWithContext ( ctx context. Context ) error {
274275 request := oci_golden_gate.DeleteConnectionAssignmentRequest {}
275276
276277 tmp := s .D .Id ()
@@ -283,14 +284,14 @@ func (s *GoldenGateConnectionAssignmentResourceCrud) Delete() error {
283284
284285 request .RequestMetadata .RetryPolicy = tfresource .GetRetryPolicy (s .DisableNotFoundRetries , "golden_gate" )
285286
286- response , err := s .Client .DeleteConnectionAssignment (context . Background () , request )
287+ response , err := s .Client .DeleteConnectionAssignment (ctx , request )
287288 if err != nil {
288289 return err
289290 }
290291
291292 workId := response .OpcWorkRequestId
292293 // Wait until it finishes
293- _ , delWorkRequestErr := connectionAssignmentWaitForWorkRequest (workId , "goldengateconnectionassignment" ,
294+ _ , delWorkRequestErr := connectionAssignmentWaitForWorkRequest (ctx , workId , "goldengateconnectionassignment" ,
294295 oci_golden_gate .ActionTypeDeleted , s .D .Timeout (schema .TimeoutDelete ), s .DisableNotFoundRetries , s .Client )
295296 return delWorkRequestErr
296297}
0 commit comments