Skip to content

Commit 7f530b5

Browse files
Sandeep-ManiMaxrovr
authored andcommitted
Added - Support for public network access control.
1 parent 7091103 commit 7f530b5

File tree

7 files changed

+645
-38
lines changed

7 files changed

+645
-38
lines changed

examples/visual_builder/main.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ resource "oci_visual_builder_vb_instance" "test_vb_instance" {
5858
freeform_tags = {
5959
"bar-key" = "value"
6060
}
61-
6261
}
6362

6463
data "oci_visual_builder_vb_instances" "test_vb_instances" {
@@ -83,4 +82,4 @@ data "oci_visual_builder_vb_instance_applications" "test_vb_instance_application
8382
#Required
8483
vb_instance_id = oci_visual_builder_vb_instance.test_vb_instance.id
8584
idcs_open_id = var.idcs_open_id
86-
}
85+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
variable "tenancy_ocid" {
5+
}
6+
7+
variable "user_ocid" {
8+
}
9+
10+
variable "fingerprint" {
11+
}
12+
13+
variable "private_key_path" {
14+
}
15+
16+
variable "region" {
17+
}
18+
19+
variable "compartment_id" {
20+
}
21+
22+
variable "idcs_open_id" {
23+
}
24+
25+
variable "vb_instance_consumption_model" {
26+
default = "UCM"
27+
}
28+
29+
variable "custom_endpoint_certificate_secret_id" {
30+
}
31+
32+
variable "vb_instance_network_endpoint_details_allowlisted_http_ips" {
33+
default = ["0.0.0.0/32"]
34+
}
35+
36+
variable "vb_instance_network_endpoint_details_allowlisted_http_vcns_allowlisted_ip_cidrs" {
37+
default = []
38+
}
39+
40+
variable "vb_instance_network_endpoint_details_allowlisted_http_vcns_id" {
41+
default = "id"
42+
}
43+
44+
variable "vb_instance_network_endpoint_details_network_endpoint_type" {
45+
default = "PUBLIC"
46+
}
47+
48+
provider "oci" {
49+
tenancy_ocid = var.tenancy_ocid
50+
user_ocid = var.user_ocid
51+
fingerprint = var.fingerprint
52+
private_key_path = var.private_key_path
53+
region = var.region
54+
}
55+
56+
resource "oci_visual_builder_vb_instance" "test_vb_instance_acl" {
57+
#Required
58+
compartment_id = var.compartment_id
59+
display_name = "displayName"
60+
is_visual_builder_enabled = "true"
61+
idcs_open_id = var.idcs_open_id
62+
node_count = "1"
63+
64+
#Optional
65+
consumption_model = var.vb_instance_consumption_model
66+
#Optional
67+
network_endpoint_details {
68+
#Required
69+
network_endpoint_type = var.vb_instance_network_endpoint_details_network_endpoint_type
70+
71+
#Optional
72+
allowlisted_http_ips = var.vb_instance_network_endpoint_details_allowlisted_http_ips
73+
allowlisted_http_vcns {
74+
#Required
75+
id = var.vb_instance_network_endpoint_details_allowlisted_http_vcns_id
76+
77+
#Optional
78+
allowlisted_ip_cidrs = var.vb_instance_network_endpoint_details_allowlisted_http_vcns_allowlisted_ip_cidrs
79+
}
80+
}
81+
}
82+
83+
data "oci_visual_builder_vb_instances" "test_vb_instances_acl" {
84+
#Required
85+
compartment_id = var.compartment_id
86+
87+
#Optional
88+
display_name = "displayName"
89+
state = "Active"
90+
filter {
91+
name = "id"
92+
values = [oci_visual_builder_vb_instance.test_vb_instance_acl.id]
93+
}
94+
}
95+
96+
data "oci_visual_builder_vb_instance" "test_vb_instance_acl" {
97+
#Required
98+
vb_instance_id = oci_visual_builder_vb_instance.test_vb_instance_acl.id
99+
}
100+
101+
data "oci_visual_builder_vb_instance_applications" "test_vb_instance_applications" {
102+
#Required
103+
vb_instance_id = oci_visual_builder_vb_instance.test_vb_instance_acl.id
104+
idcs_open_id = var.idcs_open_id
105+
}

internal/integrationtest/visual_builder_vb_instance_test.go

Lines changed: 261 additions & 25 deletions
Large diffs are not rendered by default.

internal/service/visual_builder/visual_builder_vb_instance_resource.go

Lines changed: 197 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10231216
func (s *VisualBuilderVbInstanceResourceCrud) updateCompartment(compartment interface{}) error {
10241217
changeCompartmentRequest := oci_visual_builder.ChangeVbInstanceCompartmentRequest{}
10251218

0 commit comments

Comments
 (0)