@@ -148,11 +148,16 @@ func VisualBuilderVbInstanceResource() *schema.Resource {
148148 DiffSuppressFunc : tfresource .EqualIgnoreCaseSuppressDiff ,
149149 ValidateFunc : validation .StringInSlice ([]string {
150150 "PRIVATE" ,
151+ "PUBLIC" ,
151152 }, true ),
152153 },
153154 "subnet_id" : {
154155 Type : schema .TypeString ,
155- Required : true ,
156+ Optional : true , // Since there can be PUBLIC endpoint type also. for validation see CustomizeDiff
157+ ConflictsWith : []string {
158+ "network_endpoint_details.allowlisted_http_ips" ,
159+ "network_endpoint_details.allowlisted_http_vcns" ,
160+ },
156161 },
157162
158163 // Optional
@@ -164,15 +169,86 @@ func VisualBuilderVbInstanceResource() *schema.Resource {
164169 Elem : & schema.Schema {
165170 Type : schema .TypeString ,
166171 },
172+ ConflictsWith : []string {
173+ "network_endpoint_details.allowlisted_http_ips" ,
174+ "network_endpoint_details.allowlisted_http_vcns" ,
175+ },
167176 },
168177 "private_endpoint_ip" : {
169178 Type : schema .TypeString ,
170179 Optional : true ,
171180 Computed : true ,
172181 ForceNew : true ,
182+ ConflictsWith : []string {
183+ "network_endpoint_details.allowlisted_http_ips" ,
184+ "network_endpoint_details.allowlisted_http_vcns" ,
185+ },
186+ },
187+ "allowlisted_http_ips" : {
188+ Type : schema .TypeList ,
189+ Optional : true ,
190+ Computed : true ,
191+ Elem : & schema.Schema {
192+ Type : schema .TypeString ,
193+ },
194+ ConflictsWith : []string {"network_endpoint_details.subnet_id" , "network_endpoint_details.network_security_group_ids" , "network_endpoint_details.private_endpoint_ip" },
195+ },
196+ "allowlisted_http_vcns" : {
197+ Type : schema .TypeList ,
198+ Optional : true ,
199+ Computed : true ,
200+ ConflictsWith : []string {"network_endpoint_details.subnet_id" , "network_endpoint_details.network_security_group_ids" , "network_endpoint_details.private_endpoint_ip" },
201+ Elem : & schema.Resource {
202+ Schema : map [string ]* schema.Schema {
203+ // Required
204+ "id" : {
205+ Type : schema .TypeString ,
206+ Required : true ,
207+ },
208+
209+ // Optional
210+ "allowlisted_ip_cidrs" : {
211+ Type : schema .TypeList ,
212+ Optional : true ,
213+ Computed : true ,
214+ Elem : & schema.Schema {
215+ Type : schema .TypeString ,
216+ },
217+ },
218+ },
219+ },
173220 },
174-
175- // Computed
221+ },
222+ CustomizeDiff : func (ctx context.Context , diff * schema.ResourceDiff , meta interface {}) error {
223+ networkEndpointType := diff .Get ("network_endpoint_type" ).(string )
224+
225+ if networkEndpointType == "PRIVATE" {
226+ if _ , ok := diff .GetOk ("subnet_id" ); ! ok {
227+ return fmt .Errorf ("subnet_id is required for PRIVATE network type" )
228+ }
229+ if _ , ok := diff .GetOk ("allowlisted_http_ips" ); ok {
230+ return fmt .Errorf ("allowlisted_http_ips cannot be used with PRIVATE network type" )
231+ }
232+ if _ , ok := diff .GetOk ("allowlisted_http_vcns" ); ok {
233+ return fmt .Errorf ("allowlisted_http_vcns cannot be used with PRIVATE network type" )
234+ }
235+ }
236+
237+ if networkEndpointType == "PUBLIC" {
238+ if _ , ok := diff .GetOk ("subnet_id" ); ok {
239+ return fmt .Errorf ("subnet_id cannot be used with PUBLIC network type" )
240+ }
241+ if _ , ok := diff .GetOk ("network_security_group_ids" ); ok {
242+ return fmt .Errorf ("network_security_group_ids cannot be used with PUBLIC network type" )
243+ }
244+ if _ , ok := diff .GetOk ("private_endpoint_ip" ); ok {
245+ return fmt .Errorf ("private_endpoint_ip cannot be used with PUBLIC network type" )
246+ }
247+ if _ , ok := diff .GetOk ("allowlisted_http_ips" ); ! ok && ! diff .HasChange ("allowlisted_http_vcns" ) {
248+ return fmt .Errorf ("either allowlisted_http_ips or allowlisted_http_vcns must be specified for PUBLIC network type" )
249+ }
250+ }
251+ return nil
176252 },
177253 },
178254 },
@@ -859,6 +935,37 @@ func (s *VisualBuilderVbInstanceResourceCrud) mapToNetworkEndpointDetails(fieldK
859935 details .SubnetId = & tmp
860936 }
861937 baseObject = details
938+ case strings .ToLower ("PUBLIC" ):
939+ details := oci_visual_builder.UpdatePublicEndpointDetails {}
940+ if allowlistedHttpIps , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_ips" )); ok {
941+ interfaces := allowlistedHttpIps .([]interface {})
942+ tmp := make ([]string , len (interfaces ))
943+ for i := range interfaces {
944+ if interfaces [i ] != nil {
945+ tmp [i ] = interfaces [i ].(string )
946+ }
947+ }
948+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_ips" )) {
949+ details .AllowlistedHttpIps = tmp
950+ }
951+ }
952+ if allowlistedHttpVcns , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" )); ok {
953+ interfaces := allowlistedHttpVcns .([]interface {})
954+ tmp := make ([]oci_visual_builder.VirtualCloudNetwork , len (interfaces ))
955+ for i := range interfaces {
956+ stateDataIndex := i
957+ fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" ), stateDataIndex )
958+ converted , err := s .mapToVirtualCloudNetwork (fieldKeyFormatNextLevel )
959+ if err != nil {
960+ return details , err
961+ }
962+ tmp [i ] = converted
963+ }
964+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" )) {
965+ details .AllowlistedHttpVcns = tmp
966+ }
967+ }
968+ baseObject = details
862969 default :
863970 return nil , fmt .Errorf ("unknown network_endpoint_type '%v' was specified" , networkEndpointType )
864971 }
@@ -896,6 +1003,37 @@ func (s *VisualBuilderVbInstanceResourceCrud) mapToUpdateNetworkEndpointDetails(
8961003 details .SubnetId = & tmp
8971004 }
8981005 baseObject = details
1006+ case strings .ToLower ("PUBLIC" ):
1007+ details := oci_visual_builder.UpdatePublicEndpointDetails {}
1008+ if allowlistedHttpIps , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_ips" )); ok {
1009+ interfaces := allowlistedHttpIps .([]interface {})
1010+ tmp := make ([]string , len (interfaces ))
1011+ for i := range interfaces {
1012+ if interfaces [i ] != nil {
1013+ tmp [i ] = interfaces [i ].(string )
1014+ }
1015+ }
1016+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_ips" )) {
1017+ details .AllowlistedHttpIps = tmp
1018+ }
1019+ }
1020+ if allowlistedHttpVcns , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" )); ok {
1021+ interfaces := allowlistedHttpVcns .([]interface {})
1022+ tmp := make ([]oci_visual_builder.VirtualCloudNetwork , len (interfaces ))
1023+ for i := range interfaces {
1024+ stateDataIndex := i
1025+ fieldKeyFormatNextLevel := fmt .Sprintf ("%s.%d.%%s" , fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" ), stateDataIndex )
1026+ converted , err := s .mapToVirtualCloudNetwork (fieldKeyFormatNextLevel )
1027+ if err != nil {
1028+ return details , err
1029+ }
1030+ tmp [i ] = converted
1031+ }
1032+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "allowlisted_http_vcns" )) {
1033+ details .AllowlistedHttpVcns = tmp
1034+ }
1035+ }
1036+ baseObject = details
8991037 default :
9001038 return nil , fmt .Errorf ("unknown network_endpoint_type '%v' was specified" , networkEndpointType )
9011039 }
@@ -914,7 +1052,6 @@ func NetworkEndpointDetailsToMap(obj *oci_visual_builder.NetworkEndpointDetails,
9141052 networkSecurityGroupIds = append (networkSecurityGroupIds , item )
9151053 }
9161054 result ["network_security_group_ids" ] = networkSecurityGroupIds
917- log .Printf ("Here => %s" , result )
9181055
9191056 if v .SubnetId != nil {
9201057 result ["subnet_id" ] = string (* v .SubnetId )
@@ -938,6 +1075,26 @@ func NetworkEndpointDetailsToMap(obj *oci_visual_builder.NetworkEndpointDetails,
9381075 if v .SubnetId != nil {
9391076 result ["subnet_id" ] = string (* v .SubnetId )
9401077 }
1078+ case oci_visual_builder.PublicEndpointDetails :
1079+ result ["network_endpoint_type" ] = "PUBLIC"
1080+
1081+ result ["allowlisted_http_ips" ] = v .AllowlistedHttpIps
1082+
1083+ allowlistedHttpVcns := []interface {}{}
1084+ for _ , item := range v .AllowlistedHttpVcns {
1085+ allowlistedHttpVcns = append (allowlistedHttpVcns , VirtualCloudNetworkToMap (item ))
1086+ }
1087+ result ["allowlisted_http_vcns" ] = allowlistedHttpVcns
1088+ case oci_visual_builder.UpdatePublicEndpointDetails :
1089+ result ["network_endpoint_type" ] = "PUBLIC"
1090+
1091+ result ["allowlisted_http_ips" ] = v .AllowlistedHttpIps
1092+
1093+ allowlistedHttpVcns := []interface {}{}
1094+ for _ , item := range v .AllowlistedHttpVcns {
1095+ allowlistedHttpVcns = append (allowlistedHttpVcns , VirtualCloudNetworkToMap (item ))
1096+ }
1097+ result ["allowlisted_http_vcns" ] = allowlistedHttpVcns
9411098 default :
9421099 log .Printf ("[WARN] Received 'network_endpoint_type' of unknown type %v" , * obj )
9431100 return nil
@@ -1020,6 +1177,42 @@ func VbInstanceSummaryToMap(obj oci_visual_builder.VbInstanceSummary) map[string
10201177 return result
10211178}
10221179
1180+ func (s * VisualBuilderVbInstanceResourceCrud ) mapToVirtualCloudNetwork (fieldKeyFormat string ) (oci_visual_builder.VirtualCloudNetwork , error ) {
1181+ result := oci_visual_builder.VirtualCloudNetwork {}
1182+
1183+ if allowlistedIpCidrs , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "allowlisted_ip_cidrs" )); ok {
1184+ interfaces := allowlistedIpCidrs .([]interface {})
1185+ tmp := make ([]string , len (interfaces ))
1186+ for i := range interfaces {
1187+ if interfaces [i ] != nil {
1188+ tmp [i ] = interfaces [i ].(string )
1189+ }
1190+ }
1191+ if len (tmp ) != 0 || s .D .HasChange (fmt .Sprintf (fieldKeyFormat , "allowlisted_ip_cidrs" )) {
1192+ result .AllowlistedIpCidrs = tmp
1193+ }
1194+ }
1195+
1196+ if id , ok := s .D .GetOkExists (fmt .Sprintf (fieldKeyFormat , "id" )); ok {
1197+ tmp := id .(string )
1198+ result .Id = & tmp
1199+ }
1200+
1201+ return result , nil
1202+ }
1203+
1204+ func VirtualCloudNetworkToMap (obj oci_visual_builder.VirtualCloudNetwork ) map [string ]interface {} {
1205+ result := map [string ]interface {}{}
1206+
1207+ result ["allowlisted_ip_cidrs" ] = obj .AllowlistedIpCidrs
1208+
1209+ if obj .Id != nil {
1210+ result ["id" ] = string (* obj .Id )
1211+ }
1212+
1213+ return result
1214+ }
1215+
10231216func (s * VisualBuilderVbInstanceResourceCrud ) updateCompartment (compartment interface {}) error {
10241217 changeCompartmentRequest := oci_visual_builder.ChangeVbInstanceCompartmentRequest {}
10251218
0 commit comments