### Example Usage of rancher2_node_pool Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/node_pool Demonstrates the creation of a Rancher v2 RKE Cluster, Cloud Credential, Node Template, and finally a Node Pool resource. This example outlines the necessary dependencies and resource configurations for setting up a node pool within a Rancher RKE cluster. ```terraform # Create a new rancher2 RKE Cluster resource "rancher2_cluster" "foo-custom" { name = "foo-custom" description = "Foo rancher2 custom cluster" kind = "rke" rke_config { network { plugin = "canal" } } } # Create a new rancher2 Cloud Credential resource "rancher2_cloud_credential" "foo" { name = "foo" description= "Terraform cloudCredential acceptance test" amazonec2_credential_config { access_key = "XXXXXXXXXXXXXXXXXXXX" secret_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } } # Create a new rancher2 Node Template resource "rancher2_node_template" "foo" { name = "foo" description = "foo test" cloud_credential_id = rancher2_cloud_credential.foo.id amazonec2_config { ami = "" region = "" security_group = [""] subnet_id = "" vpc_id = "" zone = "" } } # Create a new rancher2 Node Pool resource "rancher2_node_pool" "foo" { cluster_id = rancher2_cluster.foo-custom.id name = "foo" hostname_prefix = "foo-cluster-0" node_template_id = rancher2_node_template.foo.id quantity = 1 control_plane = true etcd = true worker = true } ``` -------------------------------- ### Terraform Rancher2 Cluster Sync Example Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_sync This example demonstrates how to create a Rancher v2 cluster, a node template, a node pool, and then use the rancher2_cluster_sync resource to wait for the cluster to become active. It also shows the creation of a rancher2_project resource that depends on the cluster sync. ```terraform # Create a new rancher2 rke Cluster resource "rancher2_cluster" "foo-custom" { name = "foo-custom" description = "Foo rancher2 custom cluster" rke_config { network { plugin = "canal" } } } # Create a new rancher2 Node Template resource "rancher2_node_template" "foo" { name = "foo" description = "foo test" amazonec2_config { access_key = "" secret_key = "" ami = "" region = "" security_group = [""] subnet_id = "" vpc_id = "" zone = "" } } # Create a new rancher2 Node Pool resource "rancher2_node_pool" "foo" { cluster_id = rancher2_cluster.foo-custom.id name = "foo" hostname_prefix = "foo-cluster-0" node_template_id = rancher2_node_template.foo.id quantity = 3 control_plane = true etcd = true worker = true } # Create a new rancher2 Cluster Sync resource "rancher2_cluster_sync" "foo-custom" { cluster_id = rancher2_cluster.foo-custom.id node_pool_ids = [rancher2_node_pool.foo.id] } # Create a new rancher2 Project resource "rancher2_project" "foo" { name = "foo" cluster_id = rancher2_cluster_sync.foo-custom.id description = "Terraform namespace acceptance test" resource_quota { project_limit { limits_cpu = "2000m" limits_memory = "2000Mi" requests_storage = "2Gi" } namespace_default_limit { limits_cpu = "500m" limits_memory = "500Mi" requests_storage = "1Gi" } } container_resource_limit { limits_cpu = "20m" limits_memory = "20Mi" requests_cpu = "1m" requests_memory = "1Mi" } } ``` -------------------------------- ### Create Rancher2 Bootstrap Resource Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/bootstrap This example shows how to create a `rancher2_bootstrap` resource to initialize a Rancher system. It allows setting the admin password, which can be provided directly or will be randomly generated if omitted. ```Terraform resource "rancher2_bootstrap" "admin" { password = "blahblah" } ``` -------------------------------- ### Create Rancher v2 RKE Cluster with Basic Configuration Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster This example shows the creation of a Rancher v2 RKE cluster with a minimal configuration, specifying only the network plugin ('canal'). It's a simpler setup compared to the audit logging example. ```terraform # Create a new rancher2 RKE Cluster resource "rancher2_cluster" "foo-custom" { name = "foo-custom" description = "Foo rancher2 custom cluster" rke_config { network { plugin = "canal" } } } ``` -------------------------------- ### Create Rancher v2 Token Resource Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/token Demonstrates how to create a new Rancher v2 Token resource. This example shows the basic usage for creating a global token with a specified description and time-to-live (TTL). ```Terraform resource "rancher2_token" "foo" { description = "foo token" ttl = 1200 } ``` -------------------------------- ### Create Rancher2 Multi Cluster App Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/multi_cluster_app Example of how to create a new rancher2 Multi Cluster App with specified catalog, name, targets, template, and answers. This defines the basic deployment configuration. ```Terraform resource "rancher2_multi_cluster_app" "foo" { catalog_name = "" name = "foo" targets { project_id = "" } template_name = "" template_version = "" answers { values = { "ingress_host" = "test.xip.io" } } roles = ["project-member"] } ``` -------------------------------- ### Create Rancher2 Node Driver Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/node_driver This example demonstrates how to create a new Rancher v2 Node Driver using the `rancher2_node_driver` resource. It requires specifying essential arguments like `active`, `builtin`, `name`, and `url`, with optional arguments for `checksum`, `description`, `external_id`, `ui_url`, and `whitelist_domains`. ```Terraform resource "rancher2_node_driver" "foo" { active = true builtin = false checksum = "0x0" description = "Foo description" external_id = "foo_external" name = "foo" ui_url = "local://ui" url = "local://" whitelist_domains = ["*.foo.com"] } ``` -------------------------------- ### Create rancher2 App in a new namespace Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/app This example shows how to create a rancher2 App within a newly created rancher2 namespace. It first defines the namespace with its resource quotas and then references the namespace ID for the app's target namespace. ```Terraform resource "rancher2_namespace" "foo" { name = "foo" description = "Foo namespace" project_id = "" resource_quota { limit { limits_cpu = "100m" limits_memory = "100Mi" requests_storage = "1Gi" } } } resource "rancher2_app" "foo" { catalog_name = "" name = "foo" description = "Foo app" project_id = "" template_name = "" template_version = "" target_namespace = rancher2_namespace.foo.id answers = { "ingress_host" = "test.xip.io" "foo" = "bar" "ingress.annotations.nginx.ingress.kubernetes.io/force-ssl-redirect" = true } } ``` -------------------------------- ### Create Rancher2 Cluster and Namespace Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/namespace This example shows the creation of a rancher2 custom cluster and then a namespace assigned to that cluster's default project. It includes configuration for the cluster's network and the namespace's resource quotas and container limits. ```Terraform # Create a new rancher2 Cluster resource "rancher2_cluster" "foo-custom" { name = "foo-custom" description = "Foo rancher2 custom cluster" rke_config { network { plugin = "canal" } } } # Create a new rancher2 Namespace assigned to default cluster project resource "rancher2_namespace" "foo" { name = "foo" project_id = rancher2_cluster.foo-custom.default_project_id description = "foo namespace" resource_quota { limit { limits_cpu = "100m" limits_memory = "100Mi" requests_storage = "1Gi" } } container_resource_limit { limits_cpu = "20m" limits_memory = "20Mi" requests_cpu = "1m" requests_memory = "1Mi" } } ``` -------------------------------- ### Terraform: Import Rancher2 Catalog Resource Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/catalog This example shows how to import an existing Rancher v2 catalog into Terraform management. The import command requires the catalog's scope and its ID, formatted as `.`. This allows you to manage pre-existing catalogs with Terraform. ```Terraform $ terraform import rancher2_catalog.foo . ``` -------------------------------- ### Create Rancher V2 Cluster with Machine Selector Config or Global Config Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2 This example shows how to configure a Rancher V2 cluster using machine selector configurations or machine global configurations. It allows for specifying RKE2-specific server settings and custom arguments for Kubernetes components. ```Terraform resource "rancher2_cluster_v2" "foo" { name = "foo" # An RKE2 version and REK2-specific server configuration are used in this example kubernetes_version = "rke2-version" enable_network_policy = false rke_config { machine_selector_config { machine_label_selector { match_labels = { # You can specify multiple labels "rke.cattle.io/control-plane-role" = "true", "rke.cattle.io/etcd-role" = "true", } # You can also specify one or more match expressions match_expressions { key = "name" values = ["a", "b"] operator = "In" } match_expressions { key = "department" operator = "In" values = ["a", "b"] } } config = < ``` -------------------------------- ### Configure Rancher2 Provider for Bootstrap and Admin Modes (Terraform) Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/index This example demonstrates configuring the Rancher2 provider for both bootstrap and admin modes using aliases. It first configures a bootstrap provider to create a `rancher2_bootstrap` resource, then uses the output (URL and token) from the bootstrap resource to configure an admin provider for managing other Rancher2 resources like `rancher2_catalog`. ```Terraform # Configure the Rancher2 provider to bootstrap and admin # Provider config for bootstrap provider "rancher2" { alias = "bootstrap" api_url = "https://rancher.my-domain.com" bootstrap = true } # Create a new rancher2_bootstrap using bootstrap provider config resource "rancher2_bootstrap" "admin" { provider = "rancher2.bootstrap" password = "blahblah" } # Provider config for admin provider "rancher2" { alias = "admin" api_url = rancher2_bootstrap.admin.url token_key = rancher2_bootstrap.admin.token insecure = true } # Create a new rancher2 resource using admin provider config resource "rancher2_catalog" "foo" { provider = "rancher2.admin" name = "test" url = "http://foo.com:8080" } ``` -------------------------------- ### Create Rancher2 Cloud Credential (Terraform) Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cloud_credential Example of creating a new `rancher2_cloud_credential` resource with AWS EC2 configuration. This requires specifying the credential name, description, and AWS access/secret keys. ```terraform resource "rancher2_cloud_credential" "foo" { name = "foo" description = "foo test" amazonec2_credential_config { access_key = "" secret_key = "" } } ``` -------------------------------- ### Get Imported Harvester Cluster Info Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2 Retrieves information about an existing imported Harvester cluster. This data source is used to fetch details needed for cloud credential configuration. Dependencies: Rancher2 provider. ```terraform data "rancher2_cluster_v2" "foo-harvester" { name = "foo-harvester" } ``` -------------------------------- ### Create rancher2 App Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/app This code snippet demonstrates how to create a new rancher2 App resource. It requires specifying the catalog name, app name, project ID, template name, template version, target namespace, and optional answers for the app configuration. ```Terraform resource "rancher2_app" "foo" { catalog_name = "" name = "foo" description = "Foo app" project_id = "" template_name = "" template_version = "" target_namespace = "" answers = { "ingress_host" = "test.xip.io" "foo" = "bar" "ingress.annotations.nginx.ingress.kubernetes.io/force-ssl-redirect" = true } } ``` -------------------------------- ### Import Rancher2 Node Driver Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/node_driver This example shows how to import an existing Rancher v2 Node Driver into Terraform management. The import command requires the `rancher2_node_driver` resource name and the specific node driver ID from Rancher. ```Bash terraform import rancher2_node_driver.foo ``` -------------------------------- ### Import Rancher v2 Project Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/project This command demonstrates how to import an existing Rancher v2 project into Terraform state management. It uses the `terraform import` command followed by the resource address (`rancher2_project.foo`) and the project ID from Rancher. ```Bash $ terraform import rancher2_project.foo ``` -------------------------------- ### Import EKS Cluster to Rancher v2 Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster This example shows how to import an existing EKS cluster into Rancher v2 using the `rancher2_cluster` resource with `eks_config_v2`. It requires a `rancher2_cloud_credential` resource for AWS access. Applicable for Rancher v2.5.x and above. ```Terraform resource "rancher2_cloud_credential" "foo" { name = "foo" description = "foo test" amazonec2_credential_config { access_key = "" secret_key = "" } } resource "rancher2_cluster" "foo" { name = "foo" description = "Terraform EKS cluster" eks_config_v2 { cloud_credential_id = rancher2_cloud_credential.foo.id name = "" region = "" imported = true } } ``` -------------------------------- ### Create Rancher2 Bootstrap using Aliased Provider Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/bootstrap This example shows how to create a `rancher2_bootstrap` resource using a provider configuration that has an alias. By specifying `provider = "rancher2.bootstrap"`, Terraform knows to use the aliased provider configuration for this resource. ```Terraform resource "rancher2_bootstrap" "admin" { provider = "rancher2.bootstrap" password = "blahblah" } ``` -------------------------------- ### OpenNebula Cloud Configuration Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/node_template Configuration arguments for deploying nodes on OpenNebula. ```APIDOC ## OpenNebula Cloud Configuration Arguments ### Description Configuration options for OpenNebula. ### Method N/A (Configuration Block) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```hcl opennebula_config { # Add OpenNebula specific arguments here } ``` ### Response #### Success Response (200) N/A (Configuration Block) #### Response Example N/A ``` -------------------------------- ### Disable RKE2 Cluster System Services with Terraform Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2 This example demonstrates how to disable RKE2-specific system services like `rke2-coredns` and `rke2-ingress-nginx` in an RKE2 cluster using the `machine_global_config` argument within the `rancher2_cluster_v2` Terraform resource. It requires the Rancher2 Terraform provider. ```Terraform resource "rancher2_cluster_v2" "foo" { name = "foo" kubernetes_version = "rke2-version" rke_config { machine_global_config= <:`. ```Bash $ terraform import rancher2_app.foo : ``` -------------------------------- ### Configure Pod and Service Network CIDRs with Terraform Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster_v2 This example shows how to specify the IPv4/IPv6 network CIDRs for pod IPs and service IPs in an RKE2/K3s cluster using the `machine_global_config` argument within the `rancher2_cluster_v2` Terraform resource. It requires the Rancher2 Terraform provider. ```Terraform resource "rancher2_cluster_v2" "foo" { name = "foo" kubernetes_version = "rke2/k3s-version" rke_config { machine_global_config= <", "name": "custom-psact", "description": "This is my custom Pod Security Admission Configuration Template", "defaults": { "audit": "restricted", "audit_version": "latest", "enforce": "restricted", "enforce_version": "latest", "warn": "restricted", "warn_version": "latest" }, "exemptions": { "usernames": ["testuser"], "runtime_classes": ["testclass"], "namespaces": ["ingress-nginx","kube-system"] }, "labels": {}, "annotations": {} } ``` ### Timeouts * `create` - (Default `10 minutes`) Used for creating the resource. * `update` - (Default `10 minutes`) Used for updating the resource. * `delete` - (Default `10 minutes`) Used for deleting the resource. ### Import Pod Security Admission Configration Templates can be imported using its ID: ```bash $ terraform import rancher2_pod_security_admission_configuration_template.foo ``` ``` -------------------------------- ### Import Rancher v2 Setting - Terraform CLI Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/setting This command shows how to import an existing Rancher v2 setting into Terraform state. It uses the `terraform import` command followed by the resource address and the Rancher setting ID. ```Bash terraform import rancher2_setting.foo ``` -------------------------------- ### Create Rancher v2 RKE Cluster with Agent Scheduling Customization Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster This example shows how to create a Rancher v2 RKE cluster with specific cluster agent scheduling customizations, including priority class and pod disruption budgets. This is for Rancher v2.11.0 and above. ```Terraform resource "rancher2_cluster" "foo" { name = "foo" description = "Terraform cluster with agent customization" rke_config { } cluster_agent_deployment_customization { scheduling_customization { priority_class { # The preemption_policy must be set to 'Never', 'PreemptLowerPriority', or omitted. # If omitted, the default of 'PreemptLowerPriority' is used. preemption_policy = "PreemptLowerPriority" # The value cannot be less than negative 1 billion, or greater than 1 billion value = 1000000000 } pod_disruption_budget { # min_available and max_unavailable must either be non-negative whole integers, # or whole number percentages greater than 0 and less than or equal to 100 (e.g. "50%"). # You cannot set both min_available and max_unavailable at the same time. min_available = "1" #max_unavailable } } } } ``` -------------------------------- ### Linode Instance Configuration Arguments Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/machine_config_v2 Specifies the arguments for configuring a Linode instance. This includes settings for SSH access, IP configuration, image, instance type, region, and optional StackScript usage. The `token` argument is mandatory for older Rancher versions. ```terraform resource "linode_config" "example" { label = "my-linode-instance" region = "us-east" instance_type = "g6-standard-4" image = "linode/ubuntu18.04" ssh_user = "root" authorized_users = "user1,user2" tags = "test,staging" stackscript_data = jsonencode({ "some_key" = "some_value" }) create_private_ip = true docker_port = "2376" root_pass = "my_root_password" ssh_port = "22" swap_size = "1024" token = "my_linode_token" ua_prefix = "my-product/1.0" } ``` -------------------------------- ### Create Rancher2 RKE Cluster with Node Pool using Terraform Source: https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/cluster This example shows how to create a Rancher v2 RKE cluster and associate a node pool with it. It defines the cluster's network configuration and the node template's AWS specific settings. ```terraform # Create a new rancher2 RKE Cluster resource "rancher2_cluster" "foo-custom" { name = "foo-custom" description = "Foo rancher2 custom cluster" rke_config { network { plugin = "canal" } } } # Create a new rancher2 Node Template resource "rancher2_node_template" "foo" { name = "foo" description = "foo test" amazonec2_config { access_key = "" secret_key = "" ami = "" region = "" security_group = [""] subnet_id = "" vpc_id = "" zone = "" } } # Create a new rancher2 Node Pool resource "rancher2_node_pool" "foo" { cluster_id = rancher2_cluster.foo-custom.id name = "foo" hostname_prefix = "foo-cluster-0" node_template_id = rancher2_node_template.foo.id quantity = 3 control_plane = true etcd = true worker = true } ```