Skip to content

Commit 34e1501

Browse files
author
Uddipaan Hazarika
committed
fix for source-config imports
1 parent d3aed19 commit 34e1501

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

docs/resources/database_postgresql.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,18 @@ resource "delphix_database_postgresql" "source" {
6666
* `tags` - The tags to be created for database. This is a map of 2 parameters:
6767
* `key` - Key of the tag
6868
* `value` - Value of the tag
69+
70+
## Import (Beta)
71+
72+
Use the [`import` block](https://developer.hashicorp.com/terraform/language/import) to add source configs created directly in Data Control Tower into a Terraform state file.
73+
74+
For example:
75+
```terraform
76+
import {
77+
to = delphix_database_postgresql.source_config_import
78+
id = "source_config_id"
79+
}
80+
```
81+
82+
*This is a beta feature. Delphix offers no guarantees of support or compatibility.*
83+

internal/provider/resource_database_postgresql.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"context"
55
"net/http"
6+
"strings"
67

78
dctapi "github.com/delphix/dct-sdk-go/v22"
89
"github.com/hashicorp/terraform-plugin-log/tflog"
@@ -181,7 +182,6 @@ func resourceDatabasePostgressqlCreate(ctx context.Context, d *schema.ResourceDa
181182
}
182183

183184
func resourceDatabasePostgressqlRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
184-
185185
client := meta.(*apiClient).client
186186

187187
source_id := d.Id()
@@ -217,7 +217,25 @@ func resourceDatabasePostgressqlRead(ctx context.Context, d *schema.ResourceData
217217
return diag.Errorf("Error occured in type casting.")
218218
}
219219

220+
repository_value := d.Get("repository_value").(string)
221+
222+
if repository_value == "" {
223+
resEnv, httpRes, err := client.EnvironmentsAPI.GetEnvironmentById(ctx, result.GetEnvironmentId()).Execute()
224+
225+
if diags := apiErrorResponseHelper(ctx, resEnv, httpRes, err); diags != nil {
226+
return diags
227+
}
228+
if result.GetRepository() != "" {
229+
for _, repo := range resEnv.Repositories {
230+
if strings.EqualFold(repo.GetId(), result.GetRepository()) {
231+
repository_value = repo.GetName()
232+
}
233+
}
234+
}
235+
}
236+
220237
d.Set("id", result.GetId())
238+
d.Set("repository_value", repository_value)
221239
d.Set("environment_id", result.GetEnvironmentId())
222240
d.Set("database_type", result.GetDatabaseType())
223241
d.Set("name", result.GetName())

0 commit comments

Comments
 (0)