Skip to content

Commit 50fcb7a

Browse files
sriniociravinitp
authored andcommitted
Added - Support for sigint context to go sdk for GoldenGate
1 parent 16c4ed8 commit 50fcb7a

File tree

36 files changed

+448
-413
lines changed

36 files changed

+448
-413
lines changed

internal/service/golden_gate/golden_gate_connection_assignment_data_source.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package golden_gate
66
import (
77
"context"
88

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011
oci_golden_gate "github.com/oracle/oci-go-sdk/v65/goldengate"
1112

@@ -19,15 +20,15 @@ func GoldenGateConnectionAssignmentDataSource() *schema.Resource {
1920
Type: schema.TypeString,
2021
Required: true,
2122
}
22-
return tfresource.GetSingularDataSourceItemSchema(GoldenGateConnectionAssignmentResource(), fieldMap, readSingularGoldenGateConnectionAssignment)
23+
return tfresource.GetSingularDataSourceItemSchemaWithContext(GoldenGateConnectionAssignmentResource(), fieldMap, readSingularGoldenGateConnectionAssignmentWithContext)
2324
}
2425

25-
func readSingularGoldenGateConnectionAssignment(d *schema.ResourceData, m interface{}) error {
26+
func readSingularGoldenGateConnectionAssignmentWithContext(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
2627
sync := &GoldenGateConnectionAssignmentDataSourceCrud{}
2728
sync.D = d
2829
sync.Client = m.(*client.OracleClients).GoldenGateClient()
2930

30-
return tfresource.ReadResource(sync)
31+
return tfresource.HandleDiagError(m, tfresource.ReadResourceWithContext(ctx, sync))
3132
}
3233

3334
type GoldenGateConnectionAssignmentDataSourceCrud struct {
@@ -40,7 +41,7 @@ func (s *GoldenGateConnectionAssignmentDataSourceCrud) VoidState() {
4041
s.D.SetId("")
4142
}
4243

43-
func (s *GoldenGateConnectionAssignmentDataSourceCrud) Get() error {
44+
func (s *GoldenGateConnectionAssignmentDataSourceCrud) GetWithContext(ctx context.Context) error {
4445
request := oci_golden_gate.GetConnectionAssignmentRequest{}
4546

4647
if connectionAssignmentId, ok := s.D.GetOkExists("connection_assignment_id"); ok {
@@ -50,7 +51,7 @@ func (s *GoldenGateConnectionAssignmentDataSourceCrud) Get() error {
5051

5152
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "golden_gate")
5253

53-
response, err := s.Client.GetConnectionAssignment(context.Background(), request)
54+
response, err := s.Client.GetConnectionAssignment(ctx, request)
5455
if err != nil {
5556
return err
5657
}

internal/service/golden_gate/golden_gate_connection_assignment_resource.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package golden_gate
66
import (
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

102103
type 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

167168
func 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
}

internal/service/golden_gate/golden_gate_connection_assignments_data_source.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package golden_gate
66
import (
77
"context"
88

9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011
oci_golden_gate "github.com/oracle/oci-go-sdk/v65/goldengate"
1112

@@ -15,7 +16,7 @@ import (
1516

1617
func GoldenGateConnectionAssignmentsDataSource() *schema.Resource {
1718
return &schema.Resource{
18-
Read: readGoldenGateConnectionAssignments,
19+
ReadContext: readGoldenGateConnectionAssignmentsWithContext,
1920
Schema: map[string]*schema.Schema{
2021
"filter": tfresource.DataSourceFiltersSchema(),
2122
"compartment_id": {
@@ -56,12 +57,12 @@ func GoldenGateConnectionAssignmentsDataSource() *schema.Resource {
5657
}
5758
}
5859

59-
func readGoldenGateConnectionAssignments(d *schema.ResourceData, m interface{}) error {
60+
func readGoldenGateConnectionAssignmentsWithContext(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
6061
sync := &GoldenGateConnectionAssignmentsDataSourceCrud{}
6162
sync.D = d
6263
sync.Client = m.(*client.OracleClients).GoldenGateClient()
6364

64-
return tfresource.ReadResource(sync)
65+
return tfresource.HandleDiagError(m, tfresource.ReadResourceWithContext(ctx, sync))
6566
}
6667

6768
type GoldenGateConnectionAssignmentsDataSourceCrud struct {
@@ -74,7 +75,7 @@ func (s *GoldenGateConnectionAssignmentsDataSourceCrud) VoidState() {
7475
s.D.SetId("")
7576
}
7677

77-
func (s *GoldenGateConnectionAssignmentsDataSourceCrud) Get() error {
78+
func (s *GoldenGateConnectionAssignmentsDataSourceCrud) GetWithContext(ctx context.Context) error {
7879
request := oci_golden_gate.ListConnectionAssignmentsRequest{}
7980

8081
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
@@ -103,7 +104,7 @@ func (s *GoldenGateConnectionAssignmentsDataSourceCrud) Get() error {
103104

104105
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "golden_gate")
105106

106-
response, err := s.Client.ListConnectionAssignments(context.Background(), request)
107+
response, err := s.Client.ListConnectionAssignments(ctx, request)
107108
if err != nil {
108109
return err
109110
}
@@ -112,7 +113,7 @@ func (s *GoldenGateConnectionAssignmentsDataSourceCrud) Get() error {
112113
request.Page = s.Res.OpcNextPage
113114

114115
for request.Page != nil {
115-
listResponse, err := s.Client.ListConnectionAssignments(context.Background(), request)
116+
listResponse, err := s.Client.ListConnectionAssignments(ctx, request)
116117
if err != nil {
117118
return err
118119
}

internal/service/golden_gate/golden_gate_connection_data_source.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package golden_gate
55

66
import (
77
"context"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"log"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -20,15 +21,15 @@ func GoldenGateConnectionDataSource() *schema.Resource {
2021
Type: schema.TypeString,
2122
Required: true,
2223
}
23-
return tfresource.GetSingularDataSourceItemSchema(GoldenGateConnectionResource(), fieldMap, readSingularGoldenGateConnection)
24+
return tfresource.GetSingularDataSourceItemSchemaWithContext(GoldenGateConnectionResource(), fieldMap, readSingularGoldenGateConnectionWithContext)
2425
}
2526

26-
func readSingularGoldenGateConnection(d *schema.ResourceData, m interface{}) error {
27+
func readSingularGoldenGateConnectionWithContext(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
2728
sync := &GoldenGateConnectionDataSourceCrud{}
2829
sync.D = d
2930
sync.Client = m.(*client.OracleClients).GoldenGateClient()
3031

31-
return tfresource.ReadResource(sync)
32+
return tfresource.HandleDiagError(m, tfresource.ReadResourceWithContext(ctx, sync))
3233
}
3334

3435
type GoldenGateConnectionDataSourceCrud struct {
@@ -41,7 +42,7 @@ func (s *GoldenGateConnectionDataSourceCrud) VoidState() {
4142
s.D.SetId("")
4243
}
4344

44-
func (s *GoldenGateConnectionDataSourceCrud) Get() error {
45+
func (s *GoldenGateConnectionDataSourceCrud) GetWithContext(ctx context.Context) error {
4546
request := oci_golden_gate.GetConnectionRequest{}
4647

4748
if connectionId, ok := s.D.GetOkExists("connection_id"); ok {
@@ -51,7 +52,7 @@ func (s *GoldenGateConnectionDataSourceCrud) Get() error {
5152

5253
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "golden_gate")
5354

54-
response, err := s.Client.GetConnection(context.Background(), request)
55+
response, err := s.Client.GetConnection(ctx, request)
5556
if err != nil {
5657
return err
5758
}

0 commit comments

Comments
 (0)