Skip to content

Commit 6a7f6a3

Browse files
committed
Updating rules
1 parent 372e2ce commit 6a7f6a3

File tree

7 files changed

+93
-28
lines changed

7 files changed

+93
-28
lines changed

feature_store/apigw_terraform/main.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ resource "random_string" "suffix" {
88
}
99

1010
locals {
11-
compartment_id = data.oci_network_load_balancer_network_load_balancer.nlb.compartment_id
11+
compartment_id = var.use_nlb_compartment?data.oci_network_load_balancer_network_load_balancer.nlb.compartment_id:var.compartment_id
1212
}
1313

14-
1514
data oci_network_load_balancer_network_load_balancer nlb {
1615
network_load_balancer_id = var.nlb_id
1716
}
1817

1918
module "feature_store_gw_subnet" {
2019
source = "./modules/subnet"
2120
kubernetes_nlb_id = var.nlb_id
21+
compartment_id = local.compartment_id
2222
subnet_name = "fs-gw-subnet"
23+
existing_subnet_id = var.api_gw_subnet_id
24+
use_existing_subnet = !var.automatically_provision_apigw_subnet
25+
create_security_rules = var.create_security_rules
2326
}
2427

2528
module "function" {
@@ -29,7 +32,6 @@ module "function" {
2932
ocir_path = var.function_img_ocir_url
3033
subnet_id = module.feature_store_gw_subnet.subnet_id
3134
name_suffix = random_string.suffix.id
32-
3335
}
3436

3537
module "api_gw" {

feature_store/apigw_terraform/modules/api_gw/main.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ locals {
66
# we are doing it like this because of issues in escaping ${ character
77
path_str = format("%s%s","$","{request.path[")
88
path_map = {for path,methods in local.unique_paths: path=>replace(replace(tostring(path), "{", local.path_str),"}", "]}")}
9-
policies = ["allow any-user to use functions-family in tenancy where ALL {request.principal.type='ApiGateway'}"]
9+
policies = ["allow any-user to use functions-family in compartment ${data.oci_identity_compartment.compartment1.name} where ALL {request.principal.type='ApiGateway'}"]
1010

1111
}
1212

13+
data "oci_identity_compartment" "compartment1" {
14+
id = var.compartment_id
15+
}
16+
1317
resource oci_apigateway_api specs {
1418
display_name = "Feature Store API spec"
1519
compartment_id = var.compartment_id
@@ -46,7 +50,9 @@ data "oci_network_load_balancer_network_load_balancer" "nlb"{
4650
}
4751

4852
resource oci_apigateway_deployment fs_deployment {
53+
display_name="Feature store api deployment"
4954
compartment_id = var.compartment_id
55+
5056
gateway_id = oci_apigateway_gateway.fs_gateway.id
5157
path_prefix = "/20230101"
5258
specification {

feature_store/apigw_terraform/modules/function/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ locals {
33
policies = ["allow dynamic-group ${oci_identity_dynamic_group.functions_dg.name} to {AUTHENTICATION_INSPECT,GROUP_MEMBERSHIP_INSPECT} in tenancy"]
44
}
55

6+
data "oci_identity_compartment" "compartment" {
7+
id = var.compartment_id
8+
}
69

710

811
resource "oci_identity_dynamic_group" "functions_dg" {
9-
compartment_id = var.compartment_id
12+
compartment_id = "ocid1.tenancy.oc1..aaaaaaaa462hfhplpx652b32ix62xrdijppq2c7okwcqjlgrbknhgtj2kofa"
1013
description = "FEATURESTORE: Allow Oci functions to inspect identity"
1114
matching_rule = "All {resource.type = 'fnfunc', resource.id = '${oci_functions_function.test_function.id}'}"
1215
name = "Feature_Store_Authorizer_${var.name_suffix}"

feature_store/apigw_terraform/modules/subnet/inputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,18 @@ variable "kubernetes_nlb_id" {
44
variable "subnet_name" {
55
type = string
66
}
7+
variable "compartment_id" {
8+
type = string
9+
}
10+
11+
variable "existing_subnet_id" {
12+
type = string
13+
}
14+
15+
variable "use_existing_subnet" {
16+
type = bool
17+
}
18+
19+
variable "create_security_rules" {
20+
type = bool
21+
}

feature_store/apigw_terraform/modules/subnet/main.tf

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ locals {
88

99
next_cidr_block = cidrsubnet(local.parent_last_cidr_block, 1, 1)
1010
cidr_block = cidrsubnet(local.next_cidr_block,28-tonumber(local.parent_last_cidr_prefix),0)
11-
compartment_id = data.oci_core_subnet.nlb_subnet.compartment_id
1211
internet_gateway_id = length(data.oci_core_internet_gateways.gateways)>0?data.oci_core_internet_gateways.gateways.gateways[0].id:oci_core_internet_gateway.gateway[0].id
13-
nlb_egress_port = data.oci_network_load_balancer_backend_sets.backend_sets.backend_set_collection[0].items[0].backends[0].port
12+
subnet = var.use_existing_subnet? data.oci_core_subnet.existing_apigw_subnet[0] : oci_core_subnet.subnet[0]
13+
# nlb_egress_port = data.oci_network_load_balancer_backend_sets.backend_sets.backend_set_collection[0].items[0].backends[0].port
14+
}
1415

16+
data "oci_core_subnet" "existing_apigw_subnet" {
17+
count = var.use_existing_subnet?1:0
18+
subnet_id = var.existing_subnet_id
1519
}
1620

1721
data "oci_network_load_balancer_backend_sets" "backend_sets" {
@@ -27,10 +31,10 @@ data "oci_core_subnet" "node_subnet" {
2731
subnet_id = data.oci_core_instance.node_instance.subnet_id
2832
}
2933

30-
3134
data oci_network_load_balancer_network_load_balancer nlb {
3235
network_load_balancer_id = var.kubernetes_nlb_id
3336
}
37+
3438
data oci_core_subnet nlb_subnet {
3539
subnet_id = data.oci_network_load_balancer_network_load_balancer.nlb.subnet_id
3640
}
@@ -48,13 +52,11 @@ data "oci_core_subnet" "subnets_dets" {
4852
subnet_id = "${each.key}"
4953
}
5054

51-
52-
53-
5455
resource "oci_core_subnet" "subnet" {
56+
count = var.use_existing_subnet?0:1
5557
display_name = var.subnet_name
5658
cidr_block = local.cidr_block
57-
compartment_id = local.compartment_id
59+
compartment_id = var.compartment_id
5860
vcn_id = data.oci_core_vcn.nlb_vcn.id
5961
route_table_id = oci_core_route_table.route_table.id
6062
security_list_ids = [oci_core_security_list.security_list_api_gw.id]
@@ -64,20 +66,20 @@ resource "oci_core_subnet" "subnet" {
6466
}
6567

6668
data "oci_core_internet_gateways" "gateways"{
67-
compartment_id = local.compartment_id
69+
compartment_id = var.compartment_id
6870
vcn_id = data.oci_core_vcn.nlb_vcn.id
6971
}
7072

7173
resource "oci_core_internet_gateway" "gateway" {
7274
count = length(data.oci_core_internet_gateways.gateways)>0?0:1
73-
compartment_id = local.compartment_id
75+
compartment_id = var.compartment_id
7476
vcn_id = data.oci_core_vcn.nlb_vcn.id
7577
enabled = true
7678
}
7779

7880
resource "oci_core_route_table" "route_table" {
7981
display_name = format("%s-route-table", var.subnet_name)
80-
compartment_id = local.compartment_id
82+
compartment_id = var.compartment_id
8183
vcn_id = data.oci_core_vcn.nlb_vcn.id
8284
route_rules {
8385
network_entity_id = local.internet_gateway_id
@@ -86,8 +88,7 @@ resource "oci_core_route_table" "route_table" {
8688
}
8789

8890
resource "oci_core_security_list" "security_list_api_gw" {
89-
90-
compartment_id = local.compartment_id
91+
compartment_id = var.compartment_id
9192
vcn_id = data.oci_core_vcn.nlb_vcn.id
9293
display_name = format("%s-sec-rules",var.subnet_name)
9394
egress_security_rules {
@@ -102,24 +103,25 @@ resource "oci_core_security_list" "security_list_api_gw" {
102103
}
103104

104105
resource "oci_core_security_list" "nlb_security_rules" {
106+
count = var.create_security_rules?1:0
105107
freeform_tags = {
106108
"subnet_id": data.oci_core_subnet.nlb_subnet.id
107109
}
108-
compartment_id = local.compartment_id
110+
compartment_id = var.compartment_id
109111
vcn_id = data.oci_core_vcn.nlb_vcn.id
110112
display_name = format("%s-sec-rules",data.oci_core_subnet.nlb_subnet.display_name)
111113
egress_security_rules {
112114
destination = data.oci_core_subnet.node_subnet.cidr_block
113115
destination_type = "CIDR_BLOCK"
114116
protocol = "6"
115117
tcp_options {
116-
max=local.nlb_egress_port
117-
min=local.nlb_egress_port
118+
max=32767
119+
min=30000
118120
}
119121
}
120122
ingress_security_rules {
121123
protocol = "6"
122-
source = oci_core_subnet.subnet.cidr_block
124+
source = local.subnet.cidr_block
123125
tcp_options {
124126
max=80
125127
min=80
@@ -137,27 +139,28 @@ resource "oci_core_security_list" "nlb_security_rules" {
137139
}
138140

139141
resource "oci_core_security_list" "node_security_rules" {
142+
count = var.create_security_rules?1:0
140143
freeform_tags = {
141-
"subnet_id": data.oci_core_subnet.node_subnet.id
144+
"subnet_id": local.subnet.id
142145
}
143-
compartment_id = local.compartment_id
146+
compartment_id = var.compartment_id
144147
vcn_id = data.oci_core_vcn.nlb_vcn.id
145148
display_name = format("%s-sec-rules",data.oci_core_subnet.node_subnet.display_name)
146149
ingress_security_rules {
147150
protocol = "6"
148151
source = data.oci_core_subnet.nlb_subnet.cidr_block
149152
tcp_options {
150-
max=local.nlb_egress_port
151-
min=local.nlb_egress_port
153+
max=32767
154+
min=30000
152155
}
153156
}
154157
egress_security_rules {
155158
destination = data.oci_core_subnet.nlb_subnet.cidr_block
156159
protocol = "6"
157160
tcp_options {
158161
source_port_range {
159-
max = local.nlb_egress_port
160-
min = local.nlb_egress_port
162+
max = 32767
163+
min = 30000
161164
}
162165
}
163166
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
output "subnet_id" {
2-
value = oci_core_subnet.subnet.id
2+
value = local.subnet.id
33
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
11
variable nlb_id {
2+
description = "Network load balancer ocid for the resource created after deploying feature store helm chart "
23
type = string
34
}
45

6+
variable "use_nlb_compartment" {
7+
description = "Uses network load balancer compartment for the stack deployment. If false, compartment id must be provided in 'compartment_id'"
8+
type = bool
9+
default = true
10+
}
11+
12+
variable "automatically_provision_apigw_subnet" {
13+
description = "Creates a new Subnet. If false, the subnet ocid to use for api gateway must be provided"
14+
type = bool
15+
default = true
16+
}
17+
18+
variable "api_gw_subnet_id" {
19+
description = "Subnet Id for api gateway. Leave blank to automatically provision a subnet"
20+
type = string
21+
default = ""
22+
}
23+
524
variable authorized_user_groups {
25+
description = "User group OCIDs authorized to access feature store environment"
626
type = list(string)
727
}
828

929
variable function_img_ocir_url {
30+
description = "OCIR URL of the authorizer image exported from feature store marketplace listing"
1031
type = string
1132
}
1233

1334
variable "tenancy_ocid" {
1435
type = string
36+
description = "OCID of the tenancy where the stack needs to be deployed"
37+
}
38+
39+
variable "compartment_id" {
40+
type = string
41+
description = "OCID of the compartment where the stack needs to be deployed"
42+
default = ""
1543
}
1644

1745
variable "region" {
46+
description = "Region in which the resources are to be provisioned"
1847
type = string
48+
default = "us-ashburn-1"
49+
}
50+
51+
variable "create_security_rules" {
52+
description = "Should we automatically create required security groups for node and load balancer subnet? Note: These need be manually attached to the respective subnets once the stack is provisioned"
53+
type = bool
54+
default = true
1955
}

0 commit comments

Comments
 (0)