Skip to content

Commit e6a838e

Browse files
authored
Merge pull request #7889 from Prajyot-Parab/k8s_power
Add terraform for provisioning power build cluster on ibmcloud
2 parents 0f18a76 + e51498f commit e6a838e

36 files changed

+1484
-0
lines changed

infra/ibmcloud/OWNERS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# See the OWNERS docs at https://go.k8s.io/owners
2+
3+
filters:
4+
".*":
5+
approvers:
6+
- sig-k8s-infra-leads
7+
labels:
8+
- sig/k8s-infra
9+
- area/infra
10+
- area/infra/ibmcloud
11+
"\\.sh$":
12+
labels:
13+
- area/bash
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# _TF: IBM K8s Account Infrastructure_
2+
This Terraform configuration sets up an organized structure for deploying various IBM Cloud resources using modules.
3+
4+
---
5+
# To run the automation, follow these steps in order:
6+
7+
**1. Navigate to the correct directory**
8+
<br> You need to be in the `k8s-infra-setup` directory to run the automation.
9+
10+
**2. Check the `versions.tf` file**
11+
<br> Set `secret_key` and `access_key` in `versions.tf` to configure the remote S3 backend (IBM Cloud COS).
12+
13+
**3. Initialize Terraform**
14+
<br> Execute the following command to initialize Terraform in your project directory. This command will download the necessary provider plugins and prepare the working environment.
15+
```
16+
terraform init -reconfigure
17+
```
18+
19+
**4. Check the `variables.tf` file**
20+
<br> Open the `variables.tf` file to review all the available variables. This file lists all customizable inputs for your Terraform configuration.
21+
22+
`ibmcloud_api_key` is the only required variable that you must set in order to proceed. You can set this key either by adding it to your `var.tfvars` file or by exporting it as an environment variable.
23+
24+
**Option 1:** Set in `var.tfvars` file
25+
Add the following line to the `var.tfvars` file:
26+
```
27+
ibmcloud_api_key = "<YOUR_API_KEY>"
28+
```
29+
30+
**Option 2:** Export as an environment variable
31+
Alternatively, you can export the ibmcloud_api_key as an environment variable before running Terraform:
32+
```
33+
export TF_VAR_ibmcloud_api_key="<YOUR_API_KEY>"
34+
```
35+
36+
**5. Run Terraform Apply**
37+
<br> After setting the necessary variables (particularly the API_KEY), execute the following command to apply the Terraform configuration and provision the infrastructure:
38+
```
39+
terraform apply -var-file var.tfvars
40+
```
41+
Terraform will display a plan of the actions it will take, and you'll be prompted to confirm the execution. Type `yes` to proceed.
42+
43+
**6 .Get Output Information**
44+
<br> Once the infrastructure has been provisioned, use the terraform output command to list details about the provisioned resources.
45+
```
46+
terraform output
47+
```
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
module "resource_group" {
18+
source = "./modules/resource_group"
19+
}
20+
21+
module "secrets_manager" {
22+
source = "./modules/secrets_manager"
23+
resource_group_id = module.resource_group.k8s_rg_id
24+
}
25+
26+
module "vpc" {
27+
providers = {
28+
ibm = ibm.vpc
29+
}
30+
source = "./modules/vpc"
31+
resource_group_id = module.resource_group.k8s_rg_id
32+
}
33+
34+
module "transit_gateway" {
35+
depends_on = [module.vpc]
36+
providers = {
37+
ibm = ibm.vpc
38+
}
39+
source = "./modules/transit_gateway"
40+
resource_group_id = module.resource_group.k8s_rg_id
41+
vpc_crn = module.vpc.crn
42+
powervs_crn = ibm_pi_workspace.build_cluster.crn
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
output "k8s_rg_id" {
18+
value = ibm_resource_group.k8s_rg.id
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
resource "ibm_resource_group" "k8s_rg" {
18+
name = "k8s-project"
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_providers {
19+
ibm = {
20+
source = "IBM-Cloud/ibm"
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
output "k8s_secrets_manager_id" {
18+
value = ibm_resource_instance.secrets_manager.guid
19+
}
20+
21+
output "k8s_powervs_ssh_public_key" {
22+
value = tls_private_key.private_key.public_key_openssh
23+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
locals {
18+
secrets_manager_region = "us-south"
19+
secrets_manager_name = "k8s-secrets-ppc64le"
20+
}
21+
22+
resource "ibm_resource_instance" "secrets_manager" {
23+
name = local.secrets_manager_name
24+
resource_group_id = var.resource_group_id
25+
service = "secrets-manager"
26+
plan = "standard"
27+
location = local.secrets_manager_region
28+
29+
timeouts {
30+
create = "15m"
31+
update = "15m"
32+
delete = "15m"
33+
}
34+
}
35+
36+
# RSA key of size 4096 bits
37+
resource "tls_private_key" "private_key" {
38+
algorithm = "RSA"
39+
rsa_bits = 4096
40+
}
41+
42+
resource "ibm_sm_arbitrary_secret" "ssh_private_key" {
43+
name = "powervs-ssh-private-key"
44+
instance_id = ibm_resource_instance.secrets_manager.guid
45+
region = local.secrets_manager_region
46+
labels = ["powervs-ssh-private-key"]
47+
payload = tls_private_key.private_key.private_key_openssh
48+
}
49+
50+
resource "ibm_sm_arbitrary_secret" "ssh_public_key" {
51+
name = "powervs-ssh-public-key"
52+
instance_id = ibm_resource_instance.secrets_manager.guid
53+
region = local.secrets_manager_region
54+
labels = ["powervs-ssh-public-key"]
55+
payload = tls_private_key.private_key.public_key_openssh
56+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
variable "resource_group_id" {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
terraform {
18+
required_providers {
19+
ibm = {
20+
source = "IBM-Cloud/ibm"
21+
}
22+
tls = {
23+
source = "hashicorp/tls"
24+
version = "4.0.6"
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)