Skip to content

Commit 99defcb

Browse files
Emily ShimodaMaxrovr
authored andcommitted
Added - oprional parameters to import
1 parent 326dbfc commit 99defcb

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

examples/management_dashboard/main.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ provider "oci" {
1010
}
1111

1212
data "oci_management_dashboard_management_dashboards_export" "test_export" {
13-
export_dashboard_id = "{\"dashboardIds\":[\"ocid1.managementdashboard.dev..aaaaaaaazrrxainoaive7adj77uqejld45vch7zkoqrlh5fwv2_dummy_ocids\"]}"
13+
export_dashboard_id = "%7B%22dashboardIds%22%3A%5B%22dummy_ocid%22%5D%7D"
1414
}
1515

1616
// example showing import_details usage
@@ -23,6 +23,21 @@ resource "oci_management_dashboard_management_dashboards_import" "test_import_vi
2323
import_details_file = "sample.json"
2424
}
2525

26+
resource "oci_management_dashboard_management_dashboards_import" "test_import_override_name" {
27+
override_same_name = true
28+
import_details_file = "sample.json"
29+
}
30+
31+
resource "oci_management_dashboard_management_dashboards_import" "test_import_override_ss_compartment" {
32+
override_saved_search_compartment_ocid = "dummy_ocid"
33+
import_details_file = "sample.json"
34+
}
35+
36+
resource "oci_management_dashboard_management_dashboards_import" "test_import_override_db_compartment" {
37+
override_dashboard_compartment_ocid = "dummy_ocid"
38+
import_details_file = "sample.json"
39+
}
40+
2641
output "test_export_data_all" {
2742
value = data.oci_management_dashboard_management_dashboards_export.test_export
2843
}

internal/service/management_dashboard/management_dashboard_management_dashboards_import_resource.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ func ManagementDashboardManagementDashboardsImportResource() *schema.Resource {
4040
ForceNew: true,
4141
ConflictsWith: []string{"import_details_file"},
4242
},
43+
"override_dashboard_compartment_ocid": {
44+
Type: schema.TypeString,
45+
Optional: true,
46+
Computed: true,
47+
ForceNew: true,
48+
},
49+
"override_same_name": {
50+
Type: schema.TypeString,
51+
Optional: true,
52+
Computed: true,
53+
ForceNew: true,
54+
},
55+
"override_saved_search_compartment_ocid": {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
Computed: true,
59+
ForceNew: true,
60+
},
4361
},
4462
}
4563
}
@@ -84,6 +102,23 @@ func (s *ManagementDashboardManagementDashboardsImportResourceCrud) Create() err
84102
request.ManagementDashboardImportDetails = importDetailsObj
85103
}
86104

105+
if overrideDashboardCompartmentOcid, ok := s.D.GetOkExists("override_dashboard_compartment_ocid"); ok {
106+
tmp := overrideDashboardCompartmentOcid.(string)
107+
request.OverrideDashboardCompartmentOcid = &tmp
108+
}
109+
110+
if overrideSameName, ok := s.D.GetOkExists("override_same_name"); ok {
111+
tmp := overrideSameName.(string)
112+
request.OverrideSameName = &tmp
113+
}
114+
115+
if overrideSavedSearchCompartmentOcid, ok := s.D.GetOkExists("override_saved_search_compartment_ocid"); ok {
116+
tmp := overrideSavedSearchCompartmentOcid.(string)
117+
request.OverrideSavedSearchCompartmentOcid = &tmp
118+
}
119+
120+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "management_dashboard")
121+
87122
if importDetailsFilePath, ok := s.D.GetOkExists("import_details_file"); ok {
88123
flag = true
89124
importDetailsFileData, err := ioutil.ReadFile(importDetailsFilePath.(string))
@@ -105,9 +140,10 @@ func (s *ManagementDashboardManagementDashboardsImportResourceCrud) Create() err
105140

106141
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "management_dashboard")
107142

108-
_, err := s.Client.ImportDashboard(context.Background(), request)
143+
response, err := s.Client.ImportDashboard(context.Background(), request)
109144
if err != nil {
110-
return err
145+
return fmt.Errorf("response: %s \n error: %s", response, err)
146+
111147
}
112148

113149
return nil

website/docs/r/management_dashboard_management_dashboards_import.html.markdown

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ Here's an example of how you can use CLI to import:
2323
```hcl
2424
resource "oci_management_dashboard_management_dashboards_import" "test_management_dashboards_import" {
2525
#Optional
26-
import_details = var.sample_import_details
27-
import_details_file = var.sample_import_details_file_path
26+
override_dashboard_compartment_ocid = var.management_dashboards_import_override_dashboard_compartment_ocid
27+
override_same_name = var.management_dashboards_import_override_same_name
28+
override_saved_search_compartment_ocid = var.management_dashboards_import_override_saved_search_compartment_ocid
2829
}
2930
```
3031

3132
## Argument Reference
3233

3334
The following arguments are supported:
3435

35-
* `import_details` - (Optional) Array of Dashboards to import. The `import_details` is mandatory if `import_details_path` is not passed. Value should be stringified JSON of [ManagementDashboardImportDetails](https://docs.cloud.oracle.com/en-us/iaas/api/#/en/managementdashboard/20200901/ManagementDashboardImportDetails/)
36-
* `import_details_path` - (Optional) Array of Dashboards to import. The `import_details_path` is mandatory if `import_details` is not passed. Value should be the path to the JSON file containing [ManagementDashboardImportDetails](https://docs.cloud.oracle.com/en-us/iaas/api/#/en/managementdashboard/20200901/ManagementDashboardImportDetails/)
36+
37+
* `override_dashboard_compartment_ocid` - (Optional) If this attribute is set, the dashboard resources are created or updated in the compartment specified by OCID. If this attribute is not set, the compartment specified in the JSON metadata is used.
38+
* `override_same_name` - (Optional) By default, if a resource with the same OCID exists in the target compartment, it is updated during the import process, otherwise, a new resource is created. However, if this attribute is set to true, then during the import process if a resource with the same displayName exists in the compartment, then it is updated even if the OCIDs are different. This is useful when importing the same resource multiple times. If the compartment and displayName remain the same, the resource is only updated and multiple copies of a resource are not created.
39+
* `override_saved_search_compartment_ocid` - (Optional) If this attribute is set, the saved search resources are created or updated in the compartment specified by OCID. If this attribute is not set, the compartment specified in the JSON metadata is used.
40+
3741

3842
** IMPORTANT **
3943
Any change to a property that does not support update will force the destruction and recreation of the resource with the new property values

0 commit comments

Comments
 (0)