Skip to content

Commit 264adde

Browse files
authored
feat: add new example create rancher with TF (#94)
1 parent afa9fff commit 264adde

File tree

8 files changed

+110
-0
lines changed

8 files changed

+110
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ use-cases/kubeflow/ovhrc.sh
5252
use-cases/kubeflow/kubeconfig
5353
my_kube_cluster.yaml
5454
kustomize
55+
containers-orchestration/managed-rancher/create-rancher-with-tf/variables.tf
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Create a Managed Rancher Service with Terraform
2+
3+
### General information
4+
- 🔗 [Using Terraform with OVHcloud](https://help.ovhcloud.com/csm/fr-terraform-at-ovhcloud?id=kb_article_view&sysparm_article=KB0054776)
5+
- 🔗 [How to use Terraform](https://help.ovhcloud.com/csm/en-gb-public-cloud-compute-terraform?id=kb_article_view&sysparm_article=KB0050787)
6+
- 🔗 [Getting started with Managed Rancher Service](https://help.ovhcloud.com/csm/en-gb-public-cloud-managed-rancher-service-getting-started?id=kb_article_view&sysparm_article=KB0061909)
7+
- 🔗 [ovh_cloud_project_rancher](https://registry.terraform.io/providers/ovh/ovh/latest/docs/resources/cloud_project_rancher)
8+
- 🔗 [OVH token generation page](https://www.ovh.com/auth/api/createToken?GET=/*&POST=/*&PUT=/*&DELETE=/*)
9+
10+
### Set up
11+
- Install the [Terraform CLI](https://www.terraform.io/downloads.html)
12+
- Get the credentials from the OVHCloud Public Cloud project:
13+
- `application_key`
14+
- `application_secret`
15+
- `consumer_key`
16+
- Get the `service_name` (Public Cloud project ID)
17+
18+
### Demo
19+
- set the environment variables `OVH_APPLICATION_KEY`, `OVH_APPLICATION_SECRET`, `OVH_CONSUMER_KEY` and `OVH_CLOUD_PROJECT_SERVICE`
20+
21+
```bash
22+
# OVHcloud provider needed keys
23+
export OVH_ENDPOINT="ovh-eu"
24+
export OVH_APPLICATION_KEY="xxx"
25+
export OVH_APPLICATION_SECRET="xxx"
26+
export OVH_CONSUMER_KEY="xxx"
27+
export OVH_CLOUD_PROJECT_SERVICE="xxx"
28+
```
29+
- Replace the value of your OVH_CLOUD_PROJECT_SERVICE environment variable in the [variables.tf](variables.tf) file (in the project_id variable)
30+
31+
`envsubst < variables.tf.template > variables.tf`
32+
33+
- use the [rancher.tf](rancher.tf) file to define the resources to create
34+
- use the [output.tf](output.tf) file to display the URL and the information of the Rancher to display at the end of Terraform execution
35+
- run the `terraform init` command
36+
- run the `terraform plan` command
37+
- run the `terraform apply` command (~ several seconds)
38+
- get the Rancher value:
39+
40+
```bash
41+
terraform output rancher_url
42+
terraform output rancher_password
43+
```
44+
45+
Note: you can run the `create.sh` script instead of executing each previous commands manually ;-)
46+
47+
### Destroy
48+
49+
- destroy the cluster: `terraform destroy`
50+
51+
Note: you can run the `destroy.sh` script instead of executing the previous command manually ;-)
52+
53+
54+
### After the demo
55+
56+
- if needed delete the token with https://api.ovh.com/console-preview/?section=%2Fme&branch=v1#delete-/me/api/credential/-credentialId-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Stop on error and display executed commands
4+
set -eo xtrace
5+
6+
terraform init
7+
8+
terraform apply -auto-approve
9+
10+
export RANCHER_URL=$(terraform output rancher_url)
11+
export RANCHER_PASSWORD=$(terraform output rancher_password)
12+
13+
echo $RANCHER_URL
14+
echo $RANCHER_PASSWORD
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Stop on error and display executed commands
4+
set -eo xtrace
5+
6+
terraform destroy -auto-approve
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
output "rancher_url" {
2+
value = ovh_cloud_project_rancher.rancher.current_state.url
3+
}
4+
5+
output "rancher_password" {
6+
value = ovh_cloud_project_rancher.rancher.current_state.bootstrap_password
7+
sensitive = true
8+
}
9+
10+
output "rancher_egress_cidr" {
11+
value = ovh_cloud_project_rancher.rancher.current_state.networking.egress_cidr_blocks
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
terraform {
2+
required_providers {
3+
ovh = {
4+
source = "ovh/ovh"
5+
}
6+
}
7+
}
8+
9+
provider "ovh" {
10+
endpoint = "ovh-eu"
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "ovh_cloud_project_rancher" "rancher" {
2+
project_id = var.service_name
3+
target_spec = {
4+
name = "MyRancherTF"
5+
plan = "STANDARD"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variable "service_name" {
2+
default = "$OVH_CLOUD_PROJECT_SERVICE"
3+
}

0 commit comments

Comments
 (0)