Skip to content

Commit aca13b7

Browse files
Ravi Tandonrcohenma
authored andcommitted
Support tagging in nested objects (cleanup)
1 parent dac53c4 commit aca13b7

11 files changed

+85
-70
lines changed

provider/containerengine_cluster_resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ func (s *ClusterResourceCrud) mapToClusterCreateOptions(fieldKeyFormat string) (
594594
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "add_ons"), 0)
595595
tmp, err := s.mapToAddOnOptions(fieldKeyFormatNextLevel)
596596
if err != nil {
597-
return result, err
597+
return result, fmt.Errorf("unable to convert add_ons, encountered error: %v", err)
598598
}
599599
result.AddOns = &tmp
600600
}
@@ -605,7 +605,7 @@ func (s *ClusterResourceCrud) mapToClusterCreateOptions(fieldKeyFormat string) (
605605
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "kubernetes_network_config"), 0)
606606
tmp, err := s.mapToKubernetesNetworkConfig(fieldKeyFormatNextLevel)
607607
if err != nil {
608-
return result, err
608+
return result, fmt.Errorf("unable to convert kubernetes_network_config, encountered error: %v", err)
609609
}
610610
result.KubernetesNetworkConfig = &tmp
611611
}

provider/core_instance_resource.go

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ func (s *InstanceResourceCrud) Create() error {
420420
}
421421

422422
if rawExtendedMetadata, ok := s.D.GetOkExists("extended_metadata"); ok {
423-
extendedMetadata := mapToExtendedMetadata(rawExtendedMetadata.(map[string]interface{}))
423+
extendedMetadata, err := mapToExtendedMetadata(rawExtendedMetadata.(map[string]interface{}))
424+
if err != nil {
425+
return err
426+
}
424427
request.ExtendedMetadata = extendedMetadata
425428
}
426429

@@ -690,7 +693,7 @@ func (s *InstanceResourceCrud) SetData() error {
690693
}
691694
}
692695

693-
err := s.D.Set("create_vnic_details", []interface{}{vnicDetailsToMap(vnic, createVnicDetails)})
696+
err := s.D.Set("create_vnic_details", []interface{}{CreateVnicDetailsToMap(vnic, createVnicDetails)})
694697
if err != nil {
695698
log.Printf("[WARN] create_vnic_details could not be set: %q", err)
696699
}
@@ -713,11 +716,11 @@ func (s *InstanceResourceCrud) mapToCreateVnicDetailsInstance(fieldKeyFormat str
713716
}
714717

715718
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
716-
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
719+
tmp, err := mapToDefinedTags(definedTags.(map[string]interface{}))
717720
if err != nil {
718-
return result, err
721+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
719722
}
720-
result.DefinedTags = convertedDefinedTags
723+
result.DefinedTags = tmp
721724
}
722725

723726
if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok {
@@ -752,40 +755,7 @@ func (s *InstanceResourceCrud) mapToCreateVnicDetailsInstance(fieldKeyFormat str
752755
return result, nil
753756
}
754757

755-
func (s *InstanceResourceCrud) mapToUpdateVnicDetailsInstance(fieldKeyFormat string) (oci_core.UpdateVnicDetails, error) {
756-
result := oci_core.UpdateVnicDetails{}
757-
758-
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
759-
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
760-
if err != nil {
761-
return result, err
762-
}
763-
result.DefinedTags = convertedDefinedTags
764-
}
765-
766-
if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok {
767-
tmp := displayName.(string)
768-
result.DisplayName = &tmp
769-
}
770-
771-
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
772-
result.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
773-
}
774-
775-
if hostnameLabel, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "hostname_label")); ok {
776-
tmp := hostnameLabel.(string)
777-
result.HostnameLabel = &tmp
778-
}
779-
780-
if skipSourceDestCheck, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "skip_source_dest_check")); ok {
781-
tmp := skipSourceDestCheck.(bool)
782-
result.SkipSourceDestCheck = &tmp
783-
}
784-
785-
return result, nil
786-
}
787-
788-
func vnicDetailsToMap(obj *oci_core.Vnic, createVnicDetails map[string]interface{}) map[string]interface{} {
758+
func CreateVnicDetailsToMap(obj *oci_core.Vnic, createVnicDetails map[string]interface{}) map[string]interface{} {
789759
result := map[string]interface{}{}
790760

791761
// "assign_public_ip" isn't part of the VNIC's state & is only useful at creation time (and
@@ -808,9 +778,7 @@ func vnicDetailsToMap(obj *oci_core.Vnic, createVnicDetails map[string]interface
808778
result["display_name"] = string(*obj.DisplayName)
809779
}
810780

811-
if obj.FreeformTags != nil {
812-
result["freeform_tags"] = obj.FreeformTags
813-
}
781+
result["freeform_tags"] = obj.FreeformTags
814782

815783
if obj.HostnameLabel != nil {
816784
result["hostname_label"] = string(*obj.HostnameLabel)
@@ -831,6 +799,39 @@ func vnicDetailsToMap(obj *oci_core.Vnic, createVnicDetails map[string]interface
831799
return result
832800
}
833801

802+
func (s *InstanceResourceCrud) mapToUpdateVnicDetailsInstance(fieldKeyFormat string) (oci_core.UpdateVnicDetails, error) {
803+
result := oci_core.UpdateVnicDetails{}
804+
805+
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
806+
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
807+
if err != nil {
808+
return result, err
809+
}
810+
result.DefinedTags = convertedDefinedTags
811+
}
812+
813+
if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok {
814+
tmp := displayName.(string)
815+
result.DisplayName = &tmp
816+
}
817+
818+
if freeformTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "freeform_tags")); ok {
819+
result.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
820+
}
821+
822+
if hostnameLabel, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "hostname_label")); ok {
823+
tmp := hostnameLabel.(string)
824+
result.HostnameLabel = &tmp
825+
}
826+
827+
if skipSourceDestCheck, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "skip_source_dest_check")); ok {
828+
tmp := skipSourceDestCheck.(bool)
829+
result.SkipSourceDestCheck = &tmp
830+
}
831+
832+
return result, nil
833+
}
834+
834835
func (s *InstanceResourceCrud) mapToInstanceSourceDetails(fieldKeyFormat string) (oci_core.InstanceSourceDetails, error) {
835836
var baseObject oci_core.InstanceSourceDetails
836837
//discriminator
@@ -904,7 +905,7 @@ func InstanceSourceDetailsToMap(obj *oci_core.InstanceSourceDetails, bootVolume
904905
return result
905906
}
906907

907-
func mapToExtendedMetadata(rm map[string]interface{}) map[string]interface{} {
908+
func mapToExtendedMetadata(rm map[string]interface{}) (map[string]interface{}, error) {
908909
result := make(map[string]interface{})
909910
for k, v := range rm {
910911
val := make(map[string]interface{})
@@ -915,7 +916,7 @@ func mapToExtendedMetadata(rm map[string]interface{}) map[string]interface{} {
915916
result[k] = v.(string)
916917
}
917918
}
918-
return result
919+
return result, nil
919920
}
920921

921922
func (s *InstanceResourceCrud) getPrimaryVnic() (*oci_core.Vnic, error) {

provider/core_security_list_resource.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func (s *SecurityListResourceCrud) mapToEgressSecurityRule(fieldKeyFormat string
698698
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "icmp_options"), 0)
699699
tmp, err := s.mapToIcmpOptions(fieldKeyFormatNextLevel)
700700
if err != nil {
701-
return result, err
701+
return result, fmt.Errorf("unable to convert icmp_options, encountered error: %v", err)
702702
}
703703
result.IcmpOptions = &tmp
704704
}
@@ -719,7 +719,7 @@ func (s *SecurityListResourceCrud) mapToEgressSecurityRule(fieldKeyFormat string
719719
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "tcp_options"), 0)
720720
tmp, err := s.mapToTcpOptions(fieldKeyFormatNextLevel)
721721
if err != nil {
722-
return result, err
722+
return result, fmt.Errorf("unable to convert tcp_options, encountered error: %v", err)
723723
}
724724
result.TcpOptions = &tmp
725725
}
@@ -730,7 +730,7 @@ func (s *SecurityListResourceCrud) mapToEgressSecurityRule(fieldKeyFormat string
730730
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "udp_options"), 0)
731731
tmp, err := s.mapToUdpOptions(fieldKeyFormatNextLevel)
732732
if err != nil {
733-
return result, err
733+
return result, fmt.Errorf("unable to convert udp_options, encountered error: %v", err)
734734
}
735735
result.UdpOptions = &tmp
736736
}
@@ -813,7 +813,7 @@ func (s *SecurityListResourceCrud) mapToIngressSecurityRule(fieldKeyFormat strin
813813
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "icmp_options"), 0)
814814
tmp, err := s.mapToIcmpOptions(fieldKeyFormatNextLevel)
815815
if err != nil {
816-
return result, err
816+
return result, fmt.Errorf("unable to convert icmp_options, encountered error: %v", err)
817817
}
818818
result.IcmpOptions = &tmp
819819
}
@@ -844,7 +844,7 @@ func (s *SecurityListResourceCrud) mapToIngressSecurityRule(fieldKeyFormat strin
844844
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "tcp_options"), 0)
845845
tmp, err := s.mapToTcpOptions(fieldKeyFormatNextLevel)
846846
if err != nil {
847-
return result, err
847+
return result, fmt.Errorf("unable to convert tcp_options, encountered error: %v", err)
848848
}
849849
result.TcpOptions = &tmp
850850
}
@@ -855,7 +855,7 @@ func (s *SecurityListResourceCrud) mapToIngressSecurityRule(fieldKeyFormat strin
855855
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "udp_options"), 0)
856856
tmp, err := s.mapToUdpOptions(fieldKeyFormatNextLevel)
857857
if err != nil {
858-
return result, err
858+
return result, fmt.Errorf("unable to convert udp_options, encountered error: %v", err)
859859
}
860860
result.UdpOptions = &tmp
861861
}
@@ -932,7 +932,10 @@ func (s *SecurityListResourceCrud) mapToTcpOptions(fieldKeyFormat string) (oci_c
932932
max, maxExists := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "max"))
933933
min, minExists := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "min"))
934934
if (maxExists && max.(int) != 0) || (minExists && min.(int) != 0) {
935-
tmp, _ := s.mapToPortRange(fieldKeyFormat)
935+
tmp, err := s.mapToPortRange(fieldKeyFormat)
936+
if err != nil {
937+
return result, fmt.Errorf("unable to convert destination_port_range, encountered error: %v", err)
938+
}
936939
result.DestinationPortRange = &tmp
937940
}
938941

@@ -941,7 +944,7 @@ func (s *SecurityListResourceCrud) mapToTcpOptions(fieldKeyFormat string) (oci_c
941944
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "source_port_range"), 0)
942945
tmp, err := s.mapToPortRange(fieldKeyFormatNextLevel)
943946
if err != nil {
944-
return result, err
947+
return result, fmt.Errorf("unable to convert source_port_range, encountered error: %v", err)
945948
}
946949
result.SourcePortRange = &tmp
947950
}
@@ -976,7 +979,10 @@ func (s *SecurityListResourceCrud) mapToUdpOptions(fieldKeyFormat string) (oci_c
976979
max, maxExists := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "max"))
977980
min, minExists := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "min"))
978981
if (maxExists && max.(int) != 0) || (minExists && min.(int) != 0) {
979-
tmp, _ := s.mapToPortRange(fieldKeyFormat)
982+
tmp, err := s.mapToPortRange(fieldKeyFormat)
983+
if err != nil {
984+
return result, fmt.Errorf("unable to convert destination_port_range, encountered error: %v", err)
985+
}
980986
result.DestinationPortRange = &tmp
981987
}
982988

@@ -985,7 +991,7 @@ func (s *SecurityListResourceCrud) mapToUdpOptions(fieldKeyFormat string) (oci_c
985991
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "source_port_range"), 0)
986992
tmp, err := s.mapToPortRange(fieldKeyFormatNextLevel)
987993
if err != nil {
988-
return result, err
994+
return result, fmt.Errorf("unable to convert source_port_range, encountered error: %v", err)
989995
}
990996
result.SourcePortRange = &tmp
991997
}

provider/core_vnic_attachment_resource.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ func (s *VnicAttachmentResourceCrud) mapToCreateVnicDetails(fieldKeyFormat strin
420420
}
421421

422422
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
423-
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
423+
tmp, err := mapToDefinedTags(definedTags.(map[string]interface{}))
424424
if err != nil {
425-
return result, err
425+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
426426
}
427-
result.DefinedTags = convertedDefinedTags
427+
result.DefinedTags = tmp
428428
}
429429

430430
if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok {
@@ -463,11 +463,11 @@ func (s *VnicAttachmentResourceCrud) mapToUpdateVnicDetails(fieldKeyFormat strin
463463
result := oci_core.UpdateVnicDetails{}
464464

465465
if definedTags, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "defined_tags")); ok {
466-
convertedDefinedTags, err := mapToDefinedTags(definedTags.(map[string]interface{}))
466+
tmp, err := mapToDefinedTags(definedTags.(map[string]interface{}))
467467
if err != nil {
468-
return result, err
468+
return result, fmt.Errorf("unable to convert defined_tags, encountered error: %v", err)
469469
}
470-
result.DefinedTags = convertedDefinedTags
470+
result.DefinedTags = tmp
471471
}
472472

473473
if displayName, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "display_name")); ok {
@@ -511,9 +511,7 @@ func VnicDetailsToMap(obj *oci_core.Vnic, createVnicDetails map[string]interface
511511
result["display_name"] = string(*obj.DisplayName)
512512
}
513513

514-
if obj.FreeformTags != nil {
515-
result["freeform_tags"] = obj.FreeformTags
516-
}
514+
result["freeform_tags"] = obj.FreeformTags
517515

518516
if obj.HostnameLabel != nil {
519517
result["hostname_label"] = string(*obj.HostnameLabel)

provider/database_database_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,5 @@ func (s *DatabaseDataSourceCrud) SetData() error {
195195

196196
return nil
197197
}
198+
199+
// @CODEGEN 08/2018: Method DbBackupConfigToMap is available in database_db_system_resource.go

provider/database_db_home_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ func (s *DbHomeDataSourceCrud) SetData() error {
127127

128128
return nil
129129
}
130+
131+
// @CODEGEN 08/2018: Methods CreateDatabaseDetailsToMap, CreateDatabaseFromBackupDetailsToMap and DbBackupConfigToMap are available in database_db_system_resource.go

provider/database_db_homes_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ func (s *DbHomesDataSourceCrud) SetData() error {
145145

146146
return nil
147147
}
148+
149+
// @CODEGEN 08/2018: Methods CreateDatabaseDetailsToMap, CreateDatabaseFromBackupDetailsToMap and DbBackupConfigToMap are available in database_db_system_resource.go

provider/database_db_system_resource.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ func (s *DbSystemResourceCrud) mapToCreateDatabaseDetails(fieldKeyFormat string)
631631
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "db_backup_config"), 0)
632632
tmp, err := s.mapToDbBackupConfig(fieldKeyFormatNextLevel)
633633
if err != nil {
634-
return result, err
634+
return result, fmt.Errorf("unable to convert db_backup_config, encountered error: %v", err)
635635
}
636636
result.DbBackupConfig = &tmp
637637
}
@@ -739,7 +739,7 @@ func (s *DbSystemResourceCrud) mapToCreateDbHomeDetails(fieldKeyFormat string) (
739739
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "database"), 0)
740740
tmp, err := s.mapToCreateDatabaseDetails(fieldKeyFormatNextLevel)
741741
if err != nil {
742-
return result, err
742+
return result, fmt.Errorf("unable to convert database, encountered error: %v", err)
743743
}
744744
result.Database = &tmp
745745
}
@@ -784,7 +784,7 @@ func (s *DbSystemResourceCrud) mapToCreateDbHomeFromBackupDetails(fieldKeyFormat
784784
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "database"), 0)
785785
tmp, err := s.mapToCreateDatabaseFromBackupDetails(fieldKeyFormatNextLevel)
786786
if err != nil {
787-
return result, err
787+
return result, fmt.Errorf("unable to convert database, encountered error: %v", err)
788788
}
789789
result.Database = &tmp
790790
}
@@ -833,6 +833,8 @@ func DbBackupConfigToMap(obj *oci_database.DbBackupConfig) map[string]interface{
833833
return result
834834
}
835835

836+
// @CODEGEN 08/2018: mapToPatchDetails and PatchDetailsToMap are not yet supported
837+
836838
func (s *DbSystemResourceCrud) populateTopLevelPolymorphicLaunchDbSystemRequest(request *oci_database.LaunchDbSystemRequest) error {
837839
//discriminator
838840
sourceRaw, ok := s.D.GetOkExists("source")

provider/dns_zone_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (s *ZoneResourceCrud) mapToExternalMaster(fieldKeyFormat string) (oci_dns.E
340340
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "tsig"), 0)
341341
tmp, err := s.mapToTSIG(fieldKeyFormatNextLevel)
342342
if err != nil {
343-
return result, err
343+
return result, fmt.Errorf("unable to convert tsig, encountered error: %v", err)
344344
}
345345
result.Tsig = &tmp
346346
}

provider/load_balancer_listener_resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,5 @@ func (s *ListenerResourceCrud) mapToSSLConfigurationDetails(fieldKeyFormat strin
531531

532532
return result, nil
533533
}
534+
535+
// @CODEGEN 08/2018 - Method SSLConfigurationDetailsToMap is available in load_balancer_backend_set_resource.go

0 commit comments

Comments
 (0)