Skip to content

Commit

Permalink
fix: fixed bug in the logic to determine the cluster ACL deny rule in…
Browse files Browse the repository at this point in the history
… the roks-ingress submodule (#264)
  • Loading branch information
Vipin654 authored Jan 31, 2025
1 parent 1c317c2 commit f55207e
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 11 deletions.
5 changes: 4 additions & 1 deletion modules/roks-ingress/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ locals {
})

# Pick the first "Deny all" rule in the ACL to place new rules before that
cluster_acl_deny_rule = [for rule in data.ibm_is_network_acl_rules.alb_acl_rules.rules : rule.rule_id if rule.action == "deny"][0]
cluster_acl_deny_rule = length([for rule in data.ibm_is_network_acl_rules.alb_acl_rules.rules : rule.rule_id if rule.action == "deny"]) > 0 ? [for rule in data.ibm_is_network_acl_rules.alb_acl_rules.rules : rule.rule_id if rule.action == "deny"][0] : null


}

data "ibm_container_nlb_dns" "cluster_nlb_dns" {
Expand Down Expand Up @@ -221,6 +223,7 @@ resource "ibm_is_network_acl_rule" "alb_https_req" {
ignore_changes = [before]
}
}

resource "ibm_is_network_acl_rule" "alb_https_resp" {
count = var.cluster_zone_count
network_acl = data.ibm_is_network_acl.alb_acl.id
Expand Down
1 change: 1 addition & 0 deletions modules/roks-ingress/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
output "cluster_workload_ingress_subdomain" {
description = "Public ingress subdomain"
value = local.ingress_subdomain

}

output "cluster_workload_ingress_controller" {
Expand Down
5 changes: 4 additions & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.22.4
toolchain go1.23.4

require (
github.com/IBM/go-sdk-core v1.1.0
github.com/gruntwork-io/terratest v0.48.1
github.com/stretchr/testify v1.10.0
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.42.10
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.45.0
)

require (
Expand All @@ -29,6 +30,7 @@ require (
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
Expand Down Expand Up @@ -95,6 +97,7 @@ require (
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 12 additions & 2 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJl
github.com/IBM-Cloud/power-go-client v1.9.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM/cloud-databases-go-sdk v0.7.1 h1:5kK4/3NUsGxZzmuUe+1ftajpOQbeDVh5VeemrPgROP4=
github.com/IBM/cloud-databases-go-sdk v0.7.1/go.mod h1:JYucI1PdwqbAd8XGdDAchxzxRP7bxOh1zUnseovHKsc=
github.com/IBM/go-sdk-core v1.1.0 h1:pV73lZqr9r1xKb3h08c1uNG3AphwoV5KzUzhS+pfEqY=
github.com/IBM/go-sdk-core v1.1.0/go.mod h1:2pcx9YWsIsZ3I7kH+1amiAkXvLTZtAq9kbxsfXilSoY=
github.com/IBM/go-sdk-core/v5 v5.9.2/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.18.5 h1:g0JRl3sYXJczB/yuDlrN6x22LJ6jIxhp0Sa4ARNW60c=
github.com/IBM/go-sdk-core/v5 v5.18.5/go.mod h1:KonTFRR+8ZSgw5cxBSYo6E4WZoY1+7n1kfHM82VcjFU=
Expand Down Expand Up @@ -48,6 +50,8 @@ github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGL
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/elazarl/goproxy v1.2.3 h1:xwIyKHbaP5yfT6O9KIeYJR5549MXRQkoQMRXGztz8YQ=
github.com/elazarl/goproxy v1.2.3/go.mod h1:YfEbZtqP4AetfO6d40vWchF3znWX7C7Vd6ZMfdL8z64=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
Expand Down Expand Up @@ -106,9 +110,11 @@ github.com/go-openapi/validate v0.22.4 h1:5v3jmMyIPKTR8Lv9syBAIRxG6lY0RqeBPB1LKE
github.com/go-openapi/validate v0.22.4/go.mod h1:qm6O8ZIcPVdSY5219468Jv7kBdGvkiZLPOmqnqTUZ2A=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
Expand Down Expand Up @@ -192,6 +198,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
Expand Down Expand Up @@ -294,8 +301,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.42.10 h1:nyPAuFwSJhp157NBJNZfdpVycOjJa/xGz6qX1V0532c=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.42.10/go.mod h1:RpHvmlmqbmry1YvwWsx90rlirNe4KZ8o8GmntjKViJA=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.45.0 h1:jbKoB7MbiTUnXKB0JXBw67Eo/AnvcIEjUFNDZbtq5Iw=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.45.0/go.mod h1:RpHvmlmqbmry1YvwWsx90rlirNe4KZ8o8GmntjKViJA=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmccombs/hcl2json v0.6.4 h1:/FWnzS9JCuyZ4MNwrG4vMrFrzRgsWEOVi+1AyYUVLGw=
github.com/tmccombs/hcl2json v0.6.4/go.mod h1:+ppKlIW3H5nsAsZddXPy2iMyvld3SHxyjswOZhavRDk=
Expand Down Expand Up @@ -506,7 +513,10 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M=
gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
Expand Down
22 changes: 15 additions & 7 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"testing"

"github.com/IBM/go-sdk-core/core"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/random"
Expand Down Expand Up @@ -45,8 +46,9 @@ func TestMain(m *testing.M) {

func setupOptions(t *testing.T, prefix string, existingTerraformOptions *terraform.Options) *testhelper.TestOptions {
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
Testing: t,
TerraformDir: bankingSolutionsDir,
Testing: t,
TerraformDir: bankingSolutionsDir,
ApiDataIsSensitive: core.BoolPtr(false),
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
ImplicitRequired: false,
Region: region,
Expand Down Expand Up @@ -75,6 +77,7 @@ func setupOptions(t *testing.T, prefix string, existingTerraformOptions *terrafo
"create_secrets": false,
},
})

return options
}

Expand All @@ -98,14 +101,14 @@ func TestRunBankingSolutions(t *testing.T) {
existingTerraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: tempTerraformDir,
Vars: map[string]interface{}{
"prefix": prefix,
"region": region,
"prefix": prefix,
"region": region,
"create_ocp_cluster": true,
},
// Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
// This is the same as setting the -upgrade=true flag with terraform.
Upgrade: true,
})

terraform.WorkspaceSelectOrNew(t, existingTerraformOptions, prefix)
_, existErr := terraform.InitAndApplyE(t, existingTerraformOptions)
if existErr != nil {
Expand All @@ -116,6 +119,8 @@ func TestRunBankingSolutions(t *testing.T) {
// ------------------------------------------------------------------------------------
options := setupOptions(t, prefix, existingTerraformOptions)

options.TerraformVars["cluster_name"] = terraform.Output(t, existingTerraformOptions, "cluster_name")

output, err := options.RunTest()
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
Expand Down Expand Up @@ -151,8 +156,9 @@ func TestRunUpgradeExample(t *testing.T) {
existingTerraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: tempTerraformDir,
Vars: map[string]interface{}{
"prefix": prefix,
"region": region,
"prefix": prefix,
"region": region,
"create_ocp_cluster": true,
},
// Set Upgrade to true to ensure latest version of providers and modules are used by terratest.
// This is the same as setting the -upgrade=true flag with terraform.
Expand All @@ -169,6 +175,8 @@ func TestRunUpgradeExample(t *testing.T) {
// ------------------------------------------------------------------------------------
options := setupOptions(t, prefix, existingTerraformOptions)

options.TerraformVars["cluster_name"] = terraform.Output(t, existingTerraformOptions, "cluster_name")

options.IgnoreDestroys = testhelper.Exemptions{
List: []string{
"module.configure_discovery_project[0].null_resource.discovery_file_upload",
Expand Down
78 changes: 78 additions & 0 deletions tests/resources/existing-resources/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
locals {

signing_key_payload = sensitive("secret-signing-key-payload")
cluster_vpc_subnets = {
default = [
{
id = var.create_ocp_cluster ? ibm_is_subnet.subnet_zone_1[0].id : null
cidr_block = var.create_ocp_cluster ? ibm_is_subnet.subnet_zone_1[0].ipv4_cidr_block : null
zone = var.create_ocp_cluster ? ibm_is_subnet.subnet_zone_1[0].zone : null
}
]
}

worker_pools = [
{
subnet_prefix = "default"
pool_name = "default" # ibm_container_vpc_cluster automatically names default pool "default" (See https://github.com/IBM-Cloud/terraform-provider-ibm/issues/2849)
machine_type = "bx2.4x16"
workers_per_zone = 2 # minimum of 2 is allowed when using single zone
operating_system = "REDHAT_8_64"
}
]
}

########################################################################################################################
Expand Down Expand Up @@ -102,3 +122,61 @@ resource "ibm_cd_toolchain_tool_pipeline" "cd_toolchain_tool_pipeline_instance"
resource "ibm_cd_tekton_pipeline" "cd_tekton_pipeline_instance" {
pipeline_id = ibm_cd_toolchain_tool_pipeline.cd_toolchain_tool_pipeline_instance.tool_id
}



########################################################################################################################
# VPC + Subnet + Public Gateway
#
# NOTE: This is a very simple VPC with single subnet in a single zone with a public gateway enabled, that will allow
# all traffic ingress/egress by default.
# For production use cases this would need to be enhanced by adding more subnets and zones for resiliency, and
# ACLs/Security Groups for network security.
########################################################################################################################

resource "ibm_is_vpc" "vpc" {
count = var.create_ocp_cluster ? 1 : 0
name = "${var.prefix}-vpc"
resource_group = module.resource_group.resource_group_id
address_prefix_management = "auto"
tags = []
}

resource "ibm_is_public_gateway" "gateway" {
count = var.create_ocp_cluster ? 1 : 0
name = "${var.prefix}-gateway-1"
vpc = ibm_is_vpc.vpc[0].id
resource_group = module.resource_group.resource_group_id
zone = "${var.region}-1"
}

resource "ibm_is_subnet" "subnet_zone_1" {
count = var.create_ocp_cluster ? 1 : 0
name = "${var.prefix}-subnet-1"
vpc = ibm_is_vpc.vpc[0].id
resource_group = module.resource_group.resource_group_id
zone = "${var.region}-1"
total_ipv4_address_count = 256
public_gateway = ibm_is_public_gateway.gateway[0].id
}


module "ocp_base" {

count = var.create_ocp_cluster ? 1 : 0
source = "terraform-ibm-modules/base-ocp-vpc/ibm"
version = "3.35.10"
resource_group_id = module.resource_group.resource_group_id
region = var.region
tags = []
cluster_name = var.prefix
force_delete_storage = true
vpc_id = ibm_is_vpc.vpc[0].id
vpc_subnets = local.cluster_vpc_subnets
ocp_version = null
worker_pools = local.worker_pools
access_tags = []
ocp_entitlement = null
disable_outbound_traffic_protection = true # set as True to enable outbound traffic; required for accessing Operator Hub in the OpenShift console.
import_default_worker_pool_on_create = false
}
5 changes: 5 additions & 0 deletions tests/resources/existing-resources/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ output "signing_key" {
sensitive = true
description = "Signing key payload."
}

output "cluster_name" {
value = var.create_ocp_cluster ? module.ocp_base[0].cluster_name : null
description = "The name of the provisioned cluster."
}
7 changes: 7 additions & 0 deletions tests/resources/existing-resources/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ variable "region" {
description = "Region where resources are deployed"
type = string
}

variable "create_ocp_cluster" {

description = "Openshift cluster for deployment of sample rag app"
type = bool
default = false
}

0 comments on commit f55207e

Please sign in to comment.