Skip to content

Commit a843a76

Browse files
committed
Add terraform for provisioning power build cluster on ibmcloud
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent c521737 commit a843a76

36 files changed

+988
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module "resource_group" {
2+
source = "./modules/resource_group"
3+
}
4+
5+
module "secrets_manager" {
6+
source = "./modules/secrets_manager"
7+
resource_group_id = module.resource_group.k8s_rg_id
8+
}
9+
10+
module "vpc" {
11+
providers = {
12+
ibm = ibm.vpc
13+
}
14+
source = "./modules/vpc"
15+
resource_group_id = module.resource_group.k8s_rg_id
16+
}
17+
18+
module "transit_gateway" {
19+
depends_on = [module.vpc]
20+
providers = {
21+
ibm = ibm.vpc
22+
}
23+
source = "./modules/transit_gateway"
24+
resource_group_id = module.resource_group.k8s_rg_id
25+
vpc_crn = module.vpc.crn
26+
powervs_crn = ibm_pi_workspace.build_cluster.crn
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "k8s_rg_id" {
2+
value = ibm_resource_group.k8s_rg.id
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "ibm_resource_group" "k8s_rg" {
2+
name = "k8s-project"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
ibm = {
4+
source = "IBM-Cloud/ibm"
5+
}
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "k8s_secrets_manager_id" {
2+
value = ibm_resource_instance.secrets_manager.guid
3+
}
4+
5+
output "k8s_powervs_ssh_public_key" {
6+
value = tls_private_key.private_key.public_key_openssh
7+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
locals {
2+
secrets_manager_region = "us-south"
3+
secrets_manager_name = "k8s-secrets-ppc64le"
4+
}
5+
6+
resource "ibm_resource_instance" "secrets_manager" {
7+
name = local.secrets_manager_name
8+
resource_group_id = var.resource_group_id
9+
service = "secrets-manager"
10+
plan = "standard"
11+
location = local.secrets_manager_region
12+
13+
timeouts {
14+
create = "15m"
15+
update = "15m"
16+
delete = "15m"
17+
}
18+
}
19+
20+
# RSA key of size 4096 bits
21+
resource "tls_private_key" "private_key" {
22+
algorithm = "RSA"
23+
rsa_bits = 4096
24+
}
25+
26+
resource "ibm_sm_arbitrary_secret" "ssh_private_key" {
27+
name = "powervs-ssh-private-key"
28+
instance_id = ibm_resource_instance.secrets_manager.guid
29+
region = local.secrets_manager_region
30+
labels = ["powervs-ssh-private-key"]
31+
payload = tls_private_key.private_key.private_key_openssh
32+
}
33+
34+
resource "ibm_sm_arbitrary_secret" "ssh_public_key" {
35+
name = "powervs-ssh-public-key"
36+
instance_id = ibm_resource_instance.secrets_manager.guid
37+
region = local.secrets_manager_region
38+
labels = ["powervs-ssh-public-key"]
39+
payload = tls_private_key.private_key.public_key_openssh
40+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
variable "resource_group_id" {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
ibm = {
4+
source = "IBM-Cloud/ibm"
5+
}
6+
tls = {
7+
source = "hashicorp/tls"
8+
version = "4.0.6"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)