Skip to content

Commit 2a2fcaa

Browse files
committed
Added - TER-5631 - Fixing cyclic model parsing
1 parent 9b1afc5 commit 2a2fcaa

File tree

6 files changed

+67
-62
lines changed

6 files changed

+67
-62
lines changed

internal/integrationtest/cloud_guard_detector_recipe_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ var (
5656
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
5757
"display_name": acctest.Representation{RepType: acctest.Required, Create: `displayName`, Update: `displayName2`},
5858
"source_detector_recipe_id": acctest.Representation{RepType: acctest.Required, Create: detectorRecipeId},
59-
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
6059
"description": acctest.Representation{RepType: acctest.Optional, Create: `description`, Update: `description2`},
6160
"detector_rules": acctest.RepresentationGroup{RepType: acctest.Optional, Group: CloudGuardDetectorRecipeDetectorRulesRepresentation},
6261
"freeform_tags": acctest.Representation{RepType: acctest.Optional, Create: map[string]string{"bar-key": "value"}, Update: map[string]string{"Department": "Accounting"}},

internal/service/cloud_guard/cloud_guard_detector_recipe_resource.go

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,8 @@ func DetectorDetailsToMap(obj *oci_cloud_guard.DetectorDetails) map[string]inter
807807
result := map[string]interface{}{}
808808

809809
if obj.Condition != nil {
810-
condition, err := tfresource.ConvertObjectToJsonString(obj.Condition)
811-
if err == nil {
812-
result["condition"] = condition
813-
}
810+
tmp, _ := json.Marshal(obj.Condition)
811+
result["condition"] = string(tmp)
814812
}
815813

816814
configurations := []interface{}{}
@@ -976,13 +974,12 @@ func (s *CloudGuardDetectorRecipeResourceCrud) mapToUpdateDetectorRuleDetails(fi
976974
//Condition Modelling
977975
if condition, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "condition")); ok {
978976
tmp := condition.(string)
979-
if len(tmp) > 0 {
980-
var err error
981-
result.Condition, err = jsonToCondition(tmp)
982-
if err != nil {
983-
return result, err
984-
}
977+
var conditionObj oci_cloud_guard.Condition
978+
err := json.Unmarshal([]byte(tmp), &conditionObj)
979+
if err != nil {
980+
return result, err
985981
}
982+
result.Condition = &conditionObj
986983
}
987984

988985
if configurations, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "configurations")); ok {
@@ -1050,39 +1047,6 @@ func (s *CloudGuardDetectorRecipeResourceCrud) updateCompartment(compartment int
10501047
return nil
10511048
}
10521049

1053-
type cloudGuardCondition struct {
1054-
JsonData []byte
1055-
Kind string `json:"kind"`
1056-
}
1057-
1058-
func jsonToCondition(data string) (oci_cloud_guard.Condition, error) {
1059-
var val cloudGuardCondition
1060-
if err := json.Unmarshal([]byte(data), &val); err == nil {
1061-
if schemaData, err := UnmarshalPolymorphicConditionJSON(val.Kind, data); err == nil {
1062-
return schemaData, nil
1063-
} else {
1064-
return nil, err
1065-
}
1066-
}
1067-
return nil, nil
1068-
}
1069-
1070-
func UnmarshalPolymorphicConditionJSON(kind string, data string) (oci_cloud_guard.Condition, error) {
1071-
var err error
1072-
switch kind {
1073-
case "SIMPLE":
1074-
mm := oci_cloud_guard.SimpleCondition{}
1075-
err = json.Unmarshal([]byte(data), &mm)
1076-
return mm, err
1077-
case "COMPOSITE":
1078-
mm := oci_cloud_guard.CompositeCondition{}
1079-
err = json.Unmarshal([]byte(data), &mm)
1080-
return mm, err
1081-
default:
1082-
return nil, nil
1083-
}
1084-
}
1085-
10861050
func (s *CloudGuardDetectorRecipeResourceCrud) mapToDetectorConfiguration(fieldKeyFormat string) (oci_cloud_guard.DetectorConfiguration, error) {
10871051
result := oci_cloud_guard.DetectorConfiguration{}
10881052

internal/service/cloud_guard/cloud_guard_target_resource.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cloud_guard
55

66
import (
77
"context"
8+
"encoding/json"
89
"fmt"
910
"log"
1011
"time"
@@ -1228,10 +1229,8 @@ func ConditionGroupToMap(obj oci_cloud_guard.ConditionGroup) map[string]interfac
12281229
}
12291230

12301231
if obj.Condition != nil {
1231-
condition, err := tfresource.ConvertObjectToJsonString(obj.Condition)
1232-
if err == nil {
1233-
result["condition"] = condition
1234-
}
1232+
tmp, _ := json.Marshal(obj.Condition)
1233+
result["condition"] = string(tmp)
12351234
}
12361235

12371236
return result
@@ -1871,13 +1870,13 @@ func (s *CloudGuardTargetResourceCrud) mapToUpdateTargetResponderRuleDetails(fie
18711870

18721871
if condition, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "condition")); ok {
18731872
tmp := condition.(string)
1874-
if len(tmp) > 0 {
1875-
var err error
1876-
result.Condition, err = jsonToCondition(tmp)
1877-
if err != nil {
1878-
return result, err
1879-
}
1873+
var conditionObj oci_cloud_guard.Condition
1874+
err := json.Unmarshal([]byte(tmp), &conditionObj)
1875+
1876+
if err != nil {
1877+
return result, err
18801878
}
1879+
result.Condition = &conditionObj
18811880
}
18821881

18831882
if configurations, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "configurations")); ok {
@@ -1970,13 +1969,13 @@ func (s *CloudGuardTargetResourceCrud) mapToConditionGroup(fieldKeyFormat string
19701969

19711970
if condition, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "condition")); ok {
19721971
tmp := condition.(string)
1973-
if len(tmp) > 0 {
1974-
var err error
1975-
result.Condition, err = jsonToCondition(tmp)
1976-
if err != nil {
1977-
return result, err
1978-
}
1972+
var conditionObj oci_cloud_guard.Condition
1973+
err := json.Unmarshal([]byte(tmp), &conditionObj)
1974+
1975+
if err != nil {
1976+
return result, err
19791977
}
1978+
result.Condition = &conditionObj
19801979
}
19811980

19821981
return result, nil

internal/service/data_connectivity/data_connectivity_registry_data_asset_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package data_connectivity
55

66
import (
77
"context"
8+
"encoding/json"
89

910
"terraform-provider-oci/internal/client"
1011
"terraform-provider-oci/internal/tfresource"
@@ -87,6 +88,11 @@ func (s *DataConnectivityRegistryDataAssetDataSourceCrud) SetData() error {
8788
s.D.Set("description", *s.Res.Description)
8889
}
8990

91+
if s.Res.EndPoints != nil {
92+
tmp, _ := json.Marshal(s.Res.EndPoints)
93+
s.D.Set("end_points", string(tmp))
94+
}
95+
9096
if s.Res.ExternalKey != nil {
9197
s.D.Set("external_key", *s.Res.ExternalKey)
9298
}

internal/service/data_connectivity/data_connectivity_registry_data_asset_resource.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@ func DataConnectivityRegistryDataAssetResource() *schema.Resource {
579579
Optional: true,
580580
Computed: true,
581581
},
582+
"end_points": {
583+
Type: schema.TypeList,
584+
Optional: true,
585+
Computed: true,
586+
Elem: &schema.Schema{
587+
Type: schema.TypeString,
588+
},
589+
},
582590
"external_key": {
583591
Type: schema.TypeString,
584592
Optional: true,
@@ -1117,6 +1125,16 @@ func (s *DataConnectivityRegistryDataAssetResourceCrud) Create() error {
11171125
request.Description = &tmp
11181126
}
11191127

1128+
if endPoints, ok := s.D.GetOkExists("end_points"); ok {
1129+
tmp := strings.Join(endPoints.([]string), " ")
1130+
var endPointsObj []oci_data_connectivity.DpEndpoint
1131+
err := json.Unmarshal([]byte(tmp), &endPointsObj)
1132+
if err != nil {
1133+
return err
1134+
}
1135+
request.EndPoints = endPointsObj
1136+
}
1137+
11201138
if externalKey, ok := s.D.GetOkExists("external_key"); ok {
11211139
tmp := externalKey.(string)
11221140
request.ExternalKey = &tmp
@@ -1253,7 +1271,6 @@ func (s *DataConnectivityRegistryDataAssetResourceCrud) Get() error {
12531271

12541272
func (s *DataConnectivityRegistryDataAssetResourceCrud) Update() error {
12551273
request := oci_data_connectivity.UpdateDataAssetRequest{}
1256-
12571274
if assetProperties, ok := s.D.GetOkExists("asset_properties"); ok {
12581275
request.AssetProperties = tfresource.ObjectMapToStringMap(assetProperties.(map[string]interface{}))
12591276
}
@@ -1279,6 +1296,16 @@ func (s *DataConnectivityRegistryDataAssetResourceCrud) Update() error {
12791296
request.Description = &tmp
12801297
}
12811298

1299+
if endPoints, ok := s.D.GetOkExists("end_points"); ok {
1300+
tmp := strings.Join(endPoints.([]string), " ")
1301+
var endPointsObj []oci_data_connectivity.DpEndpoint
1302+
err := json.Unmarshal([]byte(tmp), &endPointsObj)
1303+
if err != nil {
1304+
return err
1305+
}
1306+
request.EndPoints = endPointsObj
1307+
}
1308+
12821309
if externalKey, ok := s.D.GetOkExists("external_key"); ok {
12831310
tmp := externalKey.(string)
12841311
request.ExternalKey = &tmp
@@ -1417,6 +1444,11 @@ func (s *DataConnectivityRegistryDataAssetResourceCrud) SetData() error {
14171444
s.D.Set("description", *s.Res.Description)
14181445
}
14191446

1447+
if s.Res.EndPoints != nil {
1448+
tmp, _ := json.Marshal(s.Res.EndPoints)
1449+
s.D.Set("end_points", string(tmp))
1450+
}
1451+
14201452
if s.Res.ExternalKey != nil {
14211453
s.D.Set("external_key", *s.Res.ExternalKey)
14221454
}
@@ -1739,6 +1771,11 @@ func DataConnectivityDataAssetSummaryToMap(obj oci_data_connectivity.DataAssetSu
17391771
result["description"] = string(*obj.Description)
17401772
}
17411773

1774+
if obj.EndPoints != nil {
1775+
tmp, _ := json.Marshal(obj.EndPoints)
1776+
result["end_points"] = string(tmp)
1777+
}
1778+
17421779
if obj.ExternalKey != nil {
17431780
result["external_key"] = string(*obj.ExternalKey)
17441781
}

ocibuild.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ steps:
6464
args: "-func cover.out -o coverage/coverage.txt"
6565
}
6666
]
67-
testCoverageLocation : "coverage.html"
67+
testCoverageLocation : "coverage/coverage.txt"
6868
artifacts: [
6969
"**"
7070
]

0 commit comments

Comments
 (0)