forked from andrewh1978/px-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure.go
140 lines (122 loc) · 4.87 KB
/
azure.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"os"
"strconv"
"strings"
)
func azure_create_variables(config *Config) []string {
var pxduser string
var tf_variables []string
var tf_variables_eks []string
var tf_cluster_instance_type string
var tf_cluster_nodes string
var tf_var_ebs []string
var tf_var_tags []string
// create Azure Disks definitions
// split Azure Disks definition by spaces and range the results
ebs := strings.Fields(config.Azure_Disks)
for _, val := range ebs {
// split by : and create common .tfvars entry for all nodes
entry := strings.Split(val, ":")
tf_var_ebs = append(tf_var_ebs, " {\n type = \""+entry[0]+"\"\n size = \""+entry[1]+"\"\n },")
}
// other node ebs processing happens in cluster/node loop
// set default tagging
tf_var_tags = append(tf_var_tags, "azure_tags = {")
if config.Tags != "" {
tags := strings.Split(config.Tags, ",")
for _, val := range tags {
entry := strings.Split(val, "=")
tf_var_tags = append(tf_var_tags, " "+strings.TrimSpace(entry[0])+" = \""+strings.TrimSpace(entry[1])+"\"")
}
}
// get PXDUSER env and apply to tf_variables
pxduser = os.Getenv("PXDUSER")
if pxduser != "" {
tf_var_tags = append(tf_var_tags, " px-deploy_username = \""+pxduser+"\"")
} else {
tf_var_tags = append(tf_var_tags, " px-deploy_username = \"unknown\"")
}
tf_var_tags = append(tf_var_tags, " px-deploy_name = \""+config.Name+"\"")
tf_var_tags = append(tf_var_tags, "}\n")
switch config.Platform {
case "aks":
{
tf_variables = append(tf_variables, "aks_nodes = \""+config.Nodes+"\"")
tf_variables = append(tf_variables, "aks_version = \""+config.Aks_Version+"\"")
config.Nodes = "0"
if config.Env["run_everywhere"] != "" {
tf_variables = append(tf_variables, "run_everywhere = \""+strings.Replace(config.Env["run_everywhere"], "'", "\\\"", -1)+"\"")
}
}
}
Clusters, _ := strconv.Atoi(config.Clusters)
Nodes, _ := strconv.Atoi(config.Nodes)
// build terraform variable file
tf_variables = append(tf_variables, "config_name = \""+config.Name+"\"")
tf_variables = append(tf_variables, "clusters = "+config.Clusters)
tf_variables = append(tf_variables, "azure_region = \""+config.Azure_Region+"\"")
tf_variables = append(tf_variables, "azure_client_id = \""+config.Azure_Client_Id+"\"")
tf_variables = append(tf_variables, "azure_client_secret = \""+config.Azure_Client_Secret+"\"")
tf_variables = append(tf_variables, "azure_tenant_id = \""+config.Azure_Tenant_Id+"\"")
tf_variables = append(tf_variables, "azure_subscription_id = \""+config.Azure_Subscription_Id+"\"")
switch config.Platform {
case "aks":
{
tf_variables_eks = append(tf_variables_eks, "aksclusters = {")
}
}
tf_variables = append(tf_variables, "nodeconfig = [")
// loop clusters (masters and nodes) to build tfvars and master/node scripts
for c := 1; c <= Clusters; c++ {
masternum := strconv.Itoa(c)
tf_cluster_instance_type = config.Azure_Type
tf_cluster_nodes = strconv.Itoa(Nodes)
// if exist, apply individual scripts/settings for nodes of a cluster
for _, clusterconf := range config.Cluster {
if clusterconf.Id == c {
//is there a cluster specific aws_type override? if not, set from generic config
if clusterconf.Instance_Type != "" {
tf_cluster_instance_type = clusterconf.Instance_Type
}
if clusterconf.Nodes != "" {
tf_cluster_nodes = clusterconf.Nodes
}
}
}
// process .tfvars file for deployment
tf_variables = append(tf_variables, " {")
tf_variables = append(tf_variables, " role = \"master\"")
tf_variables = append(tf_variables, " ip_start = 89")
tf_variables = append(tf_variables, " nodecount = 1")
tf_variables = append(tf_variables, " instance_type = \""+config.Azure_Type+"\"")
tf_variables = append(tf_variables, " cluster = "+masternum)
tf_variables = append(tf_variables, " block_devices = [] ")
tf_variables = append(tf_variables, " },")
tf_variables = append(tf_variables, " {")
tf_variables = append(tf_variables, " role = \"node\"")
tf_variables = append(tf_variables, " ip_start = 100")
tf_variables = append(tf_variables, " nodecount = "+tf_cluster_nodes)
tf_variables = append(tf_variables, " instance_type = \""+tf_cluster_instance_type+"\"")
tf_variables = append(tf_variables, " cluster = "+masternum)
tf_variables = append(tf_variables, " block_devices = [")
tf_variables = append(tf_variables, tf_var_ebs...)
tf_variables = append(tf_variables, " ]\n },")
switch config.Platform {
case "aks":
{
tf_variables_eks = append(tf_variables_eks, " \""+masternum+"\" = \""+tf_cluster_instance_type+"\",")
}
}
}
tf_variables = append(tf_variables, "]")
switch config.Platform {
case "aks":
{
tf_variables_eks = append(tf_variables_eks, "}")
tf_variables = append(tf_variables, tf_variables_eks...)
}
}
tf_variables = append(tf_variables, tf_var_tags...)
return tf_variables
}