Skip to content

Commit b175770

Browse files
author
Uddipaan Hazarika
committed
added read params
1 parent d37edb9 commit b175770

File tree

3 files changed

+159
-28
lines changed

3 files changed

+159
-28
lines changed

internal/provider/commons.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,24 @@ var isDestructiveVdbUpdate = map[string]bool{
9090
"mount_point": true,
9191
"tags": false,
9292
}
93+
94+
var updatableOracleDsourceKeys = map[string]bool{
95+
"name": true,
96+
"environment_user_id": true,
97+
"backup_level_enabled": true,
98+
"rman_channels": true,
99+
"files_per_set": true,
100+
"check_logical": true,
101+
"encrypted_linking_enabled": true,
102+
"compressed_linking_enabled": true,
103+
"bandwidth_limit": true,
104+
"number_of_connections": true,
105+
"validate_by_opening_in_read_only_mode": true,
106+
"pre_provisionoing_enabled": true,
107+
"diagnose_no_logging_faults": true,
108+
"external_file_path": true,
109+
"hooks": true,
110+
"logsync_mode": true,
111+
"logsync_interval": true,
112+
"tags": true,
113+
}

internal/provider/resource_oracle_dsource.go

Lines changed: 130 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"net/http"
56

67
"github.com/hashicorp/terraform-plugin-log/tflog"
78

@@ -16,9 +17,9 @@ func resourceOracleDsource() *schema.Resource {
1617
Description: "Resource for Oracle dSource creation.",
1718

1819
CreateContext: resourceOracleDsourceCreate,
19-
ReadContext: resourceDsourceRead,
20-
UpdateContext: resourceDsourceUpdate,
21-
DeleteContext: resourceDsourceDelete,
20+
ReadContext: resourceOracleDsourceRead,
21+
UpdateContext: resourceOracleDsourceUpdate,
22+
DeleteContext: resourceOracleDsourceDelete,
2223

2324
Schema: map[string]*schema.Schema{
2425
"name": {
@@ -40,6 +41,7 @@ func resourceOracleDsource() *schema.Resource {
4041
"log_sync_enabled": {
4142
Type: schema.TypeBool,
4243
Optional: true,
44+
Computed: true,
4345
},
4446
"make_current_account_owner": {
4547
Type: schema.TypeBool,
@@ -456,22 +458,10 @@ func resourceOracleDsource() *schema.Resource {
456458
Type: schema.TypeString,
457459
Computed: true,
458460
},
459-
"source_id": {
460-
Type: schema.TypeString,
461-
Computed: true,
462-
},
463461
"database_type": {
464462
Type: schema.TypeString,
465463
Computed: true,
466464
},
467-
"namespace_id": {
468-
Type: schema.TypeString,
469-
Computed: true,
470-
},
471-
"namespace_name": {
472-
Type: schema.TypeString,
473-
Computed: true,
474-
},
475465
"is_replica": {
476466
Type: schema.TypeBool,
477467
Computed: true,
@@ -488,10 +478,6 @@ func resourceOracleDsource() *schema.Resource {
488478
Type: schema.TypeString,
489479
Computed: true,
490480
},
491-
"plugin_version": {
492-
Type: schema.TypeString,
493-
Computed: true,
494-
},
495481
"creation_date": {
496482
Type: schema.TypeString,
497483
Computed: true,
@@ -504,10 +490,18 @@ func resourceOracleDsource() *schema.Resource {
504490
Type: schema.TypeBool,
505491
Computed: true,
506492
},
493+
"is_detached": {
494+
Type: schema.TypeBool,
495+
Computed: true,
496+
},
507497
"engine_id": {
508498
Type: schema.TypeString,
509499
Computed: true,
510500
},
501+
"source_id": {
502+
Type: schema.TypeString,
503+
Computed: true,
504+
},
511505
"status": {
512506
Type: schema.TypeString,
513507
Computed: true,
@@ -520,12 +514,20 @@ func resourceOracleDsource() *schema.Resource {
520514
Type: schema.TypeString,
521515
Computed: true,
522516
},
523-
"previous_timeflow_id": {
517+
"is_appdata": {
518+
Type: schema.TypeBool,
519+
Computed: true,
520+
},
521+
"sync_policy_id": {
524522
Type: schema.TypeString,
525523
Computed: true,
526524
},
527-
"is_appdata": {
528-
Type: schema.TypeBool,
525+
"retention_policy_id": {
526+
Type: schema.TypeString,
527+
Computed: true,
528+
},
529+
"exported_data_directory": {
530+
Type: schema.TypeString,
529531
Computed: true,
530532
},
531533
"wait_time": {
@@ -710,7 +712,6 @@ func resourceOracleDsourceCreate(ctx context.Context, d *schema.ResourceData, me
710712
if v, has_v := d.GetOk("ops_pre_log_sync"); has_v {
711713
oracleDSourceLinkSourceParameters.SetOpsPreLogSync(toSourceOperationArray(v))
712714
}
713-
714715
req := client.DSourcesAPI.LinkOracleDatabase(ctx)
715716

716717
apiRes, httpRes, err := req.OracleDSourceLinkSourceParameters(*oracleDSourceLinkSourceParameters).Execute()
@@ -744,10 +745,111 @@ func resourceOracleDsourceCreate(ctx context.Context, d *schema.ResourceData, me
744745
return diags
745746
}
746747

747-
func toIntArray(array interface{}) []int32 {
748-
items := []int32{}
749-
for _, item := range array.([]interface{}) {
750-
items = append(items, int32(item.(int)))
748+
func resourceOracleDsourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
749+
750+
client := meta.(*apiClient).client
751+
752+
dsource_id := d.Id()
753+
754+
res, diags := PollForObjectExistence(ctx, func() (interface{}, *http.Response, error) {
755+
return client.DSourcesAPI.GetDsourceById(ctx, dsource_id).Execute()
756+
})
757+
758+
if res == nil {
759+
tflog.Error(ctx, DLPX+ERROR+"Dsource not found: "+dsource_id+", removing from state. ")
760+
d.SetId("")
761+
return nil
762+
}
763+
764+
if diags != nil {
765+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
766+
return client.DSourcesAPI.GetDsourceById(ctx, dsource_id).Execute()
767+
})
768+
// This would imply error in poll for deletion so we just log and exit.
769+
if diags != nil {
770+
tflog.Error(ctx, DLPX+ERROR+"Error in polling of dSource for deletion.")
771+
} else {
772+
// diags will be nil in case of successful poll for deletion logic aka 404
773+
tflog.Error(ctx, DLPX+ERROR+"Error reading the dSource "+dsource_id+", removing from state.")
774+
d.SetId("")
775+
}
776+
777+
return nil
778+
}
779+
780+
result, ok := res.(*dctapi.DSource)
781+
if !ok {
782+
return diag.Errorf("Error occured in type casting.")
783+
}
784+
785+
d.Set("id", result.GetId())
786+
d.Set("database_type", result.GetDatabaseType())
787+
d.Set("name", result.GetName())
788+
d.Set("is_replica", result.GetIsReplica())
789+
d.Set("database_version", result.GetDatabaseVersion())
790+
d.Set("content_type", result.GetContentType())
791+
d.Set("data_uuid", result.GetDataUuid())
792+
d.Set("creation_date", result.GetCreationDate().String())
793+
d.Set("group_name", result.GetGroupName())
794+
d.Set("enabled", result.GetEnabled())
795+
d.Set("is_detached", result.GetIsDetached())
796+
d.Set("engine_id", result.GetEngineId())
797+
d.Set("source_id", result.GetSourceId())
798+
d.Set("status", result.GetStatus())
799+
d.Set("engine_name", result.GetEngineName())
800+
d.Set("current_timeflow_id", result.GetCurrentTimeflowId())
801+
d.Set("is_appdata", result.GetIsAppdata())
802+
d.Set("hooks", result.GetHooks())
803+
d.Set("sync_policy_id", result.GetSyncPolicyId())
804+
d.Set("retention_policy_id", result.GetReplicaRetentionPolicyId())
805+
d.Set("log_sync_enabled", result.GetLogsyncEnabled())
806+
d.Set("exported_data_directory", result.GetExportedDataDirectory())
807+
return diags
808+
}
809+
810+
func resourceOracleDsourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
811+
// get the changed keys
812+
changedKeys := make([]string, 0, len(d.State().Attributes))
813+
for k := range d.State().Attributes {
814+
if d.HasChange(k) {
815+
changedKeys = append(changedKeys, k)
816+
}
817+
}
818+
// revert and set the old value to the changed keys
819+
for _, key := range changedKeys {
820+
old, _ := d.GetChange(key)
821+
d.Set(key, old)
751822
}
752-
return items
823+
824+
return diag.Errorf("Action update not implemented for resource : dSource")
825+
}
826+
827+
func resourceOracleDsourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
828+
client := meta.(*apiClient).client
829+
830+
dsourceId := d.Id()
831+
832+
deleteDsourceParams := dctapi.NewDeleteDSourceRequest(dsourceId)
833+
deleteDsourceParams.SetForce(false)
834+
835+
res, httpRes, err := client.DSourcesAPI.DeleteDsource(ctx).DeleteDSourceRequest(*deleteDsourceParams).Execute()
836+
837+
if diags := apiErrorResponseHelper(ctx, res, httpRes, err); diags != nil {
838+
return diags
839+
}
840+
841+
job_status, job_err := PollJobStatus(*res.Id, ctx, client)
842+
if job_err != "" {
843+
tflog.Warn(ctx, DLPX+WARN+"Job Polling failed but continuing with deletion. Error :"+job_err)
844+
}
845+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_status)
846+
if isJobTerminalFailure(job_status) {
847+
return diag.Errorf("[NOT OK] dSource-Delete %s. JobId: %s / Error: %s", job_status, *res.Id, job_err)
848+
}
849+
850+
_, diags := PollForObjectDeletion(ctx, func() (interface{}, *http.Response, error) {
851+
return client.DSourcesAPI.GetDsourceById(ctx, dsourceId).Execute()
852+
})
853+
854+
return diags
753855
}

internal/provider/utility.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,11 @@ func toTagArray(array interface{}) []dctapi.Tag {
302302
}
303303
return items
304304
}
305+
306+
func toIntArray(array interface{}) []int32 {
307+
items := []int32{}
308+
for _, item := range array.([]interface{}) {
309+
items = append(items, int32(item.(int)))
310+
}
311+
return items
312+
}

0 commit comments

Comments
 (0)