|
| 1 | +# |
| 2 | +# Apache v2 license |
| 3 | +# Copyright (C) 2023 Intel Corporation |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | + |
| 7 | +variable "disk_spec_1" { |
| 8 | + default = { |
| 9 | + disk_count = 1 |
| 10 | + disk_size = 200 |
| 11 | + disk_format = "ext4" |
| 12 | + disk_type = "cloud_essd" |
| 13 | + disk_performance = null |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +variable "disk_spec_2" { |
| 18 | + default = { |
| 19 | + disk_count = 1 |
| 20 | + disk_size = 200 |
| 21 | + disk_format = "ext4" |
| 22 | + disk_type = "cloud_essd" |
| 23 | + disk_performance = null |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +variable "region" { |
| 28 | + default = null |
| 29 | +} |
| 30 | + |
| 31 | +variable "zone" { |
| 32 | + default = "cn-beijing-l" |
| 33 | +} |
| 34 | + |
| 35 | +variable "resource_group_id" { |
| 36 | + default = "rg-aekzpvcftlcma5a" |
| 37 | +} |
| 38 | + |
| 39 | +variable "owner" { |
| 40 | + default = "" |
| 41 | +} |
| 42 | + |
| 43 | +variable "custom_tags" { |
| 44 | + default = {} |
| 45 | +} |
| 46 | + |
| 47 | +variable "spot_instance" { |
| 48 | + default = true |
| 49 | +} |
| 50 | + |
| 51 | +variable "wl_name" { |
| 52 | + default = "" |
| 53 | +} |
| 54 | + |
| 55 | +variable "wl_registry_map" { |
| 56 | + default = "" |
| 57 | +} |
| 58 | + |
| 59 | +variable "wl_namespace" { |
| 60 | + default = "" |
| 61 | +} |
| 62 | + |
| 63 | +variable "worker_profile" { |
| 64 | + default = { |
| 65 | + name = "worker" |
| 66 | + instance_type = "ecs.g6.large" |
| 67 | + cpu_model_regex = null |
| 68 | + vm_count = 1 |
| 69 | + |
| 70 | + os_image = null |
| 71 | + os_type = "ubuntu2204" |
| 72 | + os_disk_type = "cloud_essd" |
| 73 | + os_disk_size = 200 |
| 74 | + os_disk_performance = null |
| 75 | + |
| 76 | + data_disk_spec = null |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +variable "client_profile" { |
| 81 | + default = { |
| 82 | + name = "client" |
| 83 | + instance_type = "ecs.g6.large" |
| 84 | + cpu_model_regex = null |
| 85 | + vm_count = 1 |
| 86 | + |
| 87 | + os_image = null |
| 88 | + os_type = "ubuntu2204" |
| 89 | + os_disk_type = "cloud_essd" |
| 90 | + os_disk_size = 200 |
| 91 | + os_disk_performance = null |
| 92 | + |
| 93 | + data_disk_spec = null |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +variable "controller_profile" { |
| 98 | + default = { |
| 99 | + name = "controller" |
| 100 | + instance_type = "ecs.g6.large" |
| 101 | + cpu_model_regex = null |
| 102 | + vm_count = 1 |
| 103 | + |
| 104 | + os_image = null |
| 105 | + os_type = "ubuntu2204" |
| 106 | + os_disk_type = "cloud_essd" |
| 107 | + os_disk_size = 200 |
| 108 | + os_disk_performance = null |
| 109 | + |
| 110 | + data_disk_spec = null |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +module "wsf" { |
| 115 | + source = "./template/terraform/alicloud/main" |
| 116 | + |
| 117 | + region = var.region |
| 118 | + zone = var.zone |
| 119 | + resource_group_id = var.resource_group_id |
| 120 | + job_id = var.wl_namespace |
| 121 | + |
| 122 | + sg_whitelist_cidr_blocks = compact(split("\n",file("proxy-ip-list.txt"))) |
| 123 | + ssh_pub_key = file("ssh_access.key.pub") |
| 124 | + |
| 125 | + common_tags = { |
| 126 | + for k,v in merge(var.custom_tags, { |
| 127 | + owner: var.owner, |
| 128 | + workload: var.wl_name, |
| 129 | + }) : k => substr(replace(lower(v), "/[^a-z0-9_-]/", ""), 0, 63) |
| 130 | + } |
| 131 | + |
| 132 | + instance_profiles = [ |
| 133 | + merge(var.worker_profile, { |
| 134 | + data_disk_spec: null, |
| 135 | + }), |
| 136 | + merge(var.client_profile, { |
| 137 | + data_disk_spec: null, |
| 138 | + }), |
| 139 | + merge(var.controller_profile, { |
| 140 | + data_disk_spec: null, |
| 141 | + }), |
| 142 | + ] |
| 143 | + |
| 144 | + spot_instance = var.spot_instance |
| 145 | +} |
| 146 | + |
| 147 | +output "options" { |
| 148 | + value = { |
| 149 | + wl_name : var.wl_name, |
| 150 | + wl_registry_map : var.wl_registry_map, |
| 151 | + wl_namespace : var.wl_namespace, |
| 152 | + |
| 153 | + docker_dist_repo: "https://mirrors.aliyun.com/docker-ce", |
| 154 | + containerd_pause_registry: "registry.aliyuncs.com/google_containers", |
| 155 | + |
| 156 | + k8s_repo_key_url: { |
| 157 | + "debian": "http://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg", |
| 158 | + "centos": ["http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg","https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg"], |
| 159 | + }, |
| 160 | + k8s_repo_url: { |
| 161 | + "debian": "http://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main", |
| 162 | + "centos": "http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-$basearch", |
| 163 | + }, |
| 164 | + k8s_kubeadm_options: { |
| 165 | + "ClusterConfiguration": { |
| 166 | + "imageRepository": "registry.aliyuncs.com/google_containers", |
| 167 | + }, |
| 168 | + }, |
| 169 | + k8s_registry_image: "public.ecr.aws/docker/library/registry:2", |
| 170 | + k8s_calico_cni_repo: "public.ecr.aws/metakube/calico", |
| 171 | + k8s_cni: "calico", |
| 172 | + k8s_enable_nfd: false, |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +output "instances" { |
| 177 | + value = { |
| 178 | + for k,v in module.wsf.instances : k => merge(v, { |
| 179 | + csp = "alicloud", |
| 180 | + zone = var.zone, |
| 181 | + }) |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +output "terraform_replace" { |
| 186 | + value = lookup(module.wsf, "terraform_replace", null)==null?null:{ |
| 187 | + command = replace(module.wsf.terraform_replace.command, "=", "=module.wsf.") |
| 188 | + cpu_model = module.wsf.terraform_replace.cpu_model |
| 189 | + } |
| 190 | +} |
0 commit comments