generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add gpu example #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vburckhardt
wants to merge
7
commits into
main
Choose a base branch
from
gpu-example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+326
−1
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f576bf6
feat: add gpu example
vburckhardt 09a63dd
tests: add test case for gpu example
vburckhardt 14cb3da
Merge branch 'main' into gpu-example
vburckhardt 9daa317
chore: remove catalog template
vburckhardt 91f1886
Merge branch 'main' of github.com:terraform-ibm-modules/terraform-ibm…
vburckhardt d6041a2
chore: merge with main
vburckhardt ae27ead
chore: open up network acl to get ingress green out of the box
vburckhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # GPU Worker Pool Example | ||
|
|
||
| This example illustrates how to create an OpenShift cluster on IBM Cloud VPC with: | ||
| 1. A default worker pool with basic machines (bx2.4x16) across 3 zones | ||
| 2. A second worker pool with a single GPU machine (gx3.16x80.l4) in one zone | ||
|
|
||
| This configuration is useful for workloads that require both general-purpose compute nodes and specialized GPU nodes for AI/ML workloads. | ||
|
|
||
| ## Architecture | ||
|
|
||
| This example creates: | ||
| - A VPC using the landing-zone-vpc module with: | ||
| - Subnets across 3 zones for the default worker pool | ||
| - A separate subnet in zone 1 for the GPU worker pool | ||
| - Public gateways in all 3 zones | ||
| - An OpenShift cluster with: | ||
| - Default worker pool: 1 worker per zone (3 total) using bx2.4x16 machines | ||
| - GPU worker pool: 1 worker in zone 1 using gx3.16x80.l4 machine with NVIDIA L4 GPUs | ||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| terraform init | ||
| terraform plan -var-file="input.tfvars" | ||
| terraform apply -var-file="input.tfvars" | ||
| ``` | ||
|
|
||
| ## Example input.tfvars file | ||
|
|
||
| ```hcl | ||
| ibmcloud_api_key = "your_api_key_here" # pragma: allowlist secret | ||
| prefix = "gpu" | ||
| region = "us-south" | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "ibmcloud_api_key": $VALIDATION_APIKEY, | ||
| "region": "us-south", | ||
| "resource_tags": $TAGS, | ||
| "prefix": $PREFIX | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| ######################################################################################################################## | ||
| # Resource Group | ||
| ######################################################################################################################## | ||
|
|
||
| module "resource_group" { | ||
| source = "terraform-ibm-modules/resource-group/ibm" | ||
| version = "1.4.0" | ||
| # if an existing resource group is not set (null) create a new one using prefix | ||
| resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null | ||
| existing_resource_group_name = var.resource_group | ||
| } | ||
|
|
||
| ######################################################################################################################## | ||
| # VPC + Subnets + Public Gateways using landing-zone-vpc module | ||
| ######################################################################################################################## | ||
|
|
||
| module "vpc" { | ||
| source = "terraform-ibm-modules/landing-zone-vpc/ibm" | ||
| version = "8.8.0" | ||
| resource_group_id = module.resource_group.resource_group_id | ||
| region = var.region | ||
| prefix = var.prefix | ||
| tags = var.resource_tags | ||
| name = "${var.prefix}-vpc" | ||
|
|
||
| # Define subnets across 3 zones for the default worker pool | ||
| # and a separate subnet in zone 1 for the GPU worker pool | ||
| subnets = { | ||
| zone-1 = [ | ||
| { | ||
| name = "subnet-default-1" | ||
| cidr = "10.10.10.0/24" | ||
| public_gateway = true | ||
| acl_name = "vpc-acl" | ||
| }, | ||
| { | ||
| name = "subnet-gpu" | ||
| cidr = "10.10.20.0/24" | ||
| public_gateway = true | ||
| acl_name = "vpc-acl" | ||
| } | ||
| ], | ||
| zone-2 = [ | ||
| { | ||
| name = "subnet-default-2" | ||
| cidr = "10.20.10.0/24" | ||
| public_gateway = true | ||
| acl_name = "vpc-acl" | ||
| } | ||
| ], | ||
| zone-3 = [ | ||
| { | ||
| name = "subnet-default-3" | ||
| cidr = "10.30.10.0/24" | ||
| public_gateway = true | ||
| acl_name = "vpc-acl" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| # Enable public gateways in all zones | ||
| use_public_gateways = { | ||
| zone-1 = true | ||
| zone-2 = true | ||
| zone-3 = true | ||
| } | ||
|
|
||
| # Define network ACLs | ||
| network_acls = [ | ||
| { | ||
| name = "vpc-acl" | ||
| add_ibm_cloud_internal_rules = true | ||
| add_vpc_connectivity_rules = true | ||
| rules = [] | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| ######################################################################################################################## | ||
| # OCP VPC cluster with default worker pool across 3 zones and a GPU worker pool in zone 1 | ||
| ######################################################################################################################## | ||
|
|
||
| locals { | ||
| # Get all subnets from the VPC module | ||
| all_subnets = module.vpc.subnet_zone_list | ||
|
|
||
| # Define subnets for the default worker pool (across 3 zones) | ||
| default_vpc_subnets = { | ||
| default = [ | ||
| for subnet in local.all_subnets : | ||
| { | ||
| id = subnet.id | ||
| cidr_block = subnet.cidr | ||
| zone = subnet.zone | ||
| } | ||
| if strcontains(subnet.name, "subnet-default") | ||
| ] | ||
| } | ||
|
|
||
| # Define subnet for the GPU worker pool (single zone) | ||
| gpu_vpc_subnets = { | ||
| gpu = [ | ||
| for subnet in local.all_subnets : | ||
| { | ||
| id = subnet.id | ||
| cidr_block = subnet.cidr | ||
| zone = subnet.zone | ||
| } | ||
| if strcontains(subnet.name, "subnet-gpu") # Use strcontains rather than == given that a prefix is added by landing zone vpc to subnet names | ||
| ] | ||
| } | ||
|
|
||
| # Combine all subnets | ||
| cluster_vpc_subnets = merge(local.default_vpc_subnets, local.gpu_vpc_subnets) | ||
|
|
||
| # Define worker pools | ||
| worker_pools = [ | ||
| { | ||
| subnet_prefix = "default" | ||
| pool_name = "default" # ibm_container_vpc_cluster automatically names default pool "default" | ||
| machine_type = var.default_worker_pool_machine_type | ||
| workers_per_zone = 1 | ||
| operating_system = "RHCOS" | ||
| }, | ||
| { | ||
| subnet_prefix = "gpu" | ||
| pool_name = "gpu" | ||
| machine_type = var.gpu_worker_pool_machine_type | ||
| workers_per_zone = 1 | ||
| operating_system = "RHCOS" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| module "ocp_base" { | ||
| source = "../.." | ||
| resource_group_id = module.resource_group.resource_group_id | ||
| region = var.region | ||
| tags = var.resource_tags | ||
| cluster_name = var.prefix | ||
| force_delete_storage = true | ||
| vpc_id = module.vpc.vpc_id | ||
| vpc_subnets = local.cluster_vpc_subnets | ||
| ocp_version = var.ocp_version | ||
| worker_pools = local.worker_pools | ||
| access_tags = var.access_tags | ||
| ocp_entitlement = var.ocp_entitlement | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| ######################################################################################################################## | ||
| # Outputs | ||
| ######################################################################################################################## | ||
|
|
||
| output "cluster_name" { | ||
| value = module.ocp_base.cluster_name | ||
| description = "The name of the provisioned cluster." | ||
| } | ||
|
|
||
| output "workerpools" { | ||
| value = module.ocp_base.workerpools | ||
| description = "Worker pools created in the cluster." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| ######################################################################################################################## | ||
| # Provider config | ||
| ######################################################################################################################## | ||
|
|
||
| provider "ibm" { | ||
| ibmcloud_api_key = var.ibmcloud_api_key | ||
| region = var.region | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| ######################################################################################################################## | ||
| # Input variables | ||
| ######################################################################################################################## | ||
|
|
||
| variable "ibmcloud_api_key" { | ||
| type = string | ||
| description = "The IBM Cloud api token" | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "prefix" { | ||
| type = string | ||
| description = "Prefix for name of all resource created by this example" | ||
| validation { | ||
| error_message = "Prefix must begin and end with a letter and contain only letters, numbers, and - characters." | ||
| condition = can(regex("^([A-z]|[a-z][-a-z0-9]*[a-z0-9])$", var.prefix)) | ||
| } | ||
| } | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| description = "Region where resources are created" | ||
| } | ||
|
|
||
| variable "resource_group" { | ||
| type = string | ||
| description = "An existing resource group name to use for this example, if unset a new resource group will be created" | ||
| default = null | ||
| } | ||
|
|
||
| variable "resource_tags" { | ||
| type = list(string) | ||
| description = "Optional list of tags to be added to created resources" | ||
| default = [] | ||
| } | ||
|
|
||
| variable "ocp_version" { | ||
| type = string | ||
| description = "Version of the OCP cluster to provision" | ||
| default = null | ||
| } | ||
|
|
||
| variable "access_tags" { | ||
| type = list(string) | ||
| description = "A list of access tags to apply to the resources created by the module." | ||
| default = [] | ||
| } | ||
|
|
||
| variable "ocp_entitlement" { | ||
| type = string | ||
| description = "Value that is applied to the entitlements for OCP cluster provisioning" | ||
| default = null | ||
| } | ||
|
|
||
| variable "default_worker_pool_machine_type" { | ||
| type = string | ||
| description = "The machine type for the default worker pool" | ||
| default = "bx2.4x16" | ||
| } | ||
|
|
||
| variable "gpu_worker_pool_machine_type" { | ||
| type = string | ||
| description = "The machine type for the GPU worker pool" | ||
| default = "gx3.16x80.l4" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| terraform { | ||
| required_version = ">=1.9.0" | ||
|
|
||
| # Using the latest provider version to ensure GPU support | ||
| required_providers { | ||
| ibm = { | ||
| source = "IBM-Cloud/ibm" | ||
| version = ">= 1.79.2" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is not needed since we no longer onboard to module registry