33package oci
44
55import (
6+ "bytes"
67 "context"
78 "fmt"
89 "log"
910 "strings"
1011 "time"
1112
12- "github.com/terraform-providers/terraform-provider-oci/httpreplay"
13-
13+ "github.com/hashicorp/terraform/helper/hashcode"
1414 "github.com/hashicorp/terraform/helper/resource"
1515 "github.com/hashicorp/terraform/helper/schema"
1616 "github.com/hashicorp/terraform/helper/validation"
1717
18+ "github.com/terraform-providers/terraform-provider-oci/httpreplay"
19+
1820 oci_common "github.com/oracle/oci-go-sdk/common"
1921 oci_containerengine "github.com/oracle/oci-go-sdk/containerengine"
2022)
@@ -99,8 +101,9 @@ func ContainerengineNodePoolResource() *schema.Resource {
99101 Schema : map [string ]* schema.Schema {
100102 // Required
101103 "placement_configs" : {
102- Type : schema .TypeList ,
104+ Type : schema .TypeSet ,
103105 Required : true ,
106+ Set : placementConfigsHashCodeForSets ,
104107 Elem : & schema.Resource {
105108 Schema : map [string ]* schema.Schema {
106109 // Required
@@ -742,7 +745,7 @@ func (s *ContainerengineNodePoolResourceCrud) SetData() error {
742745 }
743746
744747 if s .Res .NodeConfigDetails != nil {
745- s .D .Set ("node_config_details" , []interface {}{NodePoolNodeConfigDetailsToMap (s .Res .NodeConfigDetails )})
748+ s .D .Set ("node_config_details" , []interface {}{NodePoolNodeConfigDetailsToMap (s .Res .NodeConfigDetails , false )})
746749 } else {
747750 s .D .Set ("node_config_details" , nil )
748751 }
@@ -802,10 +805,11 @@ func (s *ContainerengineNodePoolResourceCrud) mapToCreateNodePoolNodeConfigDetai
802805 result := oci_containerengine.CreateNodePoolNodeConfigDetails {}
803806
804807 if placementConfigs , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "placement_configs" )); ok {
805- interfaces := placementConfigs .([]interface {})
808+ set := placementConfigs .(* schema.Set )
809+ interfaces := set .List ()
806810 tmp := make ([]oci_containerengine.NodePoolPlacementConfigDetails , len (interfaces ))
807811 for i := range interfaces {
808- stateDataIndex := i
812+ stateDataIndex := placementConfigsHashCodeForSets ( interfaces [ i ])
809813 fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "placement_configs" ), stateDataIndex )
810814 converted , err := s .mapToNodePoolPlacementConfigDetails (fieldKeyFormatNextLevel )
811815 if err != nil {
@@ -826,14 +830,18 @@ func (s *ContainerengineNodePoolResourceCrud) mapToCreateNodePoolNodeConfigDetai
826830 return result , nil
827831}
828832
829- func NodePoolNodeConfigDetailsToMap (obj * oci_containerengine.NodePoolNodeConfigDetails ) map [string ]interface {} {
833+ func NodePoolNodeConfigDetailsToMap (obj * oci_containerengine.NodePoolNodeConfigDetails , datasource bool ) map [string ]interface {} {
830834 result := map [string ]interface {}{}
831835
832836 placementConfigs := []interface {}{}
833837 for _ , item := range obj .PlacementConfigs {
834838 placementConfigs = append (placementConfigs , NodePoolPlacementConfigDetailsToMap (item ))
835839 }
836- result ["placement_configs" ] = placementConfigs
840+ if datasource {
841+ result ["placement_configs" ] = placementConfigs
842+ } else {
843+ result ["placement_configs" ] = schema .NewSet (placementConfigsHashCodeForSets , placementConfigs )
844+ }
837845
838846 if obj .Size != nil {
839847 result ["size" ] = int (* obj .Size )
@@ -1034,23 +1042,38 @@ func NodeSourceOptionToMap(obj *oci_containerengine.NodeSourceOption) map[string
10341042 return result
10351043}
10361044
1045+ func placementConfigsHashCodeForSets (v interface {}) int {
1046+ var buf bytes.Buffer
1047+ m := v .(map [string ]interface {})
1048+ if availabilityDomain , ok := m ["availability_domain" ]; ok && availabilityDomain != "" {
1049+ buf .WriteString (fmt .Sprintf ("%v-" , availabilityDomain ))
1050+ }
1051+ if subnetId , ok := m ["subnet_id" ]; ok && subnetId != "" {
1052+ buf .WriteString (fmt .Sprintf ("%v-" , subnetId ))
1053+ }
1054+ return hashcode .String (buf .String ())
1055+ }
1056+
10371057func (s * ContainerengineNodePoolResourceCrud ) mapToUpdateNodePoolNodeConfigDetails (fieldKeyFormat string ) (oci_containerengine.UpdateNodePoolNodeConfigDetails , error ) {
10381058 result := oci_containerengine.UpdateNodePoolNodeConfigDetails {}
10391059
10401060 result .PlacementConfigs = []oci_containerengine.NodePoolPlacementConfigDetails {}
10411061 if placementConfigs , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "placement_configs" )); ok {
1042- interfaces := placementConfigs .([]interface {})
1062+ set := placementConfigs .(* schema.Set )
1063+ interfaces := set .List ()
10431064 tmp := make ([]oci_containerengine.NodePoolPlacementConfigDetails , len (interfaces ))
10441065 for i := range interfaces {
1045- stateDataIndex := i
1066+ stateDataIndex := placementConfigsHashCodeForSets ( interfaces [ i ])
10461067 fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "placement_configs" ), stateDataIndex )
10471068 converted , err := s .mapToNodePoolPlacementConfigDetails (fieldKeyFormatNextLevel )
10481069 if err != nil {
10491070 return result , err
10501071 }
10511072 tmp [i ] = converted
10521073 }
1053- result .PlacementConfigs = tmp
1074+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "placement_configs" )) {
1075+ result .PlacementConfigs = tmp
1076+ }
10541077 }
10551078
10561079 if size , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "size" )); ok {
0 commit comments