Skip to content

Commit 95774d2

Browse files
Terraform Team AutomationMeharwadeDivya
authored andcommitted
Added - Changes on test and resource files for DMS Validation and Migration error cause and resolution. Reviewer comments addressed.
1 parent 42ecbe9 commit 95774d2

13 files changed

+111
-151
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "job_ocid" {}
2+
3+
data "oci_database_migration_job" "test_job" {
4+
job_id = var.job_ocid
5+
}

internal/integrationtest/database_migration_job_test.go

Lines changed: 14 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ package integrationtest
66
import (
77
"context"
88
"fmt"
9-
"strconv"
109
"testing"
1110
"time"
1211

1312
"github.com/oracle/terraform-provider-oci/internal/acctest"
1413
tf_client "github.com/oracle/terraform-provider-oci/internal/client"
15-
"github.com/oracle/terraform-provider-oci/internal/resourcediscovery"
1614
"github.com/oracle/terraform-provider-oci/internal/tfresource"
1715
"github.com/oracle/terraform-provider-oci/internal/utils"
1816

@@ -26,169 +24,42 @@ import (
2624
)
2725

2826
var (
29-
DatabaseMigrationJobRequiredOnlyResource = DatabaseMigrationJobResourceDependencies +
30-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Required, acctest.Create, jobRepresentation)
31-
32-
DatabaseMigrationJobResourceConfig = //DatabaseMigrationJobResourceDependencies +
33-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Optional, acctest.Update, jobRepresentation2)
34-
3527
DatabaseMigrationjobSingularDataSourceRepresentation = map[string]interface{}{
36-
"job_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_migration_job.test_job.id}`},
37-
}
38-
39-
DatabaseMigrationjobDataSourceRepresentation = map[string]interface{}{
40-
"migration_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_migration_migration.test_migration.id}`},
41-
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `TF_displayName`, Update: `TF_displayName2`},
42-
"state": acctest.Representation{RepType: acctest.Optional, Create: `Succeeded`},
43-
"filter": acctest.RepresentationGroup{RepType: acctest.Required, Group: jobDataSourceFilterRepresentation}}
44-
jobDataSourceFilterRepresentation = map[string]interface{}{
45-
"name": acctest.Representation{RepType: acctest.Required, Create: `TF_id`},
46-
"values": acctest.Representation{RepType: acctest.Required, Create: []string{`${oci_database_migration_job.test_job.id}`}},
28+
"job_id": acctest.Representation{RepType: acctest.Required, Create: `${var.oci_job_id}`},
4729
}
4830

4931
jobRepresentation = map[string]interface{}{
50-
"job_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_migration_job.test_job.id}`},
51-
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `TF_displayName`, Update: `TF_displayName2`},
32+
"job_id": acctest.Representation{RepType: acctest.Required, Create: `${var.oci_job_id}`},
5233
}
53-
54-
jobRepresentation2 = map[string]interface{}{
55-
"job_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_migration_job.test_job.id}`},
56-
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `TF_displayName`, Update: `TF_displayName2`},
57-
}
58-
59-
DatabaseMigrationJobResourceDependencies = acctest.GenerateResourceFromRepresentationMap("oci_apigateway_deployment", "test_deployment", acctest.Required, acctest.Create, ApigatewayDeploymentRepresentation) +
60-
acctest.GenerateResourceFromRepresentationMap("oci_apigateway_gateway", "test_gateway", acctest.Required, acctest.Create, ApigatewayRepresentation) +
61-
acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Required, acctest.Create, CoreSubnetRepresentation) +
62-
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, CoreVcnRepresentation) +
63-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_connection", "test_connection", acctest.Required, acctest.Create, connectionRepresentationCon) +
64-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Required, acctest.Create, jobRepresentation) +
65-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_migration", "test_migration", acctest.Required, acctest.Create, migrationRepresentation) +
66-
acctest.GenerateResourceFromRepresentationMap("oci_functions_application", "test_application", acctest.Required, acctest.Create, FunctionsApplicationRepresentation) +
67-
acctest.GenerateResourceFromRepresentationMap("oci_functions_function", "test_function", acctest.Required, acctest.Create, FunctionsFunctionRepresentation) +
68-
DefinedTagsDependencies +
69-
KeyResourceDependencyConfig +
70-
acctest.GenerateResourceFromRepresentationMap("oci_kms_vault", "test_vault", acctest.Required, acctest.Create, KmsVaultRepresentation) +
71-
acctest.GenerateResourceFromRepresentationMap("oci_objectstorage_bucket", "test_bucket", acctest.Required, acctest.Create, ObjectStorageBucketRepresentation) +
72-
acctest.GenerateDataSourceFromRepresentationMap("oci_objectstorage_namespace", "test_namespace", acctest.Required, acctest.Create, ObjectStorageObjectStorageNamespaceSingularDataSourceRepresentation)
7334
)
7435

7536
// issue-routing-tag: database_migration/default
7637
func TestDatabaseMigrationJobResource_basic(t *testing.T) {
77-
t.Skip("Skip this job creation is an independent operation after validating the migration")
7838
httpreplay.SetScenario("TestDatabaseMigrationJobResource_basic")
7939
defer httpreplay.SaveScenario()
8040

8141
config := acctest.ProviderTestConfig()
8242

83-
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
84-
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
43+
jobId := utils.GetEnvSettingWithBlankDefault("job_ocid")
44+
jobIdVariableStr := fmt.Sprintf("variable \"oci_job_id\" { default = \"%s\" }\n", jobId)
8545

86-
resourceName := "oci_database_migration_job.test_job"
87-
datasourceName := "data.oci_database_migration_jobs.test_jobs"
8846
singularDatasourceName := "data.oci_database_migration_job.test_job"
8947

90-
var resId, resId2 string
91-
// Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "Create with optionals" step in the test.
92-
acctest.SaveConfigContent(config+compartmentIdVariableStr+
93-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Optional, acctest.Create, jobRepresentation), "databasemigration", "job", t)
94-
9548
acctest.ResourceTest(t, testAccCheckDatabaseMigrationJobDestroy, []resource.TestStep{
96-
// verify Create
97-
{
98-
Config: config + compartmentIdVariableStr +
99-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Required, acctest.Create, jobRepresentation),
100-
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
101-
resource.TestCheckResourceAttrSet(resourceName, "job_id"),
102-
103-
func(s *terraform.State) (err error) {
104-
resId, err = acctest.FromInstanceState(s, resourceName, "job_id")
105-
return err
106-
},
107-
),
108-
},
109-
110-
// delete before next Create
111-
{
112-
Config: config + compartmentIdVariableStr,
113-
},
114-
// verify Create with optionals
115-
{
116-
Config: config + compartmentIdVariableStr +
117-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Optional, acctest.Create, jobRepresentation2),
118-
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
119-
resource.TestCheckResourceAttr(resourceName, "display_name", "TF_displayName"),
120-
resource.TestCheckResourceAttrSet(resourceName, "job_id"),
121-
resource.TestCheckResourceAttrSet(resourceName, "migration_id"),
122-
resource.TestCheckResourceAttrSet(resourceName, "state"),
123-
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
124-
resource.TestCheckResourceAttrSet(resourceName, "type"),
125-
func(s *terraform.State) (err error) {
126-
resId, err = acctest.FromInstanceState(s, resourceName, "job_id")
127-
if isEnableExportCompartment, _ := strconv.ParseBool(utils.GetEnvSettingWithDefault("enable_export_compartment", "true")); isEnableExportCompartment {
128-
if errExport := resourcediscovery.TestExportCompartmentWithResourceName(&resId, &compartmentId, resourceName); errExport != nil {
129-
return errExport
130-
}
131-
}
132-
return err
133-
},
134-
),
135-
},
136-
137-
// verify updates to updatable parameters
138-
{
139-
Config: config + compartmentIdVariableStr +
140-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Optional, acctest.Update, jobRepresentation2),
141-
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
142-
resource.TestCheckResourceAttr(resourceName, "display_name", "TF_displayName2"),
143-
resource.TestCheckResourceAttrSet(resourceName, "job_id"),
144-
resource.TestCheckResourceAttrSet(resourceName, "migration_id"),
145-
resource.TestCheckResourceAttrSet(resourceName, "state"),
146-
resource.TestCheckResourceAttrSet(resourceName, "time_created"),
147-
resource.TestCheckResourceAttrSet(resourceName, "type"),
148-
func(s *terraform.State) (err error) {
149-
resId2, err = acctest.FromInstanceState(s, resourceName, "job_id")
150-
if resId != resId2 {
151-
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
152-
}
153-
return err
154-
},
155-
),
156-
},
157-
// verify datasource
158-
{
159-
Config: config +
160-
acctest.GenerateDataSourceFromRepresentationMap("oci_database_migration_jobs", "test_jobs", acctest.Optional, acctest.Update, DatabaseMigrationjobDataSourceRepresentation) +
161-
compartmentIdVariableStr + //DatabaseMigrationJobResourceDependencies +
162-
acctest.GenerateResourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Optional, acctest.Update, jobRepresentation2),
163-
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
164-
resource.TestCheckResourceAttr(datasourceName, "display_name", "TF_displayName2"),
165-
resource.TestCheckResourceAttr(datasourceName, "state", "Succeeded"),
166-
resource.TestCheckResourceAttr(datasourceName, "job_collection.#", "1"),
167-
resource.TestCheckResourceAttr(datasourceName, "job_collection.0.items.#", "0"),
168-
),
169-
},
17049
// verify singular datasource
17150
{
172-
Config: config +
173-
acctest.GenerateDataSourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Required, acctest.Create, DatabaseMigrationjobSingularDataSourceRepresentation) +
174-
compartmentIdVariableStr + DatabaseMigrationJobResourceConfig,
51+
Config: config + jobIdVariableStr +
52+
acctest.GenerateDataSourceFromRepresentationMap("oci_database_migration_job", "test_job", acctest.Required, acctest.Create, DatabaseMigrationjobSingularDataSourceRepresentation),
17553
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
17654
resource.TestCheckResourceAttrSet(singularDatasourceName, "job_id"),
177-
resource.TestCheckResourceAttr(singularDatasourceName, "display_name", "TF_displayName2"),
178-
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
179-
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_created"),
180-
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_updated"),
181-
resource.TestCheckResourceAttrSet(singularDatasourceName, "type"),
55+
resource.TestCheckResourceAttr(singularDatasourceName, "progress.0.phases.0.status", "COMPLETED"),
56+
resource.TestCheckResourceAttr(singularDatasourceName, "progress.0.phases.0.issue", ""),
57+
resource.TestCheckResourceAttr(singularDatasourceName, "progress.0.phases.0.action", ""),
58+
resource.TestCheckResourceAttr(singularDatasourceName, "progress.0.phases.1.status", "FAILED"),
59+
resource.TestCheckResourceAttrSet(singularDatasourceName, "progress.0.phases.1.issue"),
60+
resource.TestCheckResourceAttrSet(singularDatasourceName, "progress.0.phases.1.action"),
18261
),
18362
},
184-
// verify resource import
185-
{
186-
Config: config + DatabaseMigrationJobRequiredOnlyResource,
187-
ImportState: true,
188-
ImportStateVerify: false,
189-
ImportStateVerifyIgnore: []string{},
190-
ResourceName: resourceName,
191-
},
19263
})
19364
}
19465

@@ -209,7 +80,8 @@ func testAccCheckDatabaseMigrationJobDestroy(s *terraform.State) error {
20980

21081
if err == nil {
21182
deletedLifecycleStates := map[string]bool{
212-
string(oci_database_migration.JobLifecycleStatesTerminated): true,
83+
// Because of the nature of this test, the Job is expected to finish in a Failed State
84+
string(oci_database_migration.JobLifecycleStatesFailed): true,
21385
}
21486
if _, ok := deletedLifecycleStates[string(response.LifecycleState)]; !ok {
21587
//resource lifecycle state is not in expected deleted lifecycle states.

internal/service/database_migration/database_migration_connection_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (s *DatabaseMigrationConnectionDataSourceCrud) SetData() error {
110110
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
111111
}
112112

113+
s.D.Set("nsg_ids", s.Res.NsgIds)
114+
113115
if s.Res.PrivateEndpoint != nil {
114116
s.D.Set("private_endpoint", []interface{}{PrivateEndpointDetailsToMap(s.Res.PrivateEndpoint)})
115117
} else {

internal/service/database_migration/database_migration_connection_resource.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ func DatabaseMigrationConnectionResource() *schema.Resource {
162162
Computed: true,
163163
Elem: schema.TypeString,
164164
},
165+
"nsg_ids": {
166+
Type: schema.TypeSet,
167+
Optional: true,
168+
Computed: true,
169+
Set: tfresource.LiteralTypeHashCodeForSets,
170+
Elem: &schema.Schema{
171+
Type: schema.TypeString,
172+
},
173+
},
165174
"private_endpoint": {
166175
Type: schema.TypeList,
167176
Optional: true,
@@ -397,6 +406,20 @@ func (s *DatabaseMigrationConnectionResourceCrud) Create() error {
397406
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
398407
}
399408

409+
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok {
410+
set := nsgIds.(*schema.Set)
411+
interfaces := set.List()
412+
tmp := make([]string, len(interfaces))
413+
for i := range interfaces {
414+
if interfaces[i] != nil {
415+
tmp[i] = interfaces[i].(string)
416+
}
417+
}
418+
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
419+
request.NsgIds = tmp
420+
}
421+
}
422+
400423
if privateEndpoint, ok := s.D.GetOkExists("private_endpoint"); ok {
401424
if tmpList := privateEndpoint.([]interface{}); len(tmpList) > 0 {
402425
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "private_endpoint", 0)
@@ -648,6 +671,20 @@ func (s *DatabaseMigrationConnectionResourceCrud) Update() error {
648671
request.FreeformTags = tfresource.ObjectMapToStringMap(freeformTags.(map[string]interface{}))
649672
}
650673

674+
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok {
675+
set := nsgIds.(*schema.Set)
676+
interfaces := set.List()
677+
tmp := make([]string, len(interfaces))
678+
for i := range interfaces {
679+
if interfaces[i] != nil {
680+
tmp[i] = interfaces[i].(string)
681+
}
682+
}
683+
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
684+
request.NsgIds = tmp
685+
}
686+
}
687+
651688
if privateEndpoint, ok := s.D.GetOkExists("private_endpoint"); ok {
652689
if tmpList := privateEndpoint.([]interface{}); len(tmpList) > 0 {
653690
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "private_endpoint", 0)
@@ -768,6 +805,12 @@ func (s *DatabaseMigrationConnectionResourceCrud) SetData() error {
768805
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
769806
}
770807

808+
nsgIds := []interface{}{}
809+
for _, item := range s.Res.NsgIds {
810+
nsgIds = append(nsgIds, item)
811+
}
812+
s.D.Set("nsg_ids", schema.NewSet(tfresource.LiteralTypeHashCodeForSets, nsgIds))
813+
771814
if s.Res.PrivateEndpoint != nil {
772815
s.D.Set("private_endpoint", []interface{}{PrivateEndpointDetailsToMap(s.Res.PrivateEndpoint)})
773816
} else {
@@ -834,6 +877,11 @@ func ConnectionSummaryToMapMig(obj oci_database_migration.ConnectionSummary) map
834877
result["lifecycle_details"] = string(*obj.LifecycleDetails)
835878
}
836879

880+
nsgIds := []interface{}{}
881+
for _, item := range obj.NsgIds {
882+
nsgIds = append(nsgIds, item)
883+
}
884+
837885
result["state"] = string(obj.LifecycleState)
838886

839887
if obj.SystemTags != nil {

internal/service/database_migration/database_migration_job_resource.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func DatabaseMigrationJobResource() *schema.Resource {
8989
// Optional
9090

9191
// Computed
92+
"action": {
93+
Type: schema.TypeString,
94+
Computed: true,
95+
},
9296
"duration_in_ms": {
9397
Type: schema.TypeInt,
9498
Computed: true,
@@ -118,6 +122,10 @@ func DatabaseMigrationJobResource() *schema.Resource {
118122
Type: schema.TypeBool,
119123
Computed: true,
120124
},
125+
"issue": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
},
121129
"log_location": {
122130
Type: schema.TypeList,
123131
Computed: true,
@@ -535,6 +543,10 @@ func PhaseExtractEntryToMap(obj oci_database_migration.PhaseExtractEntry) map[st
535543
func PhaseStatusToMap(obj oci_database_migration.PhaseStatus) map[string]interface{} {
536544
result := map[string]interface{}{}
537545

546+
if obj.Action != nil {
547+
result["action"] = string(*obj.Action)
548+
}
549+
538550
if obj.DurationInMs != nil {
539551
result["duration_in_ms"] = int(*obj.DurationInMs)
540552
}
@@ -549,6 +561,10 @@ func PhaseStatusToMap(obj oci_database_migration.PhaseStatus) map[string]interfa
549561
result["is_advisor_report_available"] = bool(*obj.IsAdvisorReportAvailable)
550562
}
551563

564+
if obj.Issue != nil {
565+
result["issue"] = string(*obj.Issue)
566+
}
567+
552568
if obj.LogLocation != nil {
553569
result["log_location"] = []interface{}{LogLocationBucketDetailsToMap(obj.LogLocation)}
554570
}

internal/service/database_migration/database_migration_migration_resource.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,14 @@ func DatabaseMigrationMigrationResource() *schema.Resource {
242242
Type: schema.TypeString,
243243
Required: true,
244244
},
245+
246+
// Optional
245247
"path": {
246248
Type: schema.TypeString,
247-
Required: true,
249+
Optional: true,
250+
Computed: true,
248251
},
249252

250-
// Optional
251-
252253
// Computed
253254
},
254255
},
@@ -266,13 +267,14 @@ func DatabaseMigrationMigrationResource() *schema.Resource {
266267
Type: schema.TypeString,
267268
Required: true,
268269
},
270+
271+
// Optional
269272
"path": {
270273
Type: schema.TypeString,
271-
Required: true,
274+
Optional: true,
275+
Computed: true,
272276
},
273277

274-
// Optional
275-
276278
// Computed
277279
},
278280
},

website/docs/d/database_migration_connection.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The following attributes are exported:
4949
* `freeform_tags` - Simple key-value pair that is applied without any predefined name, type or scope. Exists for cross-compatibility only. Example: `{"bar-key": "value"}`
5050
* `id` - The OCID of the resource
5151
* `lifecycle_details` - A message describing the current state in more detail. For example, can be used to provide actionable information for a resource in Failed state.
52+
* `nsg_ids` - An array of Network Security Group OCIDs used to define network access for Connections.
5253
* `private_endpoint` - Oracle Cloud Infrastructure Private Endpoint configuration details.
5354
* `compartment_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the compartment to contain the private endpoint.
5455
* `id` - [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of a previously created Private Endpoint.

0 commit comments

Comments
 (0)