Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit b62c72e

Browse files
author
Sean Sundberg
authored
Updates to interface (#6)
* Updates ocp-vpc module to use the output of the subnet module * Adds security group rule for kube Signed-off-by: Sean Sundberg <[email protected]>
1 parent 28540cb commit b62c72e

File tree

14 files changed

+145
-48
lines changed

14 files changed

+145
-48
lines changed

.github/workflows/verify.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717

1818
strategy:
1919
matrix:
20-
platform: [ocp4vpc_latest]
21-
# max-parallel: 1
20+
platform:
21+
- vpc_count
2222
fail-fast: false
2323

2424
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea/
2+
*.iml

main-2-config.tf

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
provider "helm" {
2-
version = ">= 1.1.1"
3-
4-
kubernetes {
5-
config_path = local.cluster_config
6-
}
7-
}
81

92
locals {
103
gitops_dir = var.gitops_dir != "" ? var.gitops_dir : "${path.cwd}/gitops"
@@ -51,7 +44,7 @@ resource "null_resource" "list_tmp" {
5144
}
5245

5346
data ibm_container_cluster_config cluster_admin {
54-
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.list_tmp]
47+
depends_on = [data.ibm_container_vpc_cluster.config, null_resource.list_tmp]
5548

5649
cluster_name_id = local.cluster_name
5750
admin = true
@@ -61,7 +54,7 @@ data ibm_container_cluster_config cluster_admin {
6154

6255
data ibm_container_cluster_config cluster {
6356
depends_on = [
64-
ibm_container_vpc_cluster.cluster,
57+
data.ibm_container_vpc_cluster.config,
6558
null_resource.list_tmp,
6659
data.ibm_container_cluster_config.cluster_admin
6760
]
@@ -72,7 +65,7 @@ data ibm_container_cluster_config cluster {
7265
}
7366

7467
resource null_resource setup_kube_config {
75-
depends_on = [null_resource.create_dirs]
68+
depends_on = [null_resource.create_dirs, data.ibm_container_cluster_config.cluster]
7669

7770
provisioner "local-exec" {
7871
command = "rm -f ${local.cluster_config} && ln -s ${data.ibm_container_cluster_config.cluster.config_file_path} ${local.cluster_config}"

main.tf

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
provider "ibm" {
2-
region = var.region
3-
generation = 2
4-
ibmcloud_api_key = var.ibmcloud_api_key
5-
}
61

72
locals {
83
config_values = {
@@ -45,9 +40,11 @@ locals {
4540
cluster_type_tag = local.cluster_type == "kubernetes" ? "iks" : "ocp"
4641
cluster_version = local.cluster_type == "openshift" ? local.openshift_versions[local.config_values[local.cluster_type_cleaned].version] : ""
4742
ibmcloud_release_name = "ibmcloud-config"
48-
cos_location = "global"
43+
vpc_subnet_count = var.vpc_subnet_count
4944
vpc_id = !var.exists ? data.ibm_is_vpc.vpc[0].id : ""
50-
vpc_subnets = !var.exists ? data.ibm_is_vpc.vpc[0].subnets : []
45+
vpc_subnets = !var.exists ? var.vpc_subnets : []
46+
security_group_id = !var.exists ? data.ibm_is_vpc.vpc[0].default_security_group : ""
47+
ipv4_cidr_blocks = !var.exists ? data.ibm_is_subnet.vpc_subnet[*].ipv4_cidr_block : []
5148
}
5249

5350
resource null_resource create_dirs {
@@ -67,7 +64,30 @@ resource null_resource create_dirs {
6764
}
6865
}
6966

67+
resource null_resource print_resources {
68+
provisioner "local-exec" {
69+
command = "echo 'Resource group: ${var.resource_group_name}'"
70+
}
71+
provisioner "local-exec" {
72+
command = "echo 'Cos id: ${var.cos_id}'"
73+
}
74+
provisioner "local-exec" {
75+
command = "echo 'VPC name: ${var.vpc_name}'"
76+
}
77+
}
78+
79+
resource null_resource print_subnets {
80+
provisioner "local-exec" {
81+
command = "echo 'VPC subnet count: ${local.vpc_subnet_count}'"
82+
}
83+
provisioner "local-exec" {
84+
command = "echo 'VPC subnets: ${jsonencode(local.vpc_subnets)}'"
85+
}
86+
}
87+
7088
data ibm_resource_group resource_group {
89+
depends_on = [null_resource.print_resources]
90+
7191
name = var.resource_group_name
7292
}
7393

@@ -77,23 +97,22 @@ data ibm_container_cluster_versions cluster_versions {
7797
resource_group_id = data.ibm_resource_group.resource_group.id
7898
}
7999

80-
resource null_resource print-vpc_name {
81-
depends_on = [null_resource.create_dirs]
82-
83-
provisioner "local-exec" {
84-
command = "echo 'VPC name: ${var.vpc_name}'"
85-
}
86-
}
87-
88100
data ibm_is_vpc vpc {
89101
count = !var.exists ? 1 : 0
90-
depends_on = [null_resource.print-vpc_name]
102+
depends_on = [null_resource.print_resources]
91103

92104
name = var.vpc_name
93105
}
94106

107+
data ibm_is_subnet vpc_subnet {
108+
count = !var.exists ? var.vpc_subnet_count : 0
109+
110+
identifier = local.vpc_subnets[count.index].id
111+
}
112+
95113
resource ibm_container_vpc_cluster cluster {
96114
count = !var.exists ? 1 : 0
115+
depends_on = [null_resource.print_resources]
97116

98117
name = local.cluster_name
99118
vpc_id = local.vpc_id
@@ -113,7 +132,7 @@ resource ibm_container_vpc_cluster cluster {
113132
}
114133

115134
resource ibm_container_vpc_worker_pool cluster_pool {
116-
count = !var.exists ? var.vpc_subnet_count - 1 : 0
135+
count = !var.exists ? local.vpc_subnet_count - 1 : 0
117136

118137
cluster = ibm_container_vpc_cluster.cluster[0].id
119138
worker_pool_name = "${local.cluster_name}-wp-${format("%02s", count.index + 1)}"
@@ -128,8 +147,21 @@ resource ibm_container_vpc_worker_pool cluster_pool {
128147
}
129148
}
130149

150+
resource ibm_is_security_group_rule rule_tcp_k8s {
151+
count = !var.exists ? local.vpc_subnet_count : 0
152+
153+
group = local.security_group_id
154+
direction = "inbound"
155+
remote = local.ipv4_cidr_blocks[count.index]
156+
157+
tcp {
158+
port_min = 30000
159+
port_max = 32767
160+
}
161+
}
162+
131163
data ibm_container_vpc_cluster config {
132-
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.create_dirs]
164+
depends_on = [ibm_container_vpc_cluster.cluster, null_resource.create_dirs, ibm_is_security_group_rule.rule_tcp_k8s]
133165

134166
name = local.cluster_name
135167
alb_type = "public"

module.yaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ description: Provisions an IBM Cloud OCP cluster
55
tags:
66
- ocp
77
- cluster
8+
- vpc
89
versions:
910
- platforms:
1011
- ocp4
1112
dependencies:
13+
- id: resource-group
14+
refs:
15+
- source: github.com/cloud-native-toolkit/terraform-ibm-resource-group
16+
version: ">= 1.0.0"
1217
- id: cos
1318
refs:
1419
- source: github.com/cloud-native-toolkit/terraform-ibm-object-storage
@@ -17,23 +22,33 @@ versions:
1722
refs:
1823
- source: github.com/cloud-native-toolkit/terraform-ibm-vpc
1924
version: ">= 1.0.0"
25+
- id: subnets
26+
refs:
27+
- source: github.com/cloud-native-toolkit/terraform-ibm-vpc-subnets
28+
version: ">= 1.0.0"
2029
variables:
30+
- name: resource_group_name
31+
moduleRef:
32+
id: resource-group
33+
output: name
2134
- name: vpc_name
2235
moduleRef:
2336
id: vpc
2437
output: name
2538
- name: vpc_subnet_count
2639
moduleRef:
2740
id: vpc
28-
output: subnet_count
41+
output: count
42+
- name: vpc_subnets
43+
moduleRef:
44+
id: subnets
45+
output: subnets
2946
- name: cos_id
3047
moduleRef:
3148
id: cos
3249
output: id
3350
- name: name_prefix
3451
scope: global
35-
- name: resource_group_name
36-
scope: global
3752
- name: region
3853
scope: global
3954
- name: ibmcloud_api_key

provider.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
provider "ibm" {
2+
region = var.region
3+
generation = 2
4+
ibmcloud_api_key = var.ibmcloud_api_key
5+
}
6+
7+
provider "helm" {
8+
version = ">= 1.1.1"
9+
10+
kubernetes {
11+
config_path = local.cluster_config
12+
}
13+
}

test/stages/stage1-cos.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module "cos" {
22
source = "github.com/cloud-native-toolkit/terraform-ibm-object-storage"
33

44
provision = true
5-
resource_group_name = var.resource_group_name
5+
resource_group_name = module.resource_group.name
66
name_prefix = var.name_prefix
77
}

test/stages/stage1-gateways.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module "gateways" {
2+
source = "github.com/cloud-native-toolkit/terraform-ibm-vpc-gateways.git"
3+
4+
resource_group_id = module.resource_group.id
5+
region = var.region
6+
ibmcloud_api_key = var.ibmcloud_api_key
7+
vpc_name = module.vpc.name
8+
subnet_count = var.vpc_subnet_count
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module "resource_group" {
2+
source = "github.com/cloud-native-toolkit/terraform-ibm-resource-group.git"
3+
4+
resource_group_name = var.resource_group_name
5+
provision = false
6+
}

test/stages/stage1-subnets.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module "subnets" {
2+
source = "github.com/cloud-native-toolkit/terraform-ibm-vpc-subnets.git"
3+
4+
resource_group_id = module.resource_group.id
5+
region = var.region
6+
ibmcloud_api_key = var.ibmcloud_api_key
7+
vpc_name = module.vpc.name
8+
acl_id = module.vpc.acl_id
9+
gateways = module.gateways.gateways
10+
_count = 2
11+
label = "bastion"
12+
}

0 commit comments

Comments
 (0)