### Example Usage of rancher2_cluster_sync Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster_sync.md 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 ensure the cluster is active before creating a `rancher2_project`. It shows the dependencies between these resources and how `cluster_id` and `node_pool_ids` are utilized. ```hcl # 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" } } ``` -------------------------------- ### Import rancher2 Namespace Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/namespace.md Example command for importing an existing rancher2 Namespace resource into Terraform state. This requires specifying the project ID and namespace ID in the correct format. ```bash # terraform import rancher2_namespace.foo . # is in the format : terraform import rancher2_namespace.foo . ``` -------------------------------- ### Create rancher2 Namespace Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/namespace.md Example of creating a new rancher2 Namespace resource with specified name, project ID, description, resource quotas, and container resource limits. This snippet demonstrates basic namespace provisioning in Terraform. ```hcl # Create a new rancher2 Namespace resource "rancher2_namespace" "foo" { name = "foo" 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" } } ``` -------------------------------- ### Create Rancher v2 RKE Cluster - Terraform Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster.md This example demonstrates the creation of a basic Rancher v2 RKE cluster with a specified network plugin. It allows for a name, description, and network configuration. ```hcl # 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 Rancher2 Global, Cluster, and Project Catalogs (Terraform) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/catalog.md Demonstrates how to create different types of Rancher v2 catalogs using the rancher2_catalog Terraform resource. It covers global, cluster, and project scopes, requiring different arguments based on the chosen scope. The examples show basic configuration with name and URL. ```hcl # Create a new Rancher2 Global Catalog resource "rancher2_catalog" "foo-global" { name = "foo-global" url = "https://" } # Create a new Rancher2 Cluster Catalog resource "rancher2_catalog" "foo-cluster" { name = "foo-cluster" url = "https://" scope = "cluster" } # Create a new Rancher2 Project Catalog resource "rancher2_catalog" "foo-project" { name = "foo-project" url = "https://" scope = "project" } ``` -------------------------------- ### Create Rancher2 Cluster Driver Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster_driver.md Example HCL code to create a new Rancher2 Cluster Driver resource. It specifies whether the driver is active and built-in, along with its name, description, URL, and whitelisted domains. Dependencies include the Rancher2 Terraform provider. ```hcl # Create a new Rancher2 Cluster Driver resource "rancher2_cluster_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"] } ``` -------------------------------- ### Use rancher2_catalog_v2 Data Source Example Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/catalog_v2.md This Terraform configuration demonstrates how to use the rancher2_catalog_v2 data source to retrieve information about a specific catalog v2 within a Rancher cluster. It requires the cluster ID and the catalog's name as input parameters. ```terraform data "rancher2_catalog_v2" "foo" { cluster_id = name = "foo" } ``` -------------------------------- ### Setting up Rancher2 Provider with PowerShell Script Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/test-process.md PowerShell script for setting up and testing a local Rancher2 provider using a downloaded binary from a specific RC version, supporting cross-platform testing on Windows. ```powershell # Example: PS /> ./setup-provider-windows.ps1 # Example: PS /> ./setup-provider-windows.ps1 rancher2 v3.0.0-rc1 ``` -------------------------------- ### Get rancher2_global_role Data Source Example Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/global_role.md This HCL code demonstrates how to use the rancher2_global_role data source to retrieve information about a specific global role by its name. It requires the 'name' argument and exports various attributes of the global role. ```hcl data "rancher2_global_role" "foo" { name = "foo" } ``` -------------------------------- ### Create Rancher v2 RKE Cluster with Node Pool Terraform Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster.md This example shows how to create a Rancher v2 RKE cluster and assign a node pool to it. It involves defining the cluster, a node template with AWS EC2 configuration, and then a node pool that links the cluster and the node template. This setup is useful for provisioning Kubernetes clusters in Rancher with specific node configurations. ```hcl # 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 } ``` -------------------------------- ### Build Rancher v2 Terraform Provider Binary Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/README.md Builds the Terraform provider plugin for Rancher v2. This command compiles the provider source code into an executable binary, typically placed in the $GOPATH/bin directory, making it available for Terraform initialization. ```sh cd $GOPATH/src/github.com/terraform-providers/terraform-provider-rancher2 make build ``` -------------------------------- ### Deploying Istio Application Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster.md This section demonstrates how to deploy Istio using the `rancher2_app` resource, configuring various Istio components and settings. ```APIDOC ## POST /v3/project/{projectId}/apps ### Description Creates a new Rancher v2 application deployment. ### Method POST ### Endpoint `/v3/project/{projectId}/apps` ### Parameters #### Path Parameters - **projectId** (string) - Required - The ID of the project where the app will be deployed. #### Request Body - **catalogName** (string) - Required - The name of the catalog to deploy from. - **name** (string) - Required - The name of the application. - **description** (string) - Optional - A description for the application. - **projectId** (string) - Required - The ID of the project. - **templateName** (string) - Required - The name of the application template. - **templateVersion** (string) - Required - The version of the application template. - **targetNamespace** (string) - Required - The namespace where the application will be deployed. - **answers** (object) - Optional - A map of answers to configure the application. ### Request Example ```json { "catalogName": "system-library", "name": "cluster-istio", "description": "Terraform app acceptance test", "projectId": "", "templateName": "rancher-istio", "templateVersion": "0.1.1", "targetNamespace": "", "answers": { "certmanager.enabled": false, "enableCRDs": true, "galley.enabled": true, "gateways.enabled": false, "gateways.istio-ingressgateway.resources.limits.cpu": "2000m", "gateways.istio-ingressgateway.resources.limits.memory": "1024Mi", "gateways.istio-ingressgateway.resources.requests.cpu": "100m", "gateways.istio-ingressgateway.resources.requests.memory": "128Mi", "gateways.istio-ingressgateway.type": "NodePort", "global.rancher.clusterId": "", "istio_cni.enabled": "false", "istiocoredns.enabled": "false", "kiali.enabled": "true", "mixer.enabled": "true", "mixer.policy.enabled": "true", "mixer.policy.resources.limits.cpu": "4800m", "mixer.policy.resources.limits.memory": "4096Mi", "mixer.policy.resources.requests.cpu": "1000m", "mixer.policy.resources.requests.memory": "1024Mi", "mixer.telemetry.resources.limits.cpu": "4800m", "mixer.telemetry.resources.limits.memory": "4096Mi", "mixer.telemetry.resources.requests.cpu": "1000m", "mixer.telemetry.resources.requests.memory": "1024Mi", "mtls.enabled": false, "nodeagent.enabled": false, "pilot.enabled": true, "pilot.resources.limits.cpu": "1000m", "pilot.resources.limits.memory": "4096Mi", "pilot.resources.requests.cpu": "500m", "pilot.resources.requests.memory": "2048Mi", "pilot.traceSampling": "1", "security.enabled": true, "sidecarInjectorWebhook.enabled": true, "tracing.enabled": true, "tracing.jaeger.resources.limits.cpu": "500m", "tracing.jaeger.resources.limits.memory": "1024Mi", "tracing.jaeger.resources.requests.cpu": "100m", "tracing.jaeger.resources.requests.memory": "100Mi" } } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the created application. - **state** (string) - The current state of the application. #### Response Example ```json { "id": "app-xxxxx", "state": "active" } ``` ``` -------------------------------- ### Create Harvester Machine Config v2 using rancher2_machine_config_v2 Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/machine_config_v2.md This example shows how to create a machine configuration for Harvester using the rancher2_machine_config_v2 Terraform resource. It includes details for Harvester-specific configurations such as VM namespace, CPU count, memory size, disk information, network interfaces, SSH user, and user data for instance setup. This is useful for managing virtual machines within a Harvester environment. ```hcl # Get imported harvester cluster info data "rancher2_cluster_v2" "foo-harvester" { name = "foo-harvester" } # Create a new Cloud Credential for an imported Harvester cluster resource "rancher2_cloud_credential" "foo-harvester" { name = "foo-harvester" harvester_credential_config { cluster_id = data.rancher2_cluster_v2.foo-harvester.cluster_v1_id cluster_type = "imported" kubeconfig_content = data.rancher2_cluster_v2.foo-harvester.kube_config } } # Create a new rancher2 machine config v2 using harvester node_driver resource "rancher2_machine_config_v2" "foo-harvester-v2" { generate_name = "foo-harvester-v2" harvester_config { vm_namespace = "default" cpu_count = "2" memory_size = "4" disk_info = < # Example: ./setup-provider.sh rancher2 v3.0.0-rc1 ``` -------------------------------- ### Create Rancher V2 Cluster with Machine Selector Config (HCL) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster_v2.md This example shows how to create a Rancher V2 cluster using machine selector configurations. It includes examples for both specific `machine_label_selector` configurations and `machine_global_config`. This allows for fine-grained control over node configurations, including RKE2-specific settings. ```hcl 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 = <` `genericoidc_group://` (list) * `auth_endpoint` - (Optional/Computed) The OIDC Auth Endpoint URL. * `certificate` - (Optional/Sensitive) A PEM-encoded CA certificate for the OIDC provider. * `enabled` - (Optional) Enable the auth config provider. Default `true` (bool) * `groups_field` - (Optional/Computed) The name of the OIDC claim to use for the user's group memberships. Default `groups` (string) * `group_search_enabled` - (Optional) Enable group search. Default `false` (bool) * `jwks_url` - (Optional/Computed) The OIDC JWKS URL. * `private_key` - (Optional/Sensitive) A PEM-encoded private key for the OIDC provider. * `scopes` - (Optional/Computed) The OIDC scopes to request. Defaults to `openid profile email` (string) * `token_endpoint` - (Optional/Computed) The OIDC Token Endpoint URL. * `userinfo_endpoint` - (Optional/Computed) The OIDC User Info Endpoint URL. * `annotations` - (Optional/Computed) Annotations of the resource (map) * `labels` - (Optional/Computed) Labels of the resource (map) ### Request Example ```hcl resource "rancher2_auth_config_generic_oidc" "generic_oidc" { name = "genericoidc" client_id = "" client_secret = "" issuer = "https://gitlab.com" rancher_url = "https:///verify-auth" # OIDC claim mapping scopes = "openid profile email read_api" groups_field = "groups" # For the 'genericoidc' provider, group processing must be explicitly enabled. group_search_enabled = true } ``` ### Response #### Success Response (200) * `id` - (Computed) The ID of the resource (string) * `name` - (Computed) The name of the resource (string) * `type` - (Computed) The type of the resource (string) #### Response Example Not Applicable (Terraform Resource) ### Import Generic OIDC auth config can be imported using its name. ``` $ terraform import rancher2_auth_config_generic_oidc.generic_oidc genericoidc ``` ``` -------------------------------- ### rancher2_certificate Data Source Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/certificate.md Retrieves information about a Rancher v2 certificate. This data source can be used to get details for either a project certificate or a namespaced certificate. ```APIDOC ## rancher2_certificate Data Source ### Description Use this data source to retrieve information about a Rancher v2 certificate. Depending of the availability, there are 2 types of Rancher v2 certificates: - Project certificate: Available to all namespaces in the `project_id` - Namespaced certificate: Available to just `namespace_id` in the `project_id` ### Method GET ### Endpoint N/A (Data Source) ### Parameters #### Query Parameters - **name** (String) - Required - The name of the certificate. - **project_id** (String) - Required - The project id where to assign the certificate. - **namespace_id** (String) - Optional - The namespace id where to assign the namespaced certificate. ### Request Example ```hcl # Retrieve a rancher2 Project Certificate data "rancher2_certificate" "foo" { name = "" project_id = "" } ``` ```hcl # Retrieve a rancher2 Namespaced Certificate data "rancher2_certificate" "foo" { name = "" project_id = "" namespace_id = "" } ``` ### Response #### Success Response (200) - **id** (String) - The ID of the resource. - **certs** (String) - Base64 encoded certs. - **description** (String) - A certificate description. - **annotations** (Map) - Annotations for certificate object. - **labels** (Map) - Labels for certificate object. #### Response Example ```json { "id": "", "certs": "", "description": "Certificate description", "annotations": { "field": "value" }, "labels": { "field": "value" } } ``` ``` -------------------------------- ### Create Rancher v2 App Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/app.md This HCL snippet demonstrates how to create a new Rancher v2 application using the `rancher2_app` resource. It specifies the catalog, name, description, project, template, target namespace, and answers for the application. ```hcl 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 } } ``` -------------------------------- ### rancher2_bootstrap Resource Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/bootstrap.md Manages the Rancher v2 bootstrap process, including setting the initial admin password, server URL, and generating an admin token. ```APIDOC ## rancher2_bootstrap Resource ### Description This resource bootstraps a Rancher system by performing the following tasks: - Updates the default admin password, provided by setting `password` or generating a random one. - Sets `server-url` setting, based on `api_url`. - Creates a token for admin user with concrete TTL. **Note:** Starting from Rancher v2.6.0, the Rancher2 installation is setting a random initial admin password by default. To specify the initial password during rancher2 installation, helm chart [`bootstrapPassword`](https://github.com/rancher/rancher/blob/release/v2.6/chart/values.yaml#L157) value for HA installation or docker env variable [`CATTLE_BOOTSTRAP_PASSWORD`](https://github.com/rancher/rancher/blob/release/v2.6/chart/templates/deployment.yaml#L135) for single node installation can be used. To properly use this resource for Rancher v2.6.0 and above, set the `initial_password` argument to the password generated or set during installation. Rancher2 admin password can be updated after the initial run of terraform by setting `password` field and applying this resource again. Rancher2 admin `token` can also be regenerated if `token_update` is set to true. Refresh resource function will check if token is expired. If it is expired, `token_update` will be set to true to force token regeneration on next `terraform apply`. To login Rancher2, the provider tries until success using `token`, then `current_password` and then `initial_password`. If the admin password has been changed outside of terraform and the `token` is expired, the login will fails and the resource will be regenerated. To recover the bootstrap resource, set `initial_password` argument to the proper password and apply. ### Method Resource (Terraform) ### Endpoint N/A (Managed by Terraform Provider) ### Parameters #### Argument Reference * `initial_password` - (Optional/Computed/Sensitive) Initial password for Admin user. Default: `admin` (string) * `password` - (Optional/Computed/Sensitive) Password for Admin user or random generated if empty (string) * `token_ttl` - (Optional) TTL in seconds for generated admin token. Default: `0` (int) * `token_update` - (Optional) Regenerate admin token. Default: `false` (bool) * `ui_default_landing` - (Optional) Default UI landing for k8s clusters. Available options: `ember` (cluster manager ui) and `vue` (cluster cluster explorer ui). Default: `ember` (string) ### Attributes Reference #### Exported Attributes * `id` - (Computed) The ID of the resource (string) * `current_password` - (Computed/Sensitive) Current password for Admin user (string) * `token` - (Computed) Generated API token for Admin User (string) * `token_id` - (Computed) Generated API token id for Admin User (string) * `url` - (Computed) URL set as server-url (string) * `user` - (Computed) Admin username (string) * `temp_token` - (Computed) Generated API temporary token as helper. Should be empty (string) * `temp_token_id` - (Computed) Generated API temporary token id as helper. Should be empty (string) ### Request Example ```hcl # Provider bootstrap config provider "rancher2" { api_url = "https://rancher.my-domain.com" bootstrap = true } # Create a new rancher2_bootstrap resource "rancher2_bootstrap" "admin" { password = "blahblah" } ``` ```hcl # Provider bootstrap config provider "rancher2" { api_url = "https://rancher.my-domain.com" bootstrap = true } # Create a new rancher2_bootstrap for Rancher v2.6.0 and above resource "rancher2_bootstrap" "admin" { initial_password = "" password = "blahblah" } ``` ```hcl # Provider bootstrap config with alias 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" } ``` ``` -------------------------------- ### Terraform HCL: Rancher2 Bootstrap for v2.6.0+ Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/bootstrap.md This snippet shows how to use the rancher2_bootstrap resource for Rancher v2.6.0 and above, requiring the initial_password to be set to the password used during installation. It also includes the standard password field. ```hcl provider "rancher2" { api_url = "https://rancher.my-domain.com" bootstrap = true } # Create a new rancher2_bootstrap for Rancher v2.6.0 and above resource "rancher2_bootstrap" "admin" { initial_password = "" password = "blahblah" } ``` -------------------------------- ### Create rancher2 Namespace assigned to default cluster project Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/namespace.md Example of creating a rancher2 Namespace resource and associating it with the default project of a dynamically created rancher2 Cluster. This illustrates dependency management between Rancher resources in Terraform. ```hcl # 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 HCL: Basic Rancher2 Bootstrap Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/bootstrap.md This snippet demonstrates how to configure the Rancher2 provider for bootstrapping and create a basic rancher2_bootstrap resource. It sets the API URL and enables bootstrapping. ```hcl provider "rancher2" { api_url = "https://rancher.my-domain.com" bootstrap = true } # Create a new rancher2_bootstrap resource "rancher2_bootstrap" "admin" { password = "blahblah" } ``` -------------------------------- ### Rancher v2 Cloud Credential Data Source Example Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/cloud_credential.md This Terraform configuration retrieves information about a Rancher v2 Cloud Credential using the rancher2_cloud_credential data source. It requires the 'name' argument to specify the credential to fetch. ```terraform data "rancher2_cloud_credential" "test" { name = "test" } ``` -------------------------------- ### Import Rancher v2 Registry Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/registry.md This example demonstrates how to import an existing Rancher v2 registry into Terraform state. The import command requires the registry ID, which includes the namespace ID (optional for project-level registries), project ID, and registry ID. ```bash $ terraform import rancher2_registry.foo .. ``` -------------------------------- ### Provider Configuration (Bootstrap and Admin Alias) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/index.md Demonstrates setting up two provider configurations: one for bootstrapping and another for managing resources after bootstrap using aliased providers. ```APIDOC ## Provider Configuration (Bootstrap and Admin Alias) ### Description This example shows how to configure the Rancher2 provider with aliases for both bootstrap and admin modes. It first uses the `bootstrap` provider to create a `rancher2_bootstrap` resource, then uses the information from that resource (URL and token) to configure the `admin` provider for subsequent resource management. ### Method `provider` block ### Endpoint N/A ### Parameters #### Configuration Arguments **Bootstrap Provider (`alias = "bootstrap"`)**: - **api_url** (string) - Required - Rancher API url. - **bootstrap** (bool) - Required - Enables bootstrap mode. **Admin Provider (`alias = "admin"`)**: - **api_url** (string) - Required - Rancher API url, typically sourced from the bootstrap resource's URL. - **token_key** (string, Sensitive) - Required - Rancher API token key, typically sourced from the bootstrap resource's token. - **insecure** (bool) - Optional - Allows insecure connection. Default: `false`. ### Request Example ```hcl # 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" } ``` ### Response N/A (This is a provider configuration block) ``` -------------------------------- ### Terraform: Retrieve rancher2 Namespaced Registry Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/registry.md This example shows how to retrieve a rancher2 Namespaced Registry by providing its name, project ID, and namespace ID. This allows fetching registry details specific to a particular namespace within a project. ```hcl # Retrieve a rancher2 Namespaced Registry data "rancher2_registry" "foo" { name = "" project_id = "" namespace_id = "" } ``` -------------------------------- ### Virtual Machine Configuration (VM) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/machine_config_v2.md Configuration arguments for creating and managing virtual machines within Rancher. ```APIDOC ## Virtual Machine Configuration (VM) ### Description Configuration arguments for creating and managing virtual machines within Rancher. ### Arguments #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **vm_namespace** (string) - Required - Virtual machine namespace e.g. `default` - **cpu_count** (string) - Optional - CPU count, Default `2` - **memory_size** (string) - Optional - Memory size (in GiB), Default `4` - **disk_info** (string) - Required - A JSON string specifying info for the disks e.g. `{"disks":[{"imageName":"harvester-public/image-57hzg","bootOrder":1,"size":40},{"storageClassName":"node-driver-test","bootOrder":2,"size":1}]}` - **ssh_user** (string) - Required - SSH username e.g. `ubuntu` - **ssh_password** (string) - Optional/Sensitive - SSH password - **network_info** (string) - Required - A JSON string specifying info for the networks e.g. `{"interfaces":[{"networkName":"harvester-public/vlan1"},{"networkName":"harvester-public/vlan2"}]}` - **user_data** (string) - Optional - UserData content of cloud-init, base64 is supported. If the image does not contain the qemu-guest-agent package, you must install and start qemu-guest-agent using userdata - **network_data** (string) - Optional - NetworkData content of cloud-init, base64 is supported - **vm_affinity** (string) - Optional - Virtual machine affinity, only base64 format is supported. For Rancher v2.6.7 and above *Note: `disk_size`, `disk_bus`, `image_name`, `network_name`, `network_model` are deprecated and `disk_info` and `network_info` should be used instead.* ### Request Example ```json { "vm_namespace": "default", "cpu_count": "4", "memory_size": "8", "disk_info": "{\"disks\":[{\"imageName\":\"harvester-public/my-image\",\"bootOrder\":1,\"size\":50}]}", "ssh_user": "ubuntu", "network_info": "{\"interfaces\":[{\"networkName\":\"harvester-public/default\"}]}" } ``` ### Response #### Success Response (200) (Response details not provided in the input.) #### Response Example (Response example not provided in the input.) ``` -------------------------------- ### Import Rancher v2 Etcd Backup (Terraform) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/etcd_backup.md This command demonstrates how to import an existing Rancher v2 Etcd Backup into Terraform state. This is useful for managing previously created backups through Terraform without needing to recreate them. The `` must be replaced with the actual ID of the etcd backup in Rancher. ```bash $ terraform import rancher2_etcd_backup.foo ``` -------------------------------- ### Create Rancher V2 Cluster with Additional Manifest (HCL) Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster_v2.md This example demonstrates how to create a Rancher V2 cluster and include additional Kubernetes manifests. This is useful for deploying custom resources or configurations as part of the cluster provisioning process. ```hcl resource "rancher2_cluster_v2" "foo" { name = "foo" kubernetes_version = "rke2/k3s-version" rke_config { additional_manifest = <` with the actual ID of the Rancher project you wish to import. ```bash terraform import rancher2_project.foo ``` -------------------------------- ### Import Rancher2 Global Role Binding Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/global_role_binding.md This command demonstrates how to import an existing Rancher Global Role Binding into Terraform management. It uses the 'terraform import' command followed by the resource address and the Rancher Global Role Binding ID. This is a Terraform CLI example. ```bash $ terraform import rancher2_global_role_binding.foo ``` -------------------------------- ### Create ETCD Snapshot Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/cluster_v2.md Initiates the creation of an ETCD snapshot. ```APIDOC ##### `etcd_snapshot_create` ### Description Initiates the creation of an ETCD snapshot. ### Arguments #### Path Parameters * `generation` - (Required, int) - ETCD generation to initiate a snapshot. ``` -------------------------------- ### Linode Instance Configuration Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/resources/machine_config_v2.md Arguments for configuring Linode instances, including user accounts, networking, and instance types. ```APIDOC ## Linode Instance Configuration ### Description Arguments for configuring Linode instances, including user accounts, networking, and instance types. ### Arguments #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **authorized_users** (string) - Optional - Linode user accounts (seperated by commas) whose Linode SSH keys will be permitted root access to the created node. - **create_private_ip** (bool) - Optional - Create private IP for the instance. Default `false` - **docker_port** (string) - Optional - Docker Port. Default `2376` - **image** (string) - Optional - Specifies the Linode Instance image which determines the OS distribution and base files. Default `linode/ubuntu18.04` - **instance_type** (string) - Optional - Specifies the Linode Instance type which determines CPU, memory, disk size, etc. Default `g6-standard-4` - **label** (string) - Optional - Linode Instance Label. - **region** (string) - Optional - Specifies the region (location) of the Linode instance. Default `us-east` - **root_pass** (string) - Optional/Sensitive - Root Password - **ssh_port** (string) - Optional - SSH port. Default `22` - **ssh_user** (string) - Optional - SSH username. Default `root` - **stackscript** (string) - Optional - Specifies the Linode StackScript to use to create the instance. - **stackscript_data** (string) - Optional - A JSON string specifying data for the selected StackScript. - **swap_size** (string) - Optional - Linode Instance Swap Size (MB). Default `512` - **tags** (string) - Optional - A comma separated list of tags to apply to the the Linode resource - **token** (string) - Optional/Sensitive - Linode API token. Mandatory on Rancher v2.0.x and v2.1.x. Use `rancher2_cloud_credential` from Rancher v2.2.x - **ua_prefix** (string) - Optional - Prefix the User-Agent in Linode API calls with some 'product/version' ### Request Example ```json { "instance_type": "g5-standard-2", "region": "us-west", "label": "my-linode-instance" } ``` ### Response #### Success Response (200) (Response details not provided in the input.) #### Response Example (Response example not provided in the input.) ``` -------------------------------- ### Rancher2 Secret V2 Datasource Example Source: https://github.com/rancher/terraform-provider-rancher2/blob/main/docs/data-sources/secret_v2.md This HCL code snippet demonstrates how to use the rancher2_secret_v2 datasource to retrieve information about a specific secret v2 within a Rancher cluster. It requires the cluster ID, secret name, and optionally the namespace. ```hcl data "rancher2_secret_v2" "foo" { cluster_id = name = namespace = } ```