@@ -314,7 +314,7 @@ func runExportCommand(clients *OracleClients, args *ExportCommandArgs) error {
314314 return err
315315 }
316316
317- if len (resource .terraformTypeInfo .ignorableRequiredMissingAttributes ) > 0 {
317+ if resource . terraformTypeInfo != nil && len (resource .terraformTypeInfo .ignorableRequiredMissingAttributes ) > 0 {
318318 attributes := make ([]string , 0 , len (resource .terraformTypeInfo .ignorableRequiredMissingAttributes ))
319319 for attribute := range resource .terraformTypeInfo .ignorableRequiredMissingAttributes {
320320 attributes = append (attributes , attribute )
@@ -649,7 +649,7 @@ func (tr *TerraformResource) getTerraformReference() string {
649649 return fmt .Sprintf ("%s.%s" , tr .terraformClass , tr .terraformName )
650650}
651651
652- func getHCLStringFromMap (builder * strings.Builder , sourceAttributes map [string ]interface {}, resourceSchema * schema.Resource , interpolationMap map [string ]string , terraformResourceHints * TerraformResourceHints , attributePrefix string ) error {
652+ func getHCLStringFromMap (builder * strings.Builder , sourceAttributes map [string ]interface {}, resourceSchema * schema.Resource , interpolationMap map [string ]string , ociRes * OCIResource , attributePrefix string ) error {
653653 sortedKeys := make ([]string , len (resourceSchema .Schema ))
654654 cnt := 0
655655 for k := range resourceSchema .Schema {
@@ -694,7 +694,7 @@ func getHCLStringFromMap(builder *strings.Builder, sourceAttributes map[string]i
694694 } else {
695695 attributePrefixForRecursiveCall = fmt .Sprintf ("%s.%s[%d]" , attributePrefix , tfAttribute , i )
696696 }
697- if err := getHCLStringFromMap (builder , val , elem , interpolationMap , terraformResourceHints , attributePrefixForRecursiveCall ); err != nil {
697+ if err := getHCLStringFromMap (builder , val , elem , interpolationMap , ociRes , attributePrefixForRecursiveCall ); err != nil {
698698 return err
699699 }
700700 builder .WriteString ("}\n " )
@@ -737,7 +737,7 @@ func getHCLStringFromMap(builder *strings.Builder, sourceAttributes map[string]i
737737 } else {
738738 attributePrefixForRecursiveCall = attributePrefix + "." + tfAttribute
739739 }
740- if err := getHCLStringFromMap (builder , v , nestedResource , interpolationMap , terraformResourceHints , attributePrefixForRecursiveCall ); err != nil {
740+ if err := getHCLStringFromMap (builder , v , nestedResource , interpolationMap , ociRes , attributePrefixForRecursiveCall ); err != nil {
741741 return err
742742 }
743743 builder .WriteString ("}\n " )
@@ -787,7 +787,14 @@ func getHCLStringFromMap(builder *strings.Builder, sourceAttributes map[string]i
787787 We can extend this in future to provide this option to customer to add default values for attributes
788788 and add this logic to Optional attributes too */
789789
790- if tfAttributeVal , exists := terraformResourceHints .defaultValuesForMissingAttributes [tfAttribute ]; exists {
790+ if ociRes .terraformTypeInfo == nil {
791+ ociRes .terraformTypeInfo = & TerraformResourceHints {}
792+ }
793+
794+ if ociRes .terraformTypeInfo .defaultValuesForMissingAttributes == nil {
795+ ociRes .terraformTypeInfo .defaultValuesForMissingAttributes = make (map [string ]string )
796+ }
797+ if tfAttributeVal , exists := ociRes .terraformTypeInfo .defaultValuesForMissingAttributes [tfAttribute ]; exists {
791798 builder .WriteString (fmt .Sprintf ("%s = %q" , tfAttribute , tfAttributeVal ))
792799 } else {
793800 builder .WriteString (fmt .Sprintf ("%s = %q" , tfAttribute , placeholderValueForMissingAttribute ))
@@ -796,13 +803,13 @@ func getHCLStringFromMap(builder *strings.Builder, sourceAttributes map[string]i
796803 isMissingRequiredAttributes = true
797804
798805 /* Add missing required attribute to ignorableRequiredMissingAttributes to be generated in lifecycle ignore_changes */
799- if terraformResourceHints .ignorableRequiredMissingAttributes == nil {
800- terraformResourceHints .ignorableRequiredMissingAttributes = make (map [string ]bool )
806+ if ociRes . terraformTypeInfo .ignorableRequiredMissingAttributes == nil {
807+ ociRes . terraformTypeInfo .ignorableRequiredMissingAttributes = make (map [string ]bool )
801808 }
802809 if attributePrefix == "" {
803- terraformResourceHints .ignorableRequiredMissingAttributes [tfAttribute ] = true
810+ ociRes . terraformTypeInfo .ignorableRequiredMissingAttributes [tfAttribute ] = true
804811 } else {
805- terraformResourceHints .ignorableRequiredMissingAttributes [attributePrefix + "." + tfAttribute ] = true
812+ ociRes . terraformTypeInfo .ignorableRequiredMissingAttributes [attributePrefix + "." + tfAttribute ] = true
806813 }
807814
808815 } else if tfSchema .Optional {
@@ -833,11 +840,11 @@ func getHclStringFromGenericMap(builder *strings.Builder, ociRes *OCIResource, i
833840 resourceSchema := resourcesMap [ociRes .terraformClass ]
834841
835842 builder .WriteString (fmt .Sprintf ("resource %s %s {\n " , ociRes .terraformClass , ociRes .terraformName ))
836- if err := getHCLStringFromMap (builder , ociRes .sourceAttributes , resourceSchema , interpolationMap , ociRes . terraformTypeInfo , "" ); err != nil {
843+ if err := getHCLStringFromMap (builder , ociRes .sourceAttributes , resourceSchema , interpolationMap , ociRes , "" ); err != nil {
837844 return err
838845 }
839846
840- if len (ociRes .terraformTypeInfo .ignorableRequiredMissingAttributes ) > 0 {
847+ if ociRes . terraformTypeInfo != nil && len (ociRes .terraformTypeInfo .ignorableRequiredMissingAttributes ) > 0 {
841848 builder .WriteString ("\n # Required attributes that were not found in discovery have been added to " +
842849 "lifecycle ignore_changes" )
843850 builder .WriteString ("\n # This is done to avoid terraform plan failure for the existing infrastructure" )
0 commit comments