-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
185 lines (165 loc) · 6.4 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
################################################################
# Copyright 2023 - IBM Corporation. All rights reserved
# SPDX-License-Identifier: Apache-2.0
################################################################
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = var.vpc_region
zone = var.vpc_zone
alias = "vpc"
}
provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = module.vpc.powervs_region
zone = module.vpc.powervs_zone
alias = "powervs"
}
# Create a random_id label
# Since we use the hex, the word length would double
resource "random_id" "label" {
count = 1
byte_length = "2"
}
locals {
cluster_id = var.cluster_id == "" ? random_id.label[0].hex : (var.cluster_id_prefix == "" ? var.cluster_id : "${var.cluster_id_prefix}-${var.cluster_id}")
# Generates vm_id as combination of vm_id_prefix + (random_id or user-defined vm_id)
name_prefix = var.name_prefix == "" ? "mac-${random_id.label[0].hex}" : "${var.name_prefix}"
node_prefix = var.use_zone_info_for_names ? "${var.powervs_zone}-" : ""
vpc_name = var.vpc_create ? "${local.name_prefix}-vpc" : var.vpc_name
}
### Prepares the VPC Support Machine
module "vpc" {
providers = {
ibm = ibm.vpc
}
source = "./modules/0_vpc"
ibmcloud_api_key = var.ibmcloud_api_key
vpc_create = var.vpc_create
vpc_name = local.vpc_name
vpc_region = var.vpc_region
vpc_zone = var.vpc_zone
vpc_resource_group = var.vpc_resource_group
powervs_region = var.powervs_region
powervs_zone = var.powervs_zone
override_region_check = var.override_region_check
name_prefix = local.name_prefix
}
### Prepares the VPC
module "vpc_prepare" {
providers = {
ibm = ibm.vpc
}
depends_on = [module.vpc]
source = "./modules/1_vpc_prepare"
private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
connection_timeout = var.connection_timeout
rhel_username = var.rhel_username
bastion_public_ip = var.powervs_bastion_ip
vpc_create = var.vpc_create
vpc_name = local.vpc_name
vpc_region = var.vpc_region
vpc_zone = var.vpc_zone
vpc_skip_ssh_key_create = var.vpc_skip_ssh_key_create
name_prefix = local.name_prefix
resource_group = module.vpc.vpc_resource_group
public_key = var.public_key
public_key_file = var.public_key_file
powervs_machine_cidr = var.powervs_machine_cidr
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
create_custom_subnet = var.create_custom_subnet
skip_create_security_group = var.skip_create_security_group
skip_route_creation = var.skip_route_creation
}
### Prepares the VPC gateway
module "vpc_gateway" {
depends_on = [module.vpc]
source = "./modules/1_vpc_gateway"
ibmcloud_api_key = var.ibmcloud_api_key
vpc_region = var.vpc_region
resource_group_name = module.vpc.vpc_resource_group_name
vpc_name = local.vpc_name
vpc_create_public_gateways = var.vpc_create_public_gateways
private_key_file = var.private_key_file
rhel_username = var.rhel_username
bastion_public_ip = var.powervs_bastion_ip
ssh_agent = var.ssh_agent
connection_timeout = var.connection_timeout
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
}
module "support" {
providers = {
ibm = ibm.powervs
}
depends_on = [module.vpc_gateway]
source = "./modules/4_pvs_support"
private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
connection_timeout = var.connection_timeout
rhel_username = var.rhel_username
bastion_public_ip = var.powervs_bastion_ip
cidrs = module.vpc_prepare.mac_vpc_subnets
powervs_machine_cidr = var.powervs_machine_cidr
ibmcloud_api_key = var.ibmcloud_api_key
vpc_name = local.vpc_name
vpc_region = var.vpc_region
resource_group = module.vpc.vpc_resource_group
ignition_ip = var.powervs_bastion_private_ip
}
module "image" {
providers = {
ibm = ibm.vpc
}
depends_on = [module.support]
source = "./modules/5_image"
name_prefix = local.name_prefix
vpc_region = var.vpc_region
rhel_username = var.rhel_username
bastion_public_ip = var.powervs_bastion_ip
private_key_file = var.private_key_file
ssh_agent = var.ssh_agent
connection_timeout = var.connection_timeout
ibmcloud_api_key = var.ibmcloud_api_key
resource_group_name = module.vpc.vpc_resource_group_name
skip_authorization_policy_create = var.skip_authorization_policy_create
}
module "worker" {
providers = {
ibm = ibm.vpc
}
depends_on = [module.image]
source = "./modules/6_worker"
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
name_prefix = local.name_prefix
rhcos_image_id = module.image.rhcos_image_id
vpc_name = local.vpc_name
vpc_key_id = module.vpc_prepare.vpc_key_id
ignition_ip = var.powervs_bastion_private_ip
target_worker_sg_id = module.vpc_prepare.target_worker_sg_id
create_custom_subnet = var.create_custom_subnet
}
module "post" {
depends_on = [module.worker]
source = "./modules/7_post"
ssh_agent = var.ssh_agent
rhel_username = var.rhel_username
connection_timeout = var.connection_timeout
bastion_public_ip = var.powervs_bastion_ip
private_key_file = var.private_key_file
vpc_region = var.vpc_region
vpc_name = local.vpc_name
vpc_zone = var.vpc_zone
ibmcloud_api_key = var.ibmcloud_api_key
resource_group_name = module.vpc.vpc_resource_group_name
name_prefix = local.name_prefix
worker_1 = var.worker_1
worker_2 = var.worker_2
worker_3 = var.worker_3
cicd_image_pruner_cleanup = var.cicd_image_pruner_cleanup
}