Skip to content

Commit

Permalink
Add postinstall and presinstall scripts on the node configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin authored and Valentin committed Nov 18, 2020
1 parent 00bd2a0 commit 9b1acf5
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 11 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ Terraform module for deploying a CCEv2 cluster.
>
> Please comment out the `key_pair` parameters of the existing nodes and declare `key_pair` parameter as a global as shown in the examples bellow.
> **Important Note regarding new module version (as of v2.2.0)**
> Now you need to add two parameters on the node configuration `postinstall_script` and `preinstall_script`. If you don't use this parameters, set the value to null as the example below.
## Terraform format
```hcl
module "cce2_cluster" {
source = "FlexibleEngineCloud/cce/flexibleengine"
version = "2.1.0"
version = "2.2.0"
cluster_name = "cluster-test"
cluster_desc = " Cluster for testing purpose"
Expand All @@ -59,6 +63,8 @@ module "cce2_cluster" {
data_volume_size = 100
node_labels = {} # this paramters si to be set empty for an existing node
vm_tags = {} # this parameters can added to an existing node
postinstall_script = null
preinstall_script = null
},
{
node_name = "new-node2"
Expand All @@ -75,6 +81,8 @@ module "cce2_cluster" {
Owner = "Me"
Env = "Prod"
}
postinstall_script = null
preinstall_script = null
}
]
}
Expand Down Expand Up @@ -119,6 +127,8 @@ inputs = {
data_volume_size = 100
node_labels = {} # this paramters si to be set empty for an existing node
vm_tags = {} # this parameters can added to an existing node
postinstall_script = null
preinstall_script = null
},
{
node_name = "new-node-2"
Expand All @@ -135,6 +145,8 @@ inputs = {
Owner = "Me"
Env = "Prod"
}
postinstall_script = null
preinstall_script = null
}
]
}
Expand Down Expand Up @@ -164,7 +176,7 @@ inputs = {
| key\_pair | Name of the SSH key pair | `string` | n/a | yes |
| network\_id | ID of the Network | `string` | n/a | yes |
| node\_os | Operating System of the CCE Worker Node | `string` | n/a | yes |
| nodes\_list | Nodes list of the CCE2 Cluster | <pre>list(object({<br> node_name = string<br> node_flavor = string<br> availability_zone = string<br> root_volume_size = number<br> root_volume_type = string<br> data_volume_size = number<br> data_volume_type = string<br> node_labels = map(string)<br> vm_tags = map(string)<br> }))</pre> | `[]` | no |
| nodes\_list | Nodes list of the CCE2 Cluster | <pre>list(object({<br> node_name = string<br> node_flavor = string<br> availability_zone = string<br> root_volume_size = number<br> root_volume_type = string<br> data_volume_size = number<br> data_volume_type = string<br> node_labels = map(string)<br> vm_tags = map(string)<br> postinstall_script= string<br> preinstall_script = string<br> }))</pre> | `[]` | no |
| vpc\_id | ID of the VPC | `string` | n/a | yes |

## Outputs
Expand Down
32 changes: 32 additions & 0 deletions examples/postinstall-script/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module "cce2_cluster" {
source = "FlexibleEngineCloud/cce/flexibleengine"
version = "2.2.0"

cluster_name = "cluster-test"
cluster_desc = " Cluster for testing purpose"
availability_zone = "eu-west-0a"

cluster_flavor = "cce.s1.small"
vpc_id = "<VPC_ID>"
network_id = "<NETWORK_ID>" //Caution here, you have to use NETWORK_ID even if argument is "subnet_id". Will be fixed soon
cluster_version = "v1.15.6-r1"

node_os = "CentOS 7.5" // Can be "EulerOS 2.5" or "CentOS 7.5"
key_pair = "<SSH_KEY_NAME>"

nodes_list = [
{
node_name = "new-node1"
node_flavor = "s3.large.2"
availability_zone = "eu-west-0a"
root_volume_type = "SATA"
root_volume_size = 40
data_volume_type = "SATA"
data_volume_size = 100
node_labels = null # this paramters si to be set empty for an existing node
vm_tags = null # this parameters can added to an existing node
postinstall_script = data.template_file.test.rendered
preinstall_script = null
}
]
}
4 changes: 4 additions & 0 deletions examples/postinstall-script/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "flexibleengine" {
auth_url = "https://iam.eu-west-0.prod-cloud-ocb.orange-business.com/v3"
region = "eu-west-0"
}
5 changes: 5 additions & 0 deletions examples/postinstall-script/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Script executed on the postinstall step of the node

echo "File content" > /root/my_file_content
3 changes: 3 additions & 0 deletions examples/postinstall-script/user-data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "template_file" "test" {
template = file("test.sh")
}
8 changes: 8 additions & 0 deletions examples/postinstall-script/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
flexibleengine = {
source = "FlexibleEngineCloud/flexibleengine"
}
}
required_version = ">= 0.13"
}
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resource "flexibleengine_cce_node_v3" "cce_cluster_node" {
os = var.node_os
availability_zone = var.nodes_list[count.index]["availability_zone"]
key_pair = var.key_pair
postinstall = var.nodes_list[count.index]["postinstall_script"]
preinstall = var.nodes_list[count.index]["preinstall_script"]

labels = var.nodes_list[count.index]["node_labels"]
tags = var.nodes_list[count.index]["vm_tags"]
Expand Down
20 changes: 11 additions & 9 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ variable "nodes_list" {
description = "Nodes list of the CCE2 Cluster"
default = []
type = list(object({
node_name = string
node_flavor = string
availability_zone = string
root_volume_size = number
root_volume_type = string
data_volume_size = number
data_volume_type = string
node_labels = map(string)
vm_tags = map(string)
node_name = string
node_flavor = string
availability_zone = string
root_volume_size = number
root_volume_type = string
data_volume_size = number
data_volume_type = string
node_labels = map(string)
vm_tags = map(string)
postinstall_script = string
preinstall_script = string
}))
}

0 comments on commit 9b1acf5

Please sign in to comment.