Skip to content

Commit 294b50c

Browse files
author
Uddipaan Hazarika
committed
added update logic in oracle dsource
1 parent b175770 commit 294b50c

File tree

2 files changed

+120
-6
lines changed

2 files changed

+120
-6
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Visit https://goreleaser.com for documentation on how to customize this
22
# behavior.
33
env:
4-
- PROVIDER_VERSION=3.3.1
4+
- PROVIDER_VERSION=3.4.0
55
before:
66
hooks:
77
# this is just an example and not a requirement for provider building/publishing

internal/provider/resource_oracle_dsource.go

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func resourceOracleDsource() *schema.Resource {
3232
},
3333
"group_id": {
3434
Type: schema.TypeString,
35-
Required: true,
35+
Optional: true,
3636
},
3737
"description": {
3838
Type: schema.TypeString,
@@ -808,20 +808,134 @@ func resourceOracleDsourceRead(ctx context.Context, d *schema.ResourceData, meta
808808
}
809809

810810
func resourceOracleDsourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
811+
812+
var diags diag.Diagnostics
813+
client := meta.(*apiClient).client
814+
updateOracleDsource := dctapi.NewUpdateOracleDsourceParameters()
815+
816+
dsourceId := d.Get("id").(string)
817+
811818
// get the changed keys
812819
changedKeys := make([]string, 0, len(d.State().Attributes))
813820
for k := range d.State().Attributes {
814821
if d.HasChange(k) {
822+
tflog.Debug(ctx, "changed keys"+k)
815823
changedKeys = append(changedKeys, k)
816824
}
817825
}
818-
// revert and set the old value to the changed keys
826+
827+
var updateFailure bool = false
828+
var nonUpdatableField []string
829+
830+
// check if the changed keys are updatable
819831
for _, key := range changedKeys {
820-
old, _ := d.GetChange(key)
821-
d.Set(key, old)
832+
if !updatableOracleDsourceKeys[key] {
833+
updateFailure = true
834+
tflog.Debug(ctx, "non updatable field: "+key)
835+
nonUpdatableField = append(nonUpdatableField, key)
836+
}
837+
}
838+
839+
// if not updatable keys are provided, error out
840+
if updateFailure {
841+
revertChanges(d, changedKeys)
842+
return diag.Errorf("cannot update options %v. Please refer to provider documentation for updatable params.", nonUpdatableField)
843+
}
844+
845+
// set changed params in the updateOracleDsource
846+
if d.HasChange("name") {
847+
updateOracleDsource.SetName(d.Get("name").(string))
848+
}
849+
if d.HasChange("environment_user_id") {
850+
updateOracleDsource.SetEnvironmentUserId(d.Get("environment_user_id").(string))
851+
}
852+
if d.HasChange("backup_level_enabled") {
853+
updateOracleDsource.SetBackupLevelEnabled(d.Get("backup_level_enabled").(bool))
854+
}
855+
if d.HasChange("rman_channels") {
856+
updateOracleDsource.SetRmanChannels(d.Get("rman_channels").(int32))
857+
}
858+
if d.HasChange("files_per_set") {
859+
updateOracleDsource.SetFilesPerSet(d.Get("files_per_set").(int32))
860+
}
861+
if d.HasChange("check_logical") {
862+
updateOracleDsource.SetCheckLogical(d.Get("check_logical").(bool))
822863
}
864+
if d.HasChange("encrypted_linking_enabled") {
865+
updateOracleDsource.SetEncryptedLinkingEnabled(d.Get("encrypted_linking_enabled").(bool))
866+
}
867+
if d.HasChange("compressed_linking_enabled") {
868+
updateOracleDsource.SetCompressedLinkingEnabled(d.Get("compressed_linking_enabled").(bool))
869+
}
870+
if d.HasChange("bandwidth_limit") {
871+
updateOracleDsource.SetBandwidthLimit(d.Get("bandwidth_limit").(int32))
872+
}
873+
if d.HasChange("number_of_connections") {
874+
updateOracleDsource.SetNumberOfConnections(d.Get("number_of_connections").(int32))
875+
}
876+
if d.HasChange("pre_provisioning_enabled") {
877+
updateOracleDsource.SetPreProvisioningEnabled(d.Get("pre_provisioning_enabled").(bool))
878+
}
879+
if d.HasChange("diagnose_no_logging_faults") {
880+
updateOracleDsource.SetDiagnoseNoLoggingFaults(d.Get("diagnose_no_logging_faults").(bool))
881+
}
882+
if d.HasChange("external_file_path") {
883+
updateOracleDsource.SetExternalFilePath(d.Get("external_file_path").(string))
884+
}
885+
// if d.HasChange("log_sync_mode") {
886+
// updateOracleDsource.SetLogSyncMode(d.Get("log_sync_mode").(string))
887+
// }
888+
// if d.HasChange("log_sync_interval") {
889+
// updateOracleDsource.SetLogSyncInterval(d.Get("log_sync_interval").(string))
890+
// }
891+
892+
res, httpRes, err := client.DSourcesAPI.UpdateOracleDsourceById(ctx, dsourceId).UpdateOracleDsourceParameters(*updateOracleDsource).Execute()
823893

824-
return diag.Errorf("Action update not implemented for resource : dSource")
894+
if diags := apiErrorResponseHelper(ctx, nil, httpRes, err); diags != nil {
895+
// revert and set the old value to the changed keys
896+
revertChanges(d, changedKeys)
897+
return diags
898+
}
899+
900+
job_status, job_err := PollJobStatus(*res.Job.Id, ctx, client)
901+
if job_err != "" {
902+
tflog.Warn(ctx, DLPX+WARN+"Dsource Update Job Polling failed but continuing with update. Error: "+job_err)
903+
}
904+
tflog.Info(ctx, DLPX+INFO+"Job result is "+job_status)
905+
if isJobTerminalFailure(job_status) {
906+
return diag.Errorf("[NOT OK] Dsource-Update %s. JobId: %s / Error: %s", job_status, *res.Job.Id, job_err)
907+
}
908+
909+
if d.HasChanges(
910+
"tags",
911+
) { // tags update
912+
tflog.Debug(ctx, "updating tags")
913+
if d.HasChange("tags") {
914+
// delete old tag
915+
tflog.Debug(ctx, "deleting old tags")
916+
oldTag, newTag := d.GetChange("tags")
917+
if len(toTagArray(oldTag)) != 0 {
918+
tflog.Debug(ctx, "tag to be deleted: "+toTagArray(oldTag)[0].GetKey()+" "+toTagArray(oldTag)[0].GetValue())
919+
deleteTag := *dctapi.NewDeleteTag()
920+
tagDelResp, tagDelErr := client.DSourcesAPI.DeleteTagsDsource(ctx, dsourceId).DeleteTag(deleteTag).Execute()
921+
if diags := apiErrorResponseHelper(ctx, nil, tagDelResp, tagDelErr); diags != nil {
922+
revertChanges(d, changedKeys)
923+
updateFailure = true
924+
}
925+
}
926+
// create tag
927+
if len(toTagArray(newTag)) != 0 {
928+
tflog.Info(ctx, "creating new tags")
929+
_, httpResp, tagCrtErr := client.DSourcesAPI.CreateTagsDsource(ctx, dsourceId).TagsRequest(*dctapi.NewTagsRequest(toTagArray(newTag))).Execute()
930+
if diags := apiErrorResponseHelper(ctx, nil, httpResp, tagCrtErr); diags != nil {
931+
revertChanges(d, changedKeys)
932+
return diags
933+
}
934+
}
935+
}
936+
}
937+
938+
return diags
825939
}
826940

827941
func resourceOracleDsourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

0 commit comments

Comments
 (0)